OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_IMPORTER_IMPORTER_HOST_H_ | 5 #ifndef CHROME_BROWSER_IMPORTER_IMPORTER_HOST_H_ |
6 #define CHROME_BROWSER_IMPORTER_IMPORTER_HOST_H_ | 6 #define CHROME_BROWSER_IMPORTER_IMPORTER_HOST_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" | 14 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" |
15 #include "chrome/browser/importer/importer_data_types.h" | 15 #include "chrome/browser/importer/importer_data_types.h" |
16 #include "chrome/browser/importer/profile_writer.h" | 16 #include "chrome/browser/importer/profile_writer.h" |
17 #include "chrome/browser/ui/browser_list_observer.h" | |
18 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
20 #include "ui/gfx/native_widget_types.h" | 19 #include "ui/gfx/native_widget_types.h" |
21 | 20 |
22 class FirefoxProfileLock; | 21 class FirefoxProfileLock; |
23 class Importer; | 22 class Importer; |
24 class Profile; | 23 class Profile; |
25 | 24 |
26 namespace importer { | 25 namespace importer { |
27 class ImporterProgressObserver; | 26 class ImporterProgressObserver; |
28 } | 27 } |
29 | 28 |
30 // This class hosts the importers. It enumerates profiles from other | 29 // This class hosts the importers. It enumerates profiles from other |
31 // browsers dynamically, and controls the process of importing. When | 30 // browsers dynamically, and controls the process of importing. When |
32 // the import process is done, ImporterHost deletes itself. | 31 // the import process is done, ImporterHost deletes itself. |
33 class ImporterHost : public BaseBookmarkModelObserver, | 32 class ImporterHost : public BaseBookmarkModelObserver, |
34 public content::NotificationObserver, | 33 public content::NotificationObserver { |
35 public chrome::BrowserListObserver { | |
36 public: | 34 public: |
37 ImporterHost(); | 35 ImporterHost(); |
38 | 36 |
39 void SetObserver(importer::ImporterProgressObserver* observer); | 37 void SetObserver(importer::ImporterProgressObserver* observer); |
40 | 38 |
41 // A series of functions invoked at the start, during and end of the import | 39 // A series of functions invoked at the start, during and end of the import |
42 // process. The middle functions are notifications that the a harvesting of a | 40 // process. The middle functions are notifications that the a harvesting of a |
43 // particular source of data (specified by |item|) is under way. | 41 // particular source of data (specified by |item|) is under way. |
44 void NotifyImportStarted(); | 42 void NotifyImportStarted(); |
45 void NotifyImportItemStarted(importer::ImportItem item); | 43 void NotifyImportItemStarted(importer::ImportItem item); |
46 void NotifyImportItemEnded(importer::ImportItem item); | 44 void NotifyImportItemEnded(importer::ImportItem item); |
47 void NotifyImportEnded(); | 45 void NotifyImportEnded(); |
48 | 46 |
49 // When in headless mode, the importer will not show any warning dialog if | 47 // When in headless mode, the importer will not show any warning dialog if |
50 // a user action is required (e.g., Firefox profile is locked and user should | 48 // a user action is required (e.g., Firefox profile is locked and user should |
51 // close Firefox to continue) and the outcome is as if the user had canceled | 49 // close Firefox to continue) and the outcome is as if the user had canceled |
52 // the import operation. | 50 // the import operation. |
53 void set_headless() { headless_ = true; } | 51 void set_headless() { headless_ = true; } |
54 bool is_headless() const { return headless_; } | 52 bool is_headless() const { return headless_; } |
55 | 53 |
56 void set_parent_window(gfx::NativeWindow parent_window) { | 54 void set_parent_window(gfx::NativeWindow parent_window) { |
57 parent_window_ = parent_window; | 55 parent_window_ = parent_window; |
58 } | 56 } |
59 | 57 |
60 void set_browser(Browser* browser) { browser_ = browser; } | |
61 | |
62 // Starts the process of importing the settings and data depending on what the | 58 // Starts the process of importing the settings and data depending on what the |
63 // user selected. | 59 // user selected. |
64 // |source_profile| - importer profile to import. | 60 // |source_profile| - importer profile to import. |
65 // |target_profile| - profile to import into. | 61 // |target_profile| - profile to import into. |
66 // |items| - specifies which data to import (bitmask of importer::ImportItem). | 62 // |items| - specifies which data to import (bitmask of importer::ImportItem). |
67 // |writer| - called to actually write data back to the profile. | 63 // |writer| - called to actually write data back to the profile. |
68 virtual void StartImportSettings( | 64 virtual void StartImportSettings( |
69 const importer::SourceProfile& source_profile, | 65 const importer::SourceProfile& source_profile, |
70 Profile* target_profile, | 66 Profile* target_profile, |
71 uint16 items, | 67 uint16 items, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 115 |
120 private: | 116 private: |
121 friend class base::RefCountedThreadSafe<ImporterHost>; | 117 friend class base::RefCountedThreadSafe<ImporterHost>; |
122 | 118 |
123 // Launches the thread that starts the import task, unless bookmark or | 119 // Launches the thread that starts the import task, unless bookmark or |
124 // template model are not yet loaded. If load is not detected, this method | 120 // template model are not yet loaded. If load is not detected, this method |
125 // will be called when the loading observer sees that model loading is | 121 // will be called when the loading observer sees that model loading is |
126 // complete. | 122 // complete. |
127 virtual void InvokeTaskIfDone(); | 123 virtual void InvokeTaskIfDone(); |
128 | 124 |
129 // Called when IsGoogleGAIACookieInstalled is done. | |
130 void OnGoogleGAIACookieChecked(bool result); | |
131 | |
132 // BaseBookmarkModelObserver: | 125 // BaseBookmarkModelObserver: |
133 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE; | 126 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE; |
134 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE; | 127 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE; |
135 virtual void BookmarkModelChanged() OVERRIDE; | 128 virtual void BookmarkModelChanged() OVERRIDE; |
136 | 129 |
137 // content::NotificationObserver: | 130 // content::NotificationObserver: |
138 // Called when TemplateURLService has been loaded. | 131 // Called when TemplateURLService has been loaded. |
139 virtual void Observe(int type, | 132 virtual void Observe(int type, |
140 const content::NotificationSource& source, | 133 const content::NotificationSource& source, |
141 const content::NotificationDetails& details) OVERRIDE; | 134 const content::NotificationDetails& details) OVERRIDE; |
142 | 135 |
143 // chrome::BrowserListObserver | |
144 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | |
145 | |
146 // The task is the process of importing settings from other browsers. | 136 // The task is the process of importing settings from other browsers. |
147 base::Closure task_; | 137 base::Closure task_; |
148 | 138 |
149 // The importer used in the task. | 139 // The importer used in the task. |
150 scoped_refptr<Importer> importer_; | 140 scoped_refptr<Importer> importer_; |
151 | 141 |
152 // True if UI is not to be shown. | 142 // True if UI is not to be shown. |
153 bool headless_; | 143 bool headless_; |
154 | 144 |
155 // Parent window that we pass to the import lock dialog (i.e, the Firefox | 145 // Parent window that we pass to the import lock dialog (i.e, the Firefox |
156 // warning dialog). | 146 // warning dialog). |
157 gfx::NativeWindow parent_window_; | 147 gfx::NativeWindow parent_window_; |
158 | 148 |
159 // Used to add a new tab if we need the user to sign in. | |
160 Browser* browser_; | |
161 | |
162 // The observer that we need to notify about changes in the import process. | 149 // The observer that we need to notify about changes in the import process. |
163 importer::ImporterProgressObserver* observer_; | 150 importer::ImporterProgressObserver* observer_; |
164 | 151 |
165 // Firefox profile lock. | 152 // Firefox profile lock. |
166 scoped_ptr<FirefoxProfileLock> firefox_lock_; | 153 scoped_ptr<FirefoxProfileLock> firefox_lock_; |
167 | 154 |
168 DISALLOW_COPY_AND_ASSIGN(ImporterHost); | 155 DISALLOW_COPY_AND_ASSIGN(ImporterHost); |
169 }; | 156 }; |
170 | 157 |
171 #endif // CHROME_BROWSER_IMPORTER_IMPORTER_HOST_H_ | 158 #endif // CHROME_BROWSER_IMPORTER_IMPORTER_HOST_H_ |
OLD | NEW |