- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / importer / external_process_importer_client.h
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.
4
5 #ifndef CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_
6 #define CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_
7
8 #include <string>
9 #include <vector>
10
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"
20
21 class ExternalProcessImporterHost;
22 struct ImportedBookmarkEntry;
23 struct ImportedFaviconUsage;
24 class InProcessImporterBridge;
25
26 namespace autofill {
27 struct PasswordForm;
28 }
29
30 namespace content{
31 class UtilityProcessHost;
32 }
33
34 namespace importer {
35 #if defined(OS_WIN)
36 struct ImporterIE7PasswordInfo;
37 #endif
38 struct URLKeywordInfo;
39 }
40
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 {
45  public:
46   ExternalProcessImporterClient(ExternalProcessImporterHost* importer_host,
47                                 const importer::SourceProfile& source_profile,
48                                 uint16 items,
49                                 InProcessImporterBridge* bridge);
50
51   // Launches the task to start the external process.
52   void Start();
53
54   // Called by the ExternalProcessImporterHost on import cancel.
55   void Cancel();
56
57   // UtilityProcessHostClient implementation:
58   virtual void OnProcessCrashed(int exit_code) OVERRIDE;
59   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
60
61   // Message handlers
62   void OnImportStart();
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,
69       int visit_source);
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);
84 #if defined(OS_WIN)
85   void OnIE7PasswordReceived(
86         const importer::ImporterIE7PasswordInfo& importer_password_info);
87 #endif
88
89  protected:
90   virtual ~ExternalProcessImporterClient();
91
92  private:
93   // Notifies the importerhost that import has finished, and calls Release().
94   void Cleanup();
95
96   // Cancel import process on IO thread.
97   void CancelImportProcessOnIOThread();
98
99   // Report item completely downloaded on IO thread.
100   void NotifyItemFinishedOnIOThread(importer::ImportItem import_item);
101
102   // Creates a new UtilityProcessHost, which launches the import process.
103   void StartProcessOnIOThread(content::BrowserThread::ID thread_id);
104
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_;
110
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_;
114
115   // Total number of bookmarks to import.
116   size_t total_bookmarks_count_;
117
118   // Total number of history items to import.
119   size_t total_history_rows_count_;
120
121   // Total number of favicons to import.
122   size_t total_favicons_count_;
123
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_
127   // deletes itself.
128   ExternalProcessImporterHost* process_importer_host_;
129
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_;
134
135   // Data to be passed from the importer host to the external importer.
136   importer::SourceProfile source_profile_;
137   uint16 items_;
138
139   // Takes import data coming over IPC and delivers it to be written by the
140   // ProfileWriter.
141   scoped_refptr<InProcessImporterBridge> bridge_;
142
143   // True if import process has been cancelled.
144   bool cancelled_;
145
146   DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterClient);
147 };
148
149 #endif  // CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_