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/external_process_importer_host.h" | 5 #include "chrome/browser/importer/external_process_importer_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/importer/external_process_importer_client.h" | 10 #include "chrome/browser/importer/external_process_importer_client.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_lock_dialog.h" | 12 #include "chrome/browser/importer/importer_lock_dialog.h" |
13 #include "chrome/browser/importer/importer_progress_observer.h" | 13 #include "chrome/browser/importer/importer_progress_observer.h" |
14 #include "chrome/browser/importer/in_process_importer_bridge.h" | 14 #include "chrome/browser/importer/in_process_importer_bridge.h" |
| 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/search_engines/template_url_service_factory.h" | 16 #include "chrome/browser/search_engines/template_url_service_factory.h" |
16 #include "components/bookmarks/browser/bookmark_model.h" | 17 #include "components/bookmarks/browser/bookmark_model.h" |
17 #include "components/search_engines/template_url_service.h" | 18 #include "components/search_engines/template_url_service.h" |
18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
19 | 20 |
20 using bookmarks::BookmarkModel; | 21 using bookmarks::BookmarkModel; |
21 using content::BrowserThread; | 22 using content::BrowserThread; |
22 | 23 |
23 ExternalProcessImporterHost::ExternalProcessImporterHost() | 24 ExternalProcessImporterHost::ExternalProcessImporterHost() |
24 : headless_(false), | 25 : headless_(false), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 88 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
88 firefox_lock_.reset(); | 89 firefox_lock_.reset(); |
89 if (observer_) | 90 if (observer_) |
90 observer_->ImportEnded(); | 91 observer_->ImportEnded(); |
91 delete this; | 92 delete this; |
92 } | 93 } |
93 | 94 |
94 ExternalProcessImporterHost::~ExternalProcessImporterHost() { | 95 ExternalProcessImporterHost::~ExternalProcessImporterHost() { |
95 if (installed_bookmark_observer_) { | 96 if (installed_bookmark_observer_) { |
96 DCHECK(profile_); | 97 DCHECK(profile_); |
97 BookmarkModelFactory::GetForProfile(profile_)->RemoveObserver(this); | 98 BookmarkModelFactory::GetForBrowserContext(profile_)->RemoveObserver(this); |
98 } | 99 } |
99 } | 100 } |
100 | 101 |
101 void ExternalProcessImporterHost::LaunchImportIfReady() { | 102 void ExternalProcessImporterHost::LaunchImportIfReady() { |
102 if (waiting_for_bookmarkbar_model_ || template_service_subscription_.get() || | 103 if (waiting_for_bookmarkbar_model_ || template_service_subscription_.get() || |
103 !is_source_readable_ || cancelled_) | 104 !is_source_readable_ || cancelled_) |
104 return; | 105 return; |
105 | 106 |
106 // This is the in-process half of the bridge, which catches data from the IPC | 107 // This is the in-process half of the bridge, which catches data from the IPC |
107 // pipe and feeds it to the ProfileWriter. The external process half of the | 108 // pipe and feeds it to the ProfileWriter. The external process half of the |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return true; | 186 return true; |
186 } | 187 } |
187 | 188 |
188 void ExternalProcessImporterHost::CheckForLoadedModels(uint16_t items) { | 189 void ExternalProcessImporterHost::CheckForLoadedModels(uint16_t items) { |
189 // A target profile must be loaded by StartImportSettings(). | 190 // A target profile must be loaded by StartImportSettings(). |
190 DCHECK(profile_); | 191 DCHECK(profile_); |
191 | 192 |
192 // BookmarkModel should be loaded before adding IE favorites. So we observe | 193 // BookmarkModel should be loaded before adding IE favorites. So we observe |
193 // the BookmarkModel if needed, and start the task after it has been loaded. | 194 // the BookmarkModel if needed, and start the task after it has been loaded. |
194 if ((items & importer::FAVORITES) && !writer_->BookmarkModelIsLoaded()) { | 195 if ((items & importer::FAVORITES) && !writer_->BookmarkModelIsLoaded()) { |
195 BookmarkModelFactory::GetForProfile(profile_)->AddObserver(this); | 196 BookmarkModelFactory::GetForBrowserContext(profile_)->AddObserver(this); |
196 waiting_for_bookmarkbar_model_ = true; | 197 waiting_for_bookmarkbar_model_ = true; |
197 installed_bookmark_observer_ = true; | 198 installed_bookmark_observer_ = true; |
198 } | 199 } |
199 | 200 |
200 // Observes the TemplateURLService if needed to import search engines from the | 201 // Observes the TemplateURLService if needed to import search engines from the |
201 // other browser. We also check to see if we're importing bookmarks because | 202 // other browser. We also check to see if we're importing bookmarks because |
202 // we can import bookmark keywords from Firefox as search engines. | 203 // we can import bookmark keywords from Firefox as search engines. |
203 if ((items & importer::SEARCH_ENGINES) || (items & importer::FAVORITES)) { | 204 if ((items & importer::SEARCH_ENGINES) || (items & importer::FAVORITES)) { |
204 if (!writer_->TemplateURLServiceIsLoaded()) { | 205 if (!writer_->TemplateURLServiceIsLoaded()) { |
205 TemplateURLService* model = | 206 TemplateURLService* model = |
206 TemplateURLServiceFactory::GetForProfile(profile_); | 207 TemplateURLServiceFactory::GetForProfile(profile_); |
207 template_service_subscription_ = model->RegisterOnLoadedCallback( | 208 template_service_subscription_ = model->RegisterOnLoadedCallback( |
208 base::Bind(&ExternalProcessImporterHost::OnTemplateURLServiceLoaded, | 209 base::Bind(&ExternalProcessImporterHost::OnTemplateURLServiceLoaded, |
209 weak_ptr_factory_.GetWeakPtr())); | 210 weak_ptr_factory_.GetWeakPtr())); |
210 model->Load(); | 211 model->Load(); |
211 } | 212 } |
212 } | 213 } |
213 } | 214 } |
OLD | NEW |