Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / importer / external_process_importer_client.h
blobe5a0aa1613eeb9b9bc74bb972c6d80b16b28308f
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_
8 #include <string>
9 #include <vector>
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/common/importer/importer_autofill_form_data_entry.h"
16 #include "chrome/common/importer/importer_data_types.h"
17 #include "chrome/common/importer/importer_url_row.h"
18 #include "components/favicon_base/favicon_usage_data.h"
19 #include "components/history/core/browser/history_types.h"
20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/utility_process_host_client.h"
23 class ExternalProcessImporterHost;
24 struct ImportedBookmarkEntry;
25 class InProcessImporterBridge;
27 namespace autofill {
28 struct PasswordForm;
31 namespace content{
32 class UtilityProcessHost;
35 namespace importer {
36 #if defined(OS_WIN)
37 struct ImporterIE7PasswordInfo;
38 #endif
39 struct ImporterAutofillFormDataEntry;
40 struct SearchEngineInfo;
43 // This class is the client for the out of process profile importing. It
44 // collects notifications from this process host and feeds data back to the
45 // importer host, who actually does the writing.
46 class ExternalProcessImporterClient : public content::UtilityProcessHostClient {
47 public:
48 ExternalProcessImporterClient(
49 base::WeakPtr<ExternalProcessImporterHost> importer_host,
50 const importer::SourceProfile& source_profile,
51 uint16 items,
52 InProcessImporterBridge* bridge);
54 // Launches the task to start the external process.
55 void Start();
57 // Called by the ExternalProcessImporterHost on import cancel.
58 void Cancel();
60 // UtilityProcessHostClient implementation:
61 void OnProcessCrashed(int exit_code) override;
62 bool OnMessageReceived(const IPC::Message& message) override;
64 // Message handlers
65 void OnImportStart();
66 void OnImportFinished(bool succeeded, const std::string& error_msg);
67 void OnImportItemStart(int item);
68 void OnImportItemFinished(int item);
69 void OnHistoryImportStart(size_t total_history_rows_count);
70 void OnHistoryImportGroup(
71 const std::vector<ImporterURLRow>& history_rows_group,
72 int visit_source);
73 void OnHomePageImportReady(const GURL& home_page);
74 void OnBookmarksImportStart(const base::string16& first_folder_name,
75 size_t total_bookmarks_count);
76 void OnBookmarksImportGroup(
77 const std::vector<ImportedBookmarkEntry>& bookmarks_group);
78 void OnFaviconsImportStart(size_t total_favicons_count);
79 void OnFaviconsImportGroup(
80 const favicon_base::FaviconUsageDataList& favicons_group);
81 void OnPasswordFormImportReady(const autofill::PasswordForm& form);
82 void OnKeywordsImportReady(
83 const std::vector<importer::SearchEngineInfo>& search_engines,
84 bool unique_on_host_and_path);
85 void OnFirefoxSearchEngineDataReceived(
86 const std::vector<std::string> search_engine_data);
87 void OnAutofillFormDataImportStart(
88 size_t total_autofill_form_data_entry_count);
89 void OnAutofillFormDataImportGroup(const std::vector<
90 ImporterAutofillFormDataEntry>& autofill_form_data_entry_group);
91 #if defined(OS_WIN)
92 void OnIE7PasswordReceived(
93 const importer::ImporterIE7PasswordInfo& importer_password_info);
94 #endif
96 protected:
97 ~ExternalProcessImporterClient() override;
99 private:
100 // Notifies the importerhost that import has finished, and calls Release().
101 void Cleanup();
103 // Cancel import process on IO thread.
104 void CancelImportProcessOnIOThread();
106 // Report item completely downloaded on IO thread.
107 void NotifyItemFinishedOnIOThread(importer::ImportItem import_item);
109 // Creates a new UtilityProcessHost, which launches the import process.
110 void StartProcessOnIOThread(content::BrowserThread::ID thread_id);
112 // These variables store data being collected from the importer until the
113 // entire group has been collected and is ready to be written to the profile.
114 std::vector<ImporterURLRow> history_rows_;
115 std::vector<ImportedBookmarkEntry> bookmarks_;
116 favicon_base::FaviconUsageDataList favicons_;
117 std::vector<ImporterAutofillFormDataEntry> autofill_form_data_;
119 // Usually some variation on IDS_BOOKMARK_GROUP_...; the name of the folder
120 // under which imported bookmarks will be placed.
121 base::string16 bookmarks_first_folder_name_;
123 // Total number of bookmarks to import.
124 size_t total_bookmarks_count_;
126 // Total number of history items to import.
127 size_t total_history_rows_count_;
129 // Total number of favicons to import.
130 size_t total_favicons_count_;
132 // Total number of autofill form data entries to import.
133 size_t total_autofill_form_data_entry_count_;
135 // Notifications received from the ProfileImportProcessHost are passed back
136 // to process_importer_host_, which calls the ProfileWriter to record the
137 // import data. When the import process is done, process_importer_host_
138 // deletes itself. This is a weak ptr so that any messages received after
139 // the host has deleted itself are ignored (e.g., it's possible to receive
140 // OnProcessCrashed() after NotifyImportEnded()).
141 base::WeakPtr<ExternalProcessImporterHost> process_importer_host_;
143 // Handles sending messages to the external process. Deletes itself when
144 // the external process dies (see
145 // BrowserChildProcessHost::OnChildDisconnected).
146 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
148 // Data to be passed from the importer host to the external importer.
149 importer::SourceProfile source_profile_;
150 uint16 items_;
152 // Takes import data coming over IPC and delivers it to be written by the
153 // ProfileWriter.
154 scoped_refptr<InProcessImporterBridge> bridge_;
156 // True if import process has been cancelled.
157 bool cancelled_;
159 DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterClient);
162 #endif // CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_