From 9a7a73b5a3bf10b903026c202177ea48464acc7b Mon Sep 17 00:00:00 2001 From: Brandon-T Date: Fri, 25 Oct 2024 17:48:10 -0400 Subject: [PATCH] [iOS] - Replace NOTREACHED_IN_MIGRATION for iOS (#26224) * Remove NOTREACHED_IN_MIGRATION for iOS. Replaced with CHECK, DCHECK, [[no_return]] where necessary. --- .../bookmarks/bookmark_model_listener_ios.mm | 2 +- .../exporter/bookmark_html_writer.cc | 26 +++++-------------- .../exporter/brave_bookmarks_exporter.mm | 15 +++++++---- .../importer/bookmark_html_reader.cc | 6 ++--- .../bookmarks/importer/bookmarks_importer.mm | 9 ++++--- ios/browser/api/web/ui/chrome_webview.mm | 2 +- .../favicon/brave_ios_web_favicon_driver.mm | 3 ++- 7 files changed, 28 insertions(+), 35 deletions(-) diff --git a/ios/browser/api/bookmarks/bookmark_model_listener_ios.mm b/ios/browser/api/bookmarks/bookmark_model_listener_ios.mm index 5ac9b38edd8e..78441174ab0c 100644 --- a/ios/browser/api/bookmarks/bookmark_model_listener_ios.mm +++ b/ios/browser/api/bookmarks/bookmark_model_listener_ios.mm @@ -49,7 +49,7 @@ - (instancetype)initWithNode:(const bookmarks::BookmarkNode*)node void BookmarkModelListener::BookmarkModelBeingDeleted() { // This is an inconsistent state in the application lifecycle. The bookmark // model shouldn't disappear. - NOTREACHED_IN_MIGRATION(); + NOTREACHED(); } void BookmarkModelListener::BookmarkNodeMoved( diff --git a/ios/browser/api/bookmarks/exporter/bookmark_html_writer.cc b/ios/browser/api/bookmarks/exporter/bookmark_html_writer.cc index 171ddf768b93..3b39fdd02a38 100644 --- a/ios/browser/api/bookmarks/exporter/bookmark_html_writer.cc +++ b/ios/browser/api/bookmarks/exporter/bookmark_html_writer.cc @@ -302,7 +302,7 @@ class Writer : public base::RefCountedThreadSafe { break; default: - NOTREACHED_IN_MIGRATION(); + NOTREACHED(); } return Write(utf8_string); @@ -327,20 +327,14 @@ class Writer : public base::RefCountedThreadSafe { const std::string* date_added_string = value.FindString(BookmarkCodec::kDateAddedKey); const std::string* type_string = value.FindString(BookmarkCodec::kTypeKey); - if (!title_ptr || !date_added_string || !type_string || - (*type_string != BookmarkCodec::kTypeURL && - *type_string != BookmarkCodec::kTypeFolder)) { - NOTREACHED_IN_MIGRATION(); - return false; - } + CHECK(title_ptr && date_added_string && type_string && + (*type_string == BookmarkCodec::kTypeURL || + *type_string == BookmarkCodec::kTypeFolder)); std::string title = *title_ptr; if (*type_string == BookmarkCodec::kTypeURL) { const std::string* url_string = value.FindString(BookmarkCodec::kURLKey); - if (!url_string) { - NOTREACHED_IN_MIGRATION(); - return false; - } + CHECK(url_string); std::string favicon_string; auto itr = favicons_map_->find(*url_string); @@ -368,10 +362,7 @@ class Writer : public base::RefCountedThreadSafe { value.FindString(BookmarkCodec::kDateModifiedKey); const base::Value::List* child_values = value.FindList(BookmarkCodec::kChildrenKey); - if (!last_modified_date || !child_values) { - NOTREACHED_IN_MIGRATION(); - return false; - } + CHECK(last_modified_date && child_values); if (folder_type != BookmarkNode::OTHER_NODE && folder_type != BookmarkNode::MOBILE) { // The other/mobile folder name are not written out. This gives the effect @@ -398,10 +389,7 @@ class Writer : public base::RefCountedThreadSafe { // Write the children. for (const base::Value& child_value : *child_values) { - if (!child_value.is_dict()) { - NOTREACHED_IN_MIGRATION(); - return false; - } + CHECK(child_value.is_dict()); if (!WriteNode(child_value.GetDict(), BookmarkNode::FOLDER)) { return false; } diff --git a/ios/browser/api/bookmarks/exporter/brave_bookmarks_exporter.mm b/ios/browser/api/bookmarks/exporter/brave_bookmarks_exporter.mm index a9df300bffdf..2a58ff6b72da 100644 --- a/ios/browser/api/bookmarks/exporter/brave_bookmarks_exporter.mm +++ b/ios/browser/api/bookmarks/exporter/brave_bookmarks_exporter.mm @@ -56,15 +56,20 @@ void BraveBookmarksExportObserver::OnExportFinished(Result result) { switch (result) { case Result::kSuccess: - return _on_export_finished(BraveBookmarksExporterStateCompleted); + _on_export_finished(BraveBookmarksExporterStateCompleted); + break; case Result::kCouldNotCreateFile: - return _on_export_finished(BraveBookmarksExporterStateErrorCreatingFile); + _on_export_finished(BraveBookmarksExporterStateErrorCreatingFile); + break; case Result::kCouldNotWriteHeader: - return _on_export_finished(BraveBookmarksExporterStateErrorWritingHeader); + _on_export_finished(BraveBookmarksExporterStateErrorWritingHeader); + break; case Result::kCouldNotWriteNodes: - return _on_export_finished(BraveBookmarksExporterStateErrorWritingNodes); + _on_export_finished(BraveBookmarksExporterStateErrorWritingNodes); + break; default: - NOTREACHED_IN_MIGRATION(); + delete this; + NOTREACHED(); } delete this; } diff --git a/ios/browser/api/bookmarks/importer/bookmark_html_reader.cc b/ios/browser/api/bookmarks/importer/bookmark_html_reader.cc index 846e921ce752..3a21aaef77a2 100644 --- a/ios/browser/api/bookmarks/importer/bookmark_html_reader.cc +++ b/ios/browser/api/bookmarks/importer/bookmark_html_reader.cc @@ -187,10 +187,8 @@ void ImportBookmarksFile( if (is_bookmark && post_data.empty() && (valid_url_callback.is_null() || valid_url_callback.Run(url))) { - if (toolbar_folder_index > path.size() && !path.empty()) { - NOTREACHED_IN_MIGRATION(); // error in parsing. - break; - } + CHECK(toolbar_folder_index <= path.size() || + path.empty()); // error in parsing. ImportedBookmarkEntry entry; entry.creation_time = add_date; diff --git a/ios/browser/api/bookmarks/importer/bookmarks_importer.mm b/ios/browser/api/bookmarks/importer/bookmarks_importer.mm index 485a4149fd71..9f7a528d3f7a 100644 --- a/ios/browser/api/bookmarks/importer/bookmarks_importer.mm +++ b/ios/browser/api/bookmarks/importer/bookmarks_importer.mm @@ -49,19 +49,20 @@ } // If the given name is unique, use it. - if (existing_folder_names.find(folder_name) == existing_folder_names.end()) + if (existing_folder_names.find(folder_name) == existing_folder_names.end()) { return folder_name; + } // Otherwise iterate until we find a unique name. for (size_t i = 1; i <= existing_folder_names.size(); ++i) { std::u16string name = folder_name + u" (" + base::NumberToString16(i) + u")"; - if (existing_folder_names.find(name) == existing_folder_names.end()) + if (existing_folder_names.find(name) == existing_folder_names.end()) { return name; + } } - NOTREACHED_IN_MIGRATION(); - return folder_name; + NOTREACHED(); } // Shows the bookmarks toolbar. diff --git a/ios/browser/api/web/ui/chrome_webview.mm b/ios/browser/api/web/ui/chrome_webview.mm index 4c984aae35e3..7853fdd50ea3 100644 --- a/ios/browser/api/web/ui/chrome_webview.mm +++ b/ios/browser/api/web/ui/chrome_webview.mm @@ -266,7 +266,7 @@ - (void)webStateDestroyed:(web::WebState*)webState { // The WebState is owned by the current instance, and the observer bridge // is unregistered before the WebState is destroyed, so this event should // never happen. - NOTREACHED_IN_MIGRATION(); + NOTREACHED(); } // MARK: - CRWWebStateDelegate implementation diff --git a/ios/browser/favicon/brave_ios_web_favicon_driver.mm b/ios/browser/favicon/brave_ios_web_favicon_driver.mm index 9be4fed6f6ff..22078a33711c 100644 --- a/ios/browser/favicon/brave_ios_web_favicon_driver.mm +++ b/ios/browser/favicon/brave_ios_web_favicon_driver.mm @@ -61,7 +61,8 @@ void BraveIOSWebFaviconDriver::DownloadManifest( const GURL& url, ManifestDownloadCallback callback) { - NOTREACHED_IN_MIGRATION(); + // We don't support downloading manifests + NOTREACHED(); } bool BraveIOSWebFaviconDriver::IsOffTheRecord() {