 Chromium Code Reviews
 Chromium Code Reviews Issue 2470283002:
  Convert profile import IPCs to Mojo  (Closed)
    
  
    Issue 2470283002:
  Convert profile import IPCs to Mojo  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_ | 
| 6 #define CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_ | 6 #define CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_ | 
| 7 | 7 | 
| 8 #include <stddef.h> | 8 #include <stddef.h> | 
| 9 #include <stdint.h> | 9 #include <stdint.h> | 
| 10 | 10 | 
| 11 #include <string> | 11 #include <string> | 
| 12 #include <vector> | 12 #include <vector> | 
| 13 | 13 | 
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" | 
| 15 #include "base/macros.h" | 15 #include "base/macros.h" | 
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" | 
| 17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" | 
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" | 
| 19 #include "chrome/common/importer/importer_autofill_form_data_entry.h" | 19 #include "chrome/common/importer/importer_autofill_form_data_entry.h" | 
| 20 #include "chrome/common/importer/importer_data_types.h" | 20 #include "chrome/common/importer/importer_data_types.h" | 
| 21 #include "chrome/common/importer/importer_url_row.h" | 21 #include "chrome/common/importer/importer_url_row.h" | 
| 22 #include "chrome/common/importer/profile_import.mojom.h" | |
| 22 #include "components/favicon_base/favicon_usage_data.h" | 23 #include "components/favicon_base/favicon_usage_data.h" | 
| 23 #include "components/history/core/browser/history_types.h" | 24 #include "components/history/core/browser/history_types.h" | 
| 24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" | 
| 25 #include "content/public/browser/utility_process_host_client.h" | 26 #include "content/public/browser/utility_process_host_client.h" | 
| 27 #include "mojo/public/cpp/bindings/binding.h" | |
| 26 | 28 | 
| 27 class ExternalProcessImporterHost; | 29 class ExternalProcessImporterHost; | 
| 28 struct ImportedBookmarkEntry; | 30 struct ImportedBookmarkEntry; | 
| 29 class InProcessImporterBridge; | 31 class InProcessImporterBridge; | 
| 30 | 32 | 
| 31 namespace autofill { | 33 namespace autofill { | 
| 32 struct PasswordForm; | 34 struct PasswordForm; | 
| 33 } | 35 } | 
| 34 | 36 | 
| 35 namespace content{ | 37 namespace content{ | 
| 36 class UtilityProcessHost; | 38 class UtilityProcessHost; | 
| 37 } | 39 } | 
| 38 | 40 | 
| 39 namespace importer { | 41 namespace importer { | 
| 40 #if defined(OS_WIN) | 42 #if defined(OS_WIN) | 
| 41 struct ImporterIE7PasswordInfo; | 43 struct ImporterIE7PasswordInfo; | 
| 42 #endif | 44 #endif | 
| 43 struct ImporterAutofillFormDataEntry; | 45 struct ImporterAutofillFormDataEntry; | 
| 44 struct SearchEngineInfo; | 46 struct SearchEngineInfo; | 
| 45 } | 47 } | 
| 46 | 48 | 
| 47 // This class is the client for the out of process profile importing. It | 49 // This class is the client for the out of process profile importing. It | 
| 48 // collects notifications from this process host and feeds data back to the | 50 // collects notifications from this process host and feeds data back to the | 
| 49 // importer host, who actually does the writing. | 51 // importer host, who actually does the writing. | 
| 50 class ExternalProcessImporterClient : public content::UtilityProcessHostClient { | 52 class ExternalProcessImporterClient | 
| 53 : public content::UtilityProcessHostClient, | |
| 54 public chrome::mojom::ProfileImportObserver { | |
| 51 public: | 55 public: | 
| 52 ExternalProcessImporterClient( | 56 ExternalProcessImporterClient( | 
| 53 base::WeakPtr<ExternalProcessImporterHost> importer_host, | 57 base::WeakPtr<ExternalProcessImporterHost> importer_host, | 
| 54 const importer::SourceProfile& source_profile, | 58 const importer::SourceProfile& source_profile, | 
| 55 uint16_t items, | 59 uint16_t items, | 
| 56 InProcessImporterBridge* bridge); | 60 InProcessImporterBridge* bridge); | 
| 57 | 61 | 
| 58 // Launches the task to start the external process. | 62 // Launches the task to start the external process. | 
| 59 void Start(); | 63 void Start(); | 
| 60 | 64 | 
| 61 // Called by the ExternalProcessImporterHost on import cancel. | 65 // Called by the ExternalProcessImporterHost on import cancel. | 
| 62 void Cancel(); | 66 void Cancel(); | 
| 63 | 67 | 
| 64 // UtilityProcessHostClient implementation: | 68 // UtilityProcessHostClient implementation: | 
| 65 void OnProcessCrashed(int exit_code) override; | 69 void OnProcessCrashed(int exit_code) override; | 
| 66 bool OnMessageReceived(const IPC::Message& message) override; | 70 bool OnMessageReceived(const IPC::Message& message) override; | 
| 67 | 71 | 
| 68 // Message handlers | 72 // chrome::mojom::ProfileImportObserver: | 
| 69 void OnImportStart(); | 73 void OnImportStart() override; | 
| 70 void OnImportFinished(bool succeeded, const std::string& error_msg); | 74 void OnImportFinished(bool succeeded, const std::string& error_msg) override; | 
| 71 void OnImportItemStart(int item); | 75 void OnImportItemStart(importer::ImportItem item) override; | 
| 72 void OnImportItemFinished(int item); | 76 void OnImportItemFinished(importer::ImportItem item) override; | 
| 73 void OnHistoryImportStart(size_t total_history_rows_count); | 77 void OnHistoryImportStart(int total_history_rows_count) override; | 
| 74 void OnHistoryImportGroup( | 78 void OnHistoryImportGroup( | 
| 75 const std::vector<ImporterURLRow>& history_rows_group, | 79 const std::vector<ImporterURLRow>& history_rows_group, | 
| 76 int visit_source); | 80 int visit_source) override; | 
| 77 void OnHomePageImportReady(const GURL& home_page); | 81 void OnHomePageImportReady(const GURL& home_page) override; | 
| 78 void OnBookmarksImportStart(const base::string16& first_folder_name, | 82 void OnBookmarksImportStart(const base::string16& first_folder_name, | 
| 79 size_t total_bookmarks_count); | 83 int total_bookmarks_count) override; | 
| 80 void OnBookmarksImportGroup( | 84 void OnBookmarksImportGroup( | 
| 81 const std::vector<ImportedBookmarkEntry>& bookmarks_group); | 85 const std::vector<ImportedBookmarkEntry>& bookmarks_group) override; | 
| 82 void OnFaviconsImportStart(size_t total_favicons_count); | 86 void OnFaviconsImportStart(int total_favicons_count) override; | 
| 83 void OnFaviconsImportGroup( | 87 void OnFaviconsImportGroup( | 
| 84 const favicon_base::FaviconUsageDataList& favicons_group); | 88 const favicon_base::FaviconUsageDataList& favicons_group) override; | 
| 85 void OnPasswordFormImportReady(const autofill::PasswordForm& form); | 89 void OnPasswordFormImportReady(const autofill::PasswordForm& form) override; | 
| 86 void OnKeywordsImportReady( | 90 void OnKeywordsImportReady( | 
| 87 const std::vector<importer::SearchEngineInfo>& search_engines, | 91 const std::vector<importer::SearchEngineInfo>& search_engines, | 
| 88 bool unique_on_host_and_path); | 92 bool unique_on_host_and_path) override; | 
| 89 void OnFirefoxSearchEngineDataReceived( | 93 void OnFirefoxSearchEngineDataReceived( | 
| 90 const std::vector<std::string> search_engine_data); | 94 const std::vector<std::string>& search_engine_data) override; | 
| 91 void OnAutofillFormDataImportStart( | 95 void OnAutofillFormDataImportStart( | 
| 92 size_t total_autofill_form_data_entry_count); | 96 int total_autofill_form_data_entry_count) override; | 
| 93 void OnAutofillFormDataImportGroup(const std::vector< | 97 void OnAutofillFormDataImportGroup( | 
| 94 ImporterAutofillFormDataEntry>& autofill_form_data_entry_group); | 98 const std::vector<ImporterAutofillFormDataEntry>& | 
| 95 #if defined(OS_WIN) | 99 autofill_form_data_entry_group) override; | 
| 
gab
2016/11/08 13:34:25
Is this because mojom doesn't have the concept of
 
tibell
2016/11/09 23:08:41
Correct. This is by design.
 | |
| 96 void OnIE7PasswordReceived( | 100 void OnIE7PasswordReceived( | 
| 97 const importer::ImporterIE7PasswordInfo& importer_password_info); | 101 const importer::ImporterIE7PasswordInfo& importer_password_info) override; | 
| 98 #endif | |
| 99 | 102 | 
| 100 protected: | 103 protected: | 
| 101 ~ExternalProcessImporterClient() override; | 104 ~ExternalProcessImporterClient() override; | 
| 102 | 105 | 
| 103 private: | 106 private: | 
| 104 // Notifies the importerhost that import has finished, and calls Release(). | 107 // Notifies the importerhost that import has finished, and calls Release(). | 
| 105 void Cleanup(); | 108 void Cleanup(); | 
| 106 | 109 | 
| 107 // Cancel import process on IO thread. | 110 // Creates a new UtilityProcessHost, which launches the import process. | 
| 108 void CancelImportProcessOnIOThread(); | 111 void StartProcessOnIOThread(content::BrowserThread::ID thread_id, | 
| 112 chrome::mojom::ProfileImportRequest request); | |
| 109 | 113 | 
| 110 // Report item completely downloaded on IO thread. | 114 // The Mojo connections need to be torn down on the same thread that created | 
| 111 void NotifyItemFinishedOnIOThread(importer::ImportItem import_item); | 115 // them, but the destructor is not guaranteed to be run on that thread so we | 
| 112 | 116 // tear down the connections explicitly. | 
| 113 // Creates a new UtilityProcessHost, which launches the import process. | 117 void CloseMojoHandles(); | 
| 114 void StartProcessOnIOThread(content::BrowserThread::ID thread_id); | |
| 115 | 118 | 
| 116 // These variables store data being collected from the importer until the | 119 // These variables store data being collected from the importer until the | 
| 117 // entire group has been collected and is ready to be written to the profile. | 120 // entire group has been collected and is ready to be written to the profile. | 
| 118 std::vector<ImporterURLRow> history_rows_; | 121 std::vector<ImporterURLRow> history_rows_; | 
| 119 std::vector<ImportedBookmarkEntry> bookmarks_; | 122 std::vector<ImportedBookmarkEntry> bookmarks_; | 
| 120 favicon_base::FaviconUsageDataList favicons_; | 123 favicon_base::FaviconUsageDataList favicons_; | 
| 121 std::vector<ImporterAutofillFormDataEntry> autofill_form_data_; | 124 std::vector<ImporterAutofillFormDataEntry> autofill_form_data_; | 
| 122 | 125 | 
| 123 // Usually some variation on IDS_BOOKMARK_GROUP_...; the name of the folder | 126 // Usually some variation on IDS_BOOKMARK_GROUP_...; the name of the folder | 
| 124 // under which imported bookmarks will be placed. | 127 // under which imported bookmarks will be placed. | 
| (...skipping 28 matching lines...) Expand all Loading... | |
| 153 importer::SourceProfile source_profile_; | 156 importer::SourceProfile source_profile_; | 
| 154 uint16_t items_; | 157 uint16_t items_; | 
| 155 | 158 | 
| 156 // Takes import data coming over IPC and delivers it to be written by the | 159 // Takes import data coming over IPC and delivers it to be written by the | 
| 157 // ProfileWriter. | 160 // ProfileWriter. | 
| 158 scoped_refptr<InProcessImporterBridge> bridge_; | 161 scoped_refptr<InProcessImporterBridge> bridge_; | 
| 159 | 162 | 
| 160 // True if import process has been cancelled. | 163 // True if import process has been cancelled. | 
| 161 bool cancelled_; | 164 bool cancelled_; | 
| 162 | 165 | 
| 166 // Used to start and stop the actual importer running in a different process. | |
| 167 chrome::mojom::ProfileImportPtr profile_import_; | |
| 168 | |
| 169 // Used to receive progress updates from the importer. | |
| 170 mojo::Binding<chrome::mojom::ProfileImportObserver> binding_; | |
| 171 | |
| 163 DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterClient); | 172 DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterClient); | 
| 164 }; | 173 }; | 
| 165 | 174 | 
| 166 #endif // CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_ | 175 #endif // CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_ | 
| OLD | NEW |