Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: chrome/browser/importer/external_process_importer_host.cc

Issue 23710022: Convert NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED to CallbackList (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/bookmarks/bookmark_model.h" 9 #include "chrome/browser/bookmarks/bookmark_model.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
11 #include "chrome/browser/importer/external_process_importer_client.h" 11 #include "chrome/browser/importer/external_process_importer_client.h"
12 #include "chrome/browser/importer/firefox_profile_lock.h" 12 #include "chrome/browser/importer/firefox_profile_lock.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/in_process_importer_bridge.h" 15 #include "chrome/browser/importer/in_process_importer_bridge.h"
16 #include "chrome/browser/search_engines/template_url_service.h" 16 #include "chrome/browser/search_engines/template_url_service.h"
17 #include "chrome/browser/search_engines/template_url_service_factory.h" 17 #include "chrome/browser/search_engines/template_url_service_factory.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/notification_source.h"
20 19
21 using content::BrowserThread; 20 using content::BrowserThread;
22 21
23 ExternalProcessImporterHost::ExternalProcessImporterHost() 22 ExternalProcessImporterHost::ExternalProcessImporterHost()
24 : weak_ptr_factory_(this), 23 : headless_(false),
25 headless_(false),
26 parent_window_(NULL), 24 parent_window_(NULL),
27 observer_(NULL), 25 observer_(NULL),
28 profile_(NULL), 26 profile_(NULL),
29 waiting_for_bookmarkbar_model_(false), 27 waiting_for_bookmarkbar_model_(false),
30 installed_bookmark_observer_(false), 28 installed_bookmark_observer_(false),
31 is_source_readable_(true), 29 is_source_readable_(true),
32 client_(NULL), 30 client_(NULL),
33 items_(0), 31 items_(0),
34 cancelled_(false), 32 cancelled_(false),
35 import_process_launched_(false) { 33 import_process_launched_(false),
34 weak_ptr_factory_(this) {
36 } 35 }
37 36
38 void ExternalProcessImporterHost::Cancel() { 37 void ExternalProcessImporterHost::Cancel() {
39 cancelled_ = true; 38 cancelled_ = true;
40 if (import_process_launched_) 39 if (import_process_launched_)
41 client_->Cancel(); 40 client_->Cancel();
42 NotifyImportEnded(); // Tells the observer that we're done, and deletes us. 41 NotifyImportEnded(); // Tells the observer that we're done, and deletes us.
43 } 42 }
44 43
45 void ExternalProcessImporterHost::StartImportSettings( 44 void ExternalProcessImporterHost::StartImportSettings(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 91 }
93 92
94 ExternalProcessImporterHost::~ExternalProcessImporterHost() { 93 ExternalProcessImporterHost::~ExternalProcessImporterHost() {
95 if (installed_bookmark_observer_) { 94 if (installed_bookmark_observer_) {
96 DCHECK(profile_); 95 DCHECK(profile_);
97 BookmarkModelFactory::GetForProfile(profile_)->RemoveObserver(this); 96 BookmarkModelFactory::GetForProfile(profile_)->RemoveObserver(this);
98 } 97 }
99 } 98 }
100 99
101 void ExternalProcessImporterHost::LaunchImportIfReady() { 100 void ExternalProcessImporterHost::LaunchImportIfReady() {
102 if (waiting_for_bookmarkbar_model_ || !registrar_.IsEmpty() || 101 if (waiting_for_bookmarkbar_model_ || template_service_subscription_.get() ||
103 !is_source_readable_ || cancelled_) 102 !is_source_readable_ || cancelled_)
104 return; 103 return;
105 104
106 // This is the in-process half of the bridge, which catches data from the IPC 105 // 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 106 // pipe and feeds it to the ProfileWriter. The external process half of the
108 // bridge lives in the external process (see ProfileImportThread). 107 // bridge lives in the external process (see ProfileImportThread).
109 // The ExternalProcessImporterClient created in the next line owns the bridge, 108 // The ExternalProcessImporterClient created in the next line owns the bridge,
110 // and will delete it. 109 // and will delete it.
111 InProcessImporterBridge* bridge = 110 InProcessImporterBridge* bridge =
112 new InProcessImporterBridge(writer_.get(), 111 new InProcessImporterBridge(writer_.get(),
(...skipping 15 matching lines...) Expand all
128 } 127 }
129 128
130 void ExternalProcessImporterHost::BookmarkModelBeingDeleted( 129 void ExternalProcessImporterHost::BookmarkModelBeingDeleted(
131 BookmarkModel* model) { 130 BookmarkModel* model) {
132 installed_bookmark_observer_ = false; 131 installed_bookmark_observer_ = false;
133 } 132 }
134 133
135 void ExternalProcessImporterHost::BookmarkModelChanged() { 134 void ExternalProcessImporterHost::BookmarkModelChanged() {
136 } 135 }
137 136
138 void ExternalProcessImporterHost::Observe(int type, 137 void ExternalProcessImporterHost::OnTemplateURLServiceLoaded() {
139 const content::NotificationSource& source, 138 template_service_subscription_.reset();
140 const content::NotificationDetails& details) {
141 DCHECK_EQ(type, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED);
142 registrar_.RemoveAll();
143 LaunchImportIfReady(); 139 LaunchImportIfReady();
144 } 140 }
145 141
146 void ExternalProcessImporterHost::ShowWarningDialog() { 142 void ExternalProcessImporterHost::ShowWarningDialog() {
147 DCHECK(!headless_); 143 DCHECK(!headless_);
148 importer::ShowImportLockDialog( 144 importer::ShowImportLockDialog(
149 parent_window_, 145 parent_window_,
150 base::Bind(&ExternalProcessImporterHost::OnImportLockDialogEnd, 146 base::Bind(&ExternalProcessImporterHost::OnImportLockDialogEnd,
151 weak_ptr_factory_.GetWeakPtr())); 147 weak_ptr_factory_.GetWeakPtr()));
152 } 148 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 installed_bookmark_observer_ = true; 197 installed_bookmark_observer_ = true;
202 } 198 }
203 199
204 // Observes the TemplateURLService if needed to import search engines from the 200 // Observes the TemplateURLService if needed to import search engines from the
205 // other browser. We also check to see if we're importing bookmarks because 201 // other browser. We also check to see if we're importing bookmarks because
206 // we can import bookmark keywords from Firefox as search engines. 202 // we can import bookmark keywords from Firefox as search engines.
207 if ((items & importer::SEARCH_ENGINES) || (items & importer::FAVORITES)) { 203 if ((items & importer::SEARCH_ENGINES) || (items & importer::FAVORITES)) {
208 if (!writer_->TemplateURLServiceIsLoaded()) { 204 if (!writer_->TemplateURLServiceIsLoaded()) {
209 TemplateURLService* model = 205 TemplateURLService* model =
210 TemplateURLServiceFactory::GetForProfile(profile_); 206 TemplateURLServiceFactory::GetForProfile(profile_);
211 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, 207 template_service_subscription_ = model->RegisterOnLoadedCallback(
212 content::Source<TemplateURLService>(model)); 208 base::Bind(&ExternalProcessImporterHost::OnTemplateURLServiceLoaded,
209 weak_ptr_factory_.GetWeakPtr()));
213 model->Load(); 210 model->Load();
214 } 211 }
215 } 212 }
216 } 213 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/external_process_importer_host.h ('k') | chrome/browser/profile_resetter/profile_resetter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698