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(
47 base::WeakPtr
<ExternalProcessImporterHost
> importer_host
,
48 const importer::SourceProfile
& source_profile
,
50 InProcessImporterBridge
* bridge
);
52 // Launches the task to start the external process.
55 // Called by the ExternalProcessImporterHost on import cancel.
58 // UtilityProcessHostClient implementation:
59 virtual void OnProcessCrashed(int exit_code
) OVERRIDE
;
60 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
64 void OnImportFinished(bool succeeded
, const std::string
& error_msg
);
65 void OnImportItemStart(int item
);
66 void OnImportItemFinished(int item
);
67 void OnHistoryImportStart(size_t total_history_rows_count
);
68 void OnHistoryImportGroup(
69 const std::vector
<ImporterURLRow
>& history_rows_group
,
71 void OnHomePageImportReady(const GURL
& home_page
);
72 void OnBookmarksImportStart(const base::string16
& first_folder_name
,
73 size_t total_bookmarks_count
);
74 void OnBookmarksImportGroup(
75 const std::vector
<ImportedBookmarkEntry
>& bookmarks_group
);
76 void OnFaviconsImportStart(size_t total_favicons_count
);
77 void OnFaviconsImportGroup(
78 const std::vector
<ImportedFaviconUsage
>& favicons_group
);
79 void OnPasswordFormImportReady(const autofill::PasswordForm
& form
);
80 void OnKeywordsImportReady(
81 const std::vector
<importer::URLKeywordInfo
>& url_keywords
,
82 bool unique_on_host_and_path
);
83 void OnFirefoxSearchEngineDataReceived(
84 const std::vector
<std::string
> search_engine_data
);
86 void OnIE7PasswordReceived(
87 const importer::ImporterIE7PasswordInfo
& importer_password_info
);
91 virtual ~ExternalProcessImporterClient();
94 // Notifies the importerhost that import has finished, and calls Release().
97 // Cancel import process on IO thread.
98 void CancelImportProcessOnIOThread();
100 // Report item completely downloaded on IO thread.
101 void NotifyItemFinishedOnIOThread(importer::ImportItem import_item
);
103 // Creates a new UtilityProcessHost, which launches the import process.
104 void StartProcessOnIOThread(content::BrowserThread::ID thread_id
);
106 // These variables store data being collected from the importer until the
107 // entire group has been collected and is ready to be written to the profile.
108 std::vector
<ImporterURLRow
> history_rows_
;
109 std::vector
<ImportedBookmarkEntry
> bookmarks_
;
110 std::vector
<ImportedFaviconUsage
> favicons_
;
112 // Usually some variation on IDS_BOOKMARK_GROUP_...; the name of the folder
113 // under which imported bookmarks will be placed.
114 base::string16 bookmarks_first_folder_name_
;
116 // Total number of bookmarks to import.
117 size_t total_bookmarks_count_
;
119 // Total number of history items to import.
120 size_t total_history_rows_count_
;
122 // Total number of favicons to import.
123 size_t total_favicons_count_
;
125 // Notifications received from the ProfileImportProcessHost are passed back
126 // to process_importer_host_, which calls the ProfileWriter to record the
127 // import data. When the import process is done, process_importer_host_
128 // deletes itself. This is a weak ptr so that any messages received after
129 // the host has deleted itself are ignored (e.g., it's possible to receive
130 // OnProcessCrashed() after NotifyImportEnded()).
131 base::WeakPtr
<ExternalProcessImporterHost
> process_importer_host_
;
133 // Handles sending messages to the external process. Deletes itself when
134 // the external process dies (see
135 // BrowserChildProcessHost::OnChildDisconnected).
136 base::WeakPtr
<content::UtilityProcessHost
> utility_process_host_
;
138 // Data to be passed from the importer host to the external importer.
139 importer::SourceProfile source_profile_
;
142 // Takes import data coming over IPC and delivers it to be written by the
144 scoped_refptr
<InProcessImporterBridge
> bridge_
;
146 // True if import process has been cancelled.
149 DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterClient
);
152 #endif // CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_