OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/importer/importer_host.h" | 5 #include "chrome/browser/importer/importer_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/importer/firefox_profile_lock.h" | 11 #include "chrome/browser/importer/firefox_profile_lock.h" |
12 #include "chrome/browser/importer/importer.h" | 12 #include "chrome/browser/importer/importer.h" |
13 #include "chrome/browser/importer/importer_lock_dialog.h" | 13 #include "chrome/browser/importer/importer_lock_dialog.h" |
14 #include "chrome/browser/importer/importer_progress_observer.h" | 14 #include "chrome/browser/importer/importer_progress_observer.h" |
15 #include "chrome/browser/importer/importer_type.h" | 15 #include "chrome/browser/importer/importer_type.h" |
16 #include "chrome/browser/importer/in_process_importer_bridge.h" | 16 #include "chrome/browser/importer/in_process_importer_bridge.h" |
17 #include "chrome/browser/importer/toolbar_importer_utils.h" | 17 #include "chrome/browser/importer/toolbar_importer_utils.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/search_engines/template_url.h" | 20 #include "chrome/browser/search_engines/template_url.h" |
21 #include "chrome/browser/search_engines/template_url_service.h" | 21 #include "chrome/browser/search_engines/template_url_service.h" |
22 #include "chrome/browser/search_engines/template_url_service_factory.h" | 22 #include "chrome/browser/search_engines/template_url_service_factory.h" |
23 #include "chrome/browser/ui/browser_finder.h" | |
24 #include "chrome/browser/ui/browser_tabstrip.h" | 23 #include "chrome/browser/ui/browser_tabstrip.h" |
25 #include "chrome/browser/ui/simple_message_box.h" | 24 #include "chrome/browser/ui/simple_message_box.h" |
26 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
27 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
28 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
30 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
31 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
32 | 31 |
33 using content::BrowserThread; | 32 using content::BrowserThread; |
34 | 33 |
35 ImporterHost::ImporterHost() | 34 ImporterHost::ImporterHost() |
36 : profile_(NULL), | 35 : profile_(NULL), |
37 waiting_for_bookmarkbar_model_(false), | 36 waiting_for_bookmarkbar_model_(false), |
38 installed_bookmark_observer_(false), | 37 installed_bookmark_observer_(false), |
39 is_source_readable_(true), | 38 is_source_readable_(true), |
40 importer_(NULL), | 39 importer_(NULL), |
41 headless_(false), | 40 headless_(false), |
42 parent_window_(NULL), | 41 parent_window_(NULL), |
42 browser_(NULL), | |
43 observer_(NULL) { | 43 observer_(NULL) { |
44 BrowserList::AddObserver(this); | |
44 } | 45 } |
45 | 46 |
46 void ImporterHost::ShowWarningDialog() { | 47 void ImporterHost::ShowWarningDialog() { |
47 if (headless_) | 48 if (headless_) |
48 OnImportLockDialogEnd(false); | 49 OnImportLockDialogEnd(false); |
49 else | 50 else |
50 importer::ShowImportLockDialog(parent_window_, this); | 51 importer::ShowImportLockDialog(parent_window_, this); |
51 } | 52 } |
52 | 53 |
53 void ImporterHost::OnImportLockDialogEnd(bool is_continue) { | 54 void ImporterHost::OnImportLockDialogEnd(bool is_continue) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 } | 157 } |
157 | 158 |
158 void ImporterHost::OnGoogleGAIACookieChecked(bool result) { | 159 void ImporterHost::OnGoogleGAIACookieChecked(bool result) { |
159 #if defined(OS_WIN) | 160 #if defined(OS_WIN) |
160 if (!result) { | 161 if (!result) { |
161 chrome::ShowMessageBox(NULL, | 162 chrome::ShowMessageBox(NULL, |
162 l10n_util::GetStringUTF16(IDS_IMPORTER_GOOGLE_LOGIN_TEXT), string16(), | 163 l10n_util::GetStringUTF16(IDS_IMPORTER_GOOGLE_LOGIN_TEXT), string16(), |
163 chrome::MESSAGE_BOX_TYPE_INFORMATION); | 164 chrome::MESSAGE_BOX_TYPE_INFORMATION); |
164 | 165 |
165 GURL url("https://accounts.google.com/ServiceLogin"); | 166 GURL url("https://accounts.google.com/ServiceLogin"); |
166 DCHECK(profile_); | 167 if (browser_) |
167 Browser* browser = browser::FindLastActiveWithProfile(profile_); | 168 chrome::AddSelectedTabWithURL(browser_, url, |
168 if (browser) | |
169 chrome::AddSelectedTabWithURL(browser, url, | |
170 content::PAGE_TRANSITION_TYPED); | 169 content::PAGE_TRANSITION_TYPED); |
171 | 170 |
172 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 171 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
173 &ImporterHost::OnImportLockDialogEnd, this, false)); | 172 &ImporterHost::OnImportLockDialogEnd, this, false)); |
174 } else { | 173 } else { |
175 is_source_readable_ = true; | 174 is_source_readable_ = true; |
176 InvokeTaskIfDone(); | 175 InvokeTaskIfDone(); |
177 } | 176 } |
178 #endif | 177 #endif |
179 } | 178 } |
180 | 179 |
181 void ImporterHost::Cancel() { | 180 void ImporterHost::Cancel() { |
182 if (importer_) | 181 if (importer_) |
183 importer_->Cancel(); | 182 importer_->Cancel(); |
184 } | 183 } |
185 | 184 |
186 ImporterHost::~ImporterHost() { | 185 ImporterHost::~ImporterHost() { |
186 BrowserList::RemoveObserver(this); | |
187 if (NULL != importer_) | 187 if (NULL != importer_) |
188 importer_->Release(); | 188 importer_->Release(); |
189 | 189 |
190 if (installed_bookmark_observer_) { | 190 if (installed_bookmark_observer_) { |
191 DCHECK(profile_); | 191 DCHECK(profile_); |
192 profile_->GetBookmarkModel()->RemoveObserver(this); | 192 profile_->GetBookmarkModel()->RemoveObserver(this); |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 void ImporterHost::CheckForFirefoxLock( | 196 void ImporterHost::CheckForFirefoxLock( |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 void ImporterHost::BookmarkModelChanged() { | 259 void ImporterHost::BookmarkModelChanged() { |
260 } | 260 } |
261 | 261 |
262 void ImporterHost::Observe(int type, | 262 void ImporterHost::Observe(int type, |
263 const content::NotificationSource& source, | 263 const content::NotificationSource& source, |
264 const content::NotificationDetails& details) { | 264 const content::NotificationDetails& details) { |
265 DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); | 265 DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); |
266 registrar_.RemoveAll(); | 266 registrar_.RemoveAll(); |
267 InvokeTaskIfDone(); | 267 InvokeTaskIfDone(); |
268 } | 268 } |
269 | |
270 void ImporterHost::OnBrowserRemoved(Browser* browser) { | |
271 if (browser_ == browser) | |
272 browser_ = NULL; | |
Ben Goodger (Google)
2012/07/10 15:13:10
idle thinking... would be cool if this could someh
| |
273 } | |
OLD | NEW |