OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_ |
| 6 #define CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" |
| 14 #include "chrome/browser/importer/profile_writer.h" |
| 15 #include "chrome/browser/profile_import_process_host.h" |
| 16 |
| 17 class ExternalProcessImporterHost; |
| 18 class InProcessImporterBridge; |
| 19 |
| 20 namespace history { |
| 21 class URLRow; |
| 22 struct ImportedFavIconUsage; |
| 23 } |
| 24 |
| 25 namespace importer { |
| 26 struct ProfileInfo; |
| 27 } |
| 28 |
| 29 // This class is the client for the ProfileImportProcessHost. It collects |
| 30 // notifications from this process host and feeds data back to the importer |
| 31 // host, who actually does the writing. |
| 32 class ExternalProcessImporterClient |
| 33 : public ProfileImportProcessHost::ImportProcessClient { |
| 34 public: |
| 35 ExternalProcessImporterClient(ExternalProcessImporterHost* importer_host, |
| 36 const importer::ProfileInfo& profile_info, |
| 37 uint16 items, |
| 38 InProcessImporterBridge* bridge, |
| 39 bool import_to_bookmark_bar); |
| 40 virtual ~ExternalProcessImporterClient(); |
| 41 |
| 42 // Cancel import process on IO thread. |
| 43 void CancelImportProcessOnIOThread(); |
| 44 |
| 45 // Report item completely downloaded on IO thread. |
| 46 void NotifyItemFinishedOnIOThread(importer::ImportItem import_item); |
| 47 |
| 48 // Notifies the importerhost that import has finished, and calls Release(). |
| 49 void Cleanup(); |
| 50 |
| 51 // Launches the task to start the external process. |
| 52 virtual void Start(); |
| 53 |
| 54 // Creates a new ProfileImportProcessHost, which launches the import process. |
| 55 virtual void StartProcessOnIOThread(ResourceDispatcherHost* rdh, |
| 56 BrowserThread::ID thread_id); |
| 57 |
| 58 // Called by the ExternalProcessImporterHost on import cancel. |
| 59 virtual void Cancel(); |
| 60 |
| 61 // Begin ProfileImportProcessHost::ImportProcessClient implementation. |
| 62 virtual void OnProcessCrashed(int exit_status) OVERRIDE; |
| 63 virtual void OnImportStart() OVERRIDE; |
| 64 virtual void OnImportFinished(bool succeeded, std::string error_msg) OVERRIDE; |
| 65 virtual void OnImportItemStart(int item) OVERRIDE; |
| 66 virtual void OnImportItemFinished(int item) OVERRIDE; |
| 67 |
| 68 // Called on first message received when importing history; gives total |
| 69 // number of rows to be imported. |
| 70 virtual void OnHistoryImportStart(size_t total_history_rows_count) OVERRIDE; |
| 71 |
| 72 // Called when a group of URLRows has been received. |
| 73 // The source is passed with history::VisitSource type. |
| 74 virtual void OnHistoryImportGroup( |
| 75 const std::vector<history::URLRow> &history_rows_group, |
| 76 int visit_source) OVERRIDE; |
| 77 |
| 78 // Called when the home page has been received. |
| 79 virtual void OnHomePageImportReady(const GURL& home_page) OVERRIDE; |
| 80 |
| 81 // First message received when importing bookmarks. |
| 82 // |first_folder_name| can be NULL. |
| 83 // |options| is described in ProfileWriter::BookmarkOptions. |
| 84 // |total_bookmarks_count| is the total number of bookmarks to be imported. |
| 85 virtual void OnBookmarksImportStart(const std::wstring first_folder_name, |
| 86 int options, |
| 87 size_t total_bookmarks_count) OVERRIDE; |
| 88 |
| 89 // Called when a group of bookmarks has been received. |
| 90 virtual void OnBookmarksImportGroup( |
| 91 const std::vector<ProfileWriter::BookmarkEntry>& bookmarks_group) |
| 92 OVERRIDE; |
| 93 |
| 94 // First message received when importing favicons. |total_fav_icons_size| |
| 95 // gives the total number of fav icons to be imported. |
| 96 virtual void OnFavIconsImportStart(size_t total_fav_icons_count) OVERRIDE; |
| 97 |
| 98 // Called when a group of favicons has been received. |
| 99 virtual void OnFavIconsImportGroup( |
| 100 const std::vector<history::ImportedFavIconUsage>& fav_icons_group) |
| 101 OVERRIDE; |
| 102 |
| 103 // Called when the passwordform has been received. |
| 104 virtual void OnPasswordFormImportReady( |
| 105 const webkit_glue::PasswordForm& form) OVERRIDE; |
| 106 |
| 107 // Called when search engines have been received. |
| 108 virtual void OnKeywordsImportReady( |
| 109 const std::vector<TemplateURL>& template_urls, |
| 110 int default_keyword_index, |
| 111 bool unique_on_host_and_path) OVERRIDE; |
| 112 |
| 113 // End ProfileImportProcessHost::ImportProcessClient implementation. |
| 114 |
| 115 private: |
| 116 // 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. |
| 118 std::vector<history::URLRow> history_rows_; |
| 119 std::vector<ProfileWriter::BookmarkEntry> bookmarks_; |
| 120 std::vector<history::ImportedFavIconUsage> fav_icons_; |
| 121 |
| 122 // Usually some variation on IDS_BOOKMARK_GROUP_...; the name of the folder |
| 123 // under which imported bookmarks will be placed. |
| 124 std::wstring bookmarks_first_folder_name_; |
| 125 |
| 126 // Determines how bookmarks should be added (ProfileWriter::BookmarkOptions). |
| 127 int bookmarks_options_; |
| 128 |
| 129 // Total number of bookmarks to import. |
| 130 size_t total_bookmarks_count_; |
| 131 |
| 132 // Total number of history items to import. |
| 133 size_t total_history_rows_count_; |
| 134 |
| 135 // Total number of fav icons to import. |
| 136 size_t total_fav_icons_count_; |
| 137 |
| 138 // Notifications received from the ProfileImportProcessHost are passed back |
| 139 // to process_importer_host_, which calls the ProfileWriter to record the |
| 140 // import data. When the import process is done, process_importer_host_ |
| 141 // deletes itself. |
| 142 ExternalProcessImporterHost* process_importer_host_; |
| 143 |
| 144 // Handles sending messages to the external process. Deletes itself when |
| 145 // the external process dies (see ChildProcessHost::OnChildDied). |
| 146 ProfileImportProcessHost* profile_import_process_host_; |
| 147 |
| 148 // Data to be passed from the importer host to the external importer. |
| 149 const importer::ProfileInfo& profile_info_; |
| 150 uint16 items_; |
| 151 bool import_to_bookmark_bar_; |
| 152 |
| 153 // Takes import data coming over IPC and delivers it to be written by the |
| 154 // ProfileWriter. Released by ExternalProcessImporterClient in its |
| 155 // destructor. |
| 156 InProcessImporterBridge* bridge_; |
| 157 |
| 158 // True if import process has been cancelled. |
| 159 bool cancelled_; |
| 160 |
| 161 DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterClient); |
| 162 }; |
| 163 |
| 164 #endif // CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_ |
OLD | NEW |