| 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/message_loop.h" | |
| 9 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 10 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model.h" | 11 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 14 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/importer/firefox_profile_lock.h" | 14 #include "chrome/browser/importer/firefox_profile_lock.h" |
| 16 #include "chrome/browser/importer/importer.h" | 15 #include "chrome/browser/importer/importer.h" |
| 17 #include "chrome/browser/importer/importer_lock_dialog.h" | 16 #include "chrome/browser/importer/importer_lock_dialog.h" |
| 18 #include "chrome/browser/importer/importer_progress_observer.h" | 17 #include "chrome/browser/importer/importer_progress_observer.h" |
| 19 #include "chrome/browser/importer/importer_type.h" | 18 #include "chrome/browser/importer/importer_type.h" |
| 20 #include "chrome/browser/importer/in_process_importer_bridge.h" | 19 #include "chrome/browser/importer/in_process_importer_bridge.h" |
| 21 #include "chrome/browser/importer/toolbar_importer_utils.h" | |
| 22 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/search_engines/template_url.h" | 21 #include "chrome/browser/search_engines/template_url.h" |
| 24 #include "chrome/browser/search_engines/template_url_service.h" | 22 #include "chrome/browser/search_engines/template_url_service.h" |
| 25 #include "chrome/browser/search_engines/template_url_service_factory.h" | 23 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 26 #include "chrome/browser/ui/browser_list.h" | |
| 27 #include "chrome/browser/ui/browser_tabstrip.h" | |
| 28 #include "chrome/browser/ui/simple_message_box.h" | |
| 29 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 30 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 31 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
| 33 #include "grit/chromium_strings.h" | |
| 34 #include "grit/generated_resources.h" | |
| 35 #include "ui/base/l10n/l10n_util.h" | |
| 36 | 28 |
| 37 using content::BrowserThread; | 29 using content::BrowserThread; |
| 38 | 30 |
| 39 ImporterHost::ImporterHost() | 31 ImporterHost::ImporterHost() |
| 40 : weak_ptr_factory_(this), | 32 : weak_ptr_factory_(this), |
| 41 profile_(NULL), | 33 profile_(NULL), |
| 42 waiting_for_bookmarkbar_model_(false), | 34 waiting_for_bookmarkbar_model_(false), |
| 43 installed_bookmark_observer_(false), | 35 installed_bookmark_observer_(false), |
| 44 is_source_readable_(true), | 36 is_source_readable_(true), |
| 45 headless_(false), | 37 headless_(false), |
| 46 parent_window_(NULL), | 38 parent_window_(NULL), |
| 47 browser_(NULL), | |
| 48 observer_(NULL) { | 39 observer_(NULL) { |
| 49 BrowserList::AddObserver(this); | |
| 50 } | 40 } |
| 51 | 41 |
| 52 void ImporterHost::ShowWarningDialog() { | 42 void ImporterHost::ShowWarningDialog() { |
| 53 DCHECK(!headless_); | 43 DCHECK(!headless_); |
| 54 importer::ShowImportLockDialog( | 44 importer::ShowImportLockDialog( |
| 55 parent_window_, | 45 parent_window_, |
| 56 base::Bind(&ImporterHost::OnImportLockDialogEnd, | 46 base::Bind(&ImporterHost::OnImportLockDialogEnd, |
| 57 weak_ptr_factory_.GetWeakPtr())); | 47 weak_ptr_factory_.GetWeakPtr())); |
| 58 } | 48 } |
| 59 | 49 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 new InProcessImporterBridge(writer_.get(), | 132 new InProcessImporterBridge(writer_.get(), |
| 143 weak_ptr_factory_.GetWeakPtr())); | 133 weak_ptr_factory_.GetWeakPtr())); |
| 144 task_ = base::Bind( | 134 task_ = base::Bind( |
| 145 &Importer::StartImport, importer_, source_profile, items, bridge); | 135 &Importer::StartImport, importer_, source_profile, items, bridge); |
| 146 | 136 |
| 147 if (!CheckForFirefoxLock(source_profile)) { | 137 if (!CheckForFirefoxLock(source_profile)) { |
| 148 NotifyImportEnded(); | 138 NotifyImportEnded(); |
| 149 return; | 139 return; |
| 150 } | 140 } |
| 151 | 141 |
| 152 #if defined(OS_WIN) | |
| 153 // For google toolbar import, we need the user to log in and store their GAIA | |
| 154 // credentials. | |
| 155 if (source_profile.importer_type == importer::TYPE_GOOGLE_TOOLBAR5) { | |
| 156 toolbar_importer_utils::IsGoogleGAIACookieInstalled( | |
| 157 base::Bind(&ImporterHost::OnGoogleGAIACookieChecked, | |
| 158 weak_ptr_factory_.GetWeakPtr()), | |
| 159 profile_); | |
| 160 is_source_readable_ = false; | |
| 161 } | |
| 162 #endif | |
| 163 | |
| 164 CheckForLoadedModels(items); | 142 CheckForLoadedModels(items); |
| 165 InvokeTaskIfDone(); | 143 InvokeTaskIfDone(); |
| 166 } | 144 } |
| 167 | 145 |
| 168 void ImporterHost::OnGoogleGAIACookieChecked(bool result) { | |
| 169 #if defined(OS_WIN) | |
| 170 if (!result) { | |
| 171 chrome::ShowMessageBox( | |
| 172 NULL, | |
| 173 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | |
| 174 l10n_util::GetStringUTF16(IDS_IMPORTER_GOOGLE_LOGIN_TEXT), | |
| 175 chrome::MESSAGE_BOX_TYPE_INFORMATION); | |
| 176 | |
| 177 GURL url("https://accounts.google.com/ServiceLogin"); | |
| 178 if (browser_) | |
| 179 chrome::AddSelectedTabWithURL(browser_, url, | |
| 180 content::PAGE_TRANSITION_TYPED); | |
| 181 | |
| 182 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | |
| 183 &ImporterHost::OnImportLockDialogEnd, | |
| 184 weak_ptr_factory_.GetWeakPtr(), false)); | |
| 185 } else { | |
| 186 is_source_readable_ = true; | |
| 187 InvokeTaskIfDone(); | |
| 188 } | |
| 189 #endif | |
| 190 } | |
| 191 | |
| 192 ImporterHost::~ImporterHost() { | 146 ImporterHost::~ImporterHost() { |
| 193 BrowserList::RemoveObserver(this); | |
| 194 | |
| 195 if (installed_bookmark_observer_) { | 147 if (installed_bookmark_observer_) { |
| 196 DCHECK(profile_); | 148 DCHECK(profile_); |
| 197 BookmarkModelFactory::GetForProfile(profile_)->RemoveObserver(this); | 149 BookmarkModelFactory::GetForProfile(profile_)->RemoveObserver(this); |
| 198 } | 150 } |
| 199 } | 151 } |
| 200 | 152 |
| 201 bool ImporterHost::CheckForFirefoxLock( | 153 bool ImporterHost::CheckForFirefoxLock( |
| 202 const importer::SourceProfile& source_profile) { | 154 const importer::SourceProfile& source_profile) { |
| 203 if (source_profile.importer_type != importer::TYPE_FIREFOX3) | 155 if (source_profile.importer_type != importer::TYPE_FIREFOX3) |
| 204 return true; | 156 return true; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 void ImporterHost::BookmarkModelChanged() { | 220 void ImporterHost::BookmarkModelChanged() { |
| 269 } | 221 } |
| 270 | 222 |
| 271 void ImporterHost::Observe(int type, | 223 void ImporterHost::Observe(int type, |
| 272 const content::NotificationSource& source, | 224 const content::NotificationSource& source, |
| 273 const content::NotificationDetails& details) { | 225 const content::NotificationDetails& details) { |
| 274 DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); | 226 DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); |
| 275 registrar_.RemoveAll(); | 227 registrar_.RemoveAll(); |
| 276 InvokeTaskIfDone(); | 228 InvokeTaskIfDone(); |
| 277 } | 229 } |
| 278 | |
| 279 void ImporterHost::OnBrowserRemoved(Browser* browser) { | |
| 280 if (browser_ == browser) | |
| 281 browser_ = NULL; | |
| 282 } | |
| OLD | NEW |