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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_
6 #define CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/strings/string16.h"
15 #include "chrome/browser/history/history_types.h"
16 #include "chrome/common/importer/importer_data_types.h"
17 #include "chrome/common/importer/importer_url_row.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/utility_process_host_client.h"
21 class ExternalProcessImporterHost;
22 struct ImportedBookmarkEntry;
23 struct ImportedFaviconUsage;
24 class InProcessImporterBridge;
31 class UtilityProcessHost;
36 struct ImporterIE7PasswordInfo;
38 struct URLKeywordInfo;
41 // This class is the client for the out of process profile importing. It
42 // collects notifications from this process host and feeds data back to the
43 // importer host, who actually does the writing.
44 class ExternalProcessImporterClient : public content::UtilityProcessHostClient {
46 ExternalProcessImporterClient(ExternalProcessImporterHost* importer_host,
47 const importer::SourceProfile& source_profile,
49 InProcessImporterBridge* bridge);
51 // Launches the task to start the external process.
54 // Called by the ExternalProcessImporterHost on import cancel.
57 // UtilityProcessHostClient implementation:
58 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
59 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
63 void OnImportFinished(bool succeeded, const std::string& error_msg);
64 void OnImportItemStart(int item);
65 void OnImportItemFinished(int item);
66 void OnHistoryImportStart(size_t total_history_rows_count);
67 void OnHistoryImportGroup(
68 const std::vector<ImporterURLRow>& history_rows_group,
70 void OnHomePageImportReady(const GURL& home_page);
71 void OnBookmarksImportStart(const string16& first_folder_name,
72 size_t total_bookmarks_count);
73 void OnBookmarksImportGroup(
74 const std::vector<ImportedBookmarkEntry>& bookmarks_group);
75 void OnFaviconsImportStart(size_t total_favicons_count);
76 void OnFaviconsImportGroup(
77 const std::vector<ImportedFaviconUsage>& favicons_group);
78 void OnPasswordFormImportReady(const autofill::PasswordForm& form);
79 void OnKeywordsImportReady(
80 const std::vector<importer::URLKeywordInfo>& url_keywords,
81 bool unique_on_host_and_path);
82 void OnFirefoxSearchEngineDataReceived(
83 const std::vector<std::string> search_engine_data);
85 void OnIE7PasswordReceived(
86 const importer::ImporterIE7PasswordInfo& importer_password_info);
90 virtual ~ExternalProcessImporterClient();
93 // Notifies the importerhost that import has finished, and calls Release().
96 // Cancel import process on IO thread.
97 void CancelImportProcessOnIOThread();
99 // Report item completely downloaded on IO thread.
100 void NotifyItemFinishedOnIOThread(importer::ImportItem import_item);
102 // Creates a new UtilityProcessHost, which launches the import process.
103 void StartProcessOnIOThread(content::BrowserThread::ID thread_id);
105 // These variables store data being collected from the importer until the
106 // entire group has been collected and is ready to be written to the profile.
107 std::vector<ImporterURLRow> history_rows_;
108 std::vector<ImportedBookmarkEntry> bookmarks_;
109 std::vector<ImportedFaviconUsage> favicons_;
111 // Usually some variation on IDS_BOOKMARK_GROUP_...; the name of the folder
112 // under which imported bookmarks will be placed.
113 string16 bookmarks_first_folder_name_;
115 // Total number of bookmarks to import.
116 size_t total_bookmarks_count_;
118 // Total number of history items to import.
119 size_t total_history_rows_count_;
121 // Total number of favicons to import.
122 size_t total_favicons_count_;
124 // Notifications received from the ProfileImportProcessHost are passed back
125 // to process_importer_host_, which calls the ProfileWriter to record the
126 // import data. When the import process is done, process_importer_host_
128 ExternalProcessImporterHost* process_importer_host_;
130 // Handles sending messages to the external process. Deletes itself when
131 // the external process dies (see
132 // BrowserChildProcessHost::OnChildDisconnected).
133 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
135 // Data to be passed from the importer host to the external importer.
136 importer::SourceProfile source_profile_;
139 // Takes import data coming over IPC and delivers it to be written by the
141 scoped_refptr<InProcessImporterBridge> bridge_;
143 // True if import process has been cancelled.
146 DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterClient);
149 #endif // CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_