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

Side by Side Diff: chrome/browser/extensions/extension_management_api.cc

Issue 7243012: Change many extension event routers to not be singletons and to be more profile-aware. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bookmark remove observer Created 9 years, 6 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) 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 #include "chrome/browser/extensions/extension_management_api.h" 5 #include "chrome/browser/extensions/extension_management_api.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 error_ = ExtensionErrorUtils::FormatErrorMessage( 241 error_ = ExtensionErrorUtils::FormatErrorMessage(
242 kUserCantDisableError, extension_id); 242 kUserCantDisableError, extension_id);
243 return false; 243 return false;
244 } 244 }
245 245
246 service()->UninstallExtension(extension_id, false /* external_uninstall */, 246 service()->UninstallExtension(extension_id, false /* external_uninstall */,
247 NULL); 247 NULL);
248 return true; 248 return true;
249 } 249 }
250 250
251 // static
252 ExtensionManagementEventRouter* ExtensionManagementEventRouter::GetInstance() {
253 return Singleton<ExtensionManagementEventRouter>::get();
254 }
255
256 ExtensionManagementEventRouter::ExtensionManagementEventRouter() {} 251 ExtensionManagementEventRouter::ExtensionManagementEventRouter() {}
257 252
258 ExtensionManagementEventRouter::~ExtensionManagementEventRouter() {} 253 ExtensionManagementEventRouter::~ExtensionManagementEventRouter() {}
259 254
260 void ExtensionManagementEventRouter::Init() { 255 void ExtensionManagementEventRouter::ObserveProfile(Profile* profile) {
261 NotificationType::Type types[] = { 256 NotificationType::Type types[] = {
262 NotificationType::EXTENSION_INSTALLED, 257 NotificationType::EXTENSION_INSTALLED,
263 NotificationType::EXTENSION_UNINSTALLED, 258 NotificationType::EXTENSION_UNINSTALLED,
264 NotificationType::EXTENSION_LOADED, 259 NotificationType::EXTENSION_LOADED,
265 NotificationType::EXTENSION_UNLOADED 260 NotificationType::EXTENSION_UNLOADED
266 }; 261 };
267 262
268 // Don't re-init (eg in the case of multiple profiles). 263 CHECK(registrar_.IsEmpty());
269 if (registrar_.IsEmpty()) { 264 for (size_t i = 0; i < arraysize(types); i++) {
270 for (size_t i = 0; i < arraysize(types); i++) { 265 registrar_.Add(this,
271 registrar_.Add(this, 266 types[i],
272 types[i], 267 Source<Profile>(profile));
273 NotificationService::AllSources()); 268 registrar_.Add(this,
274 } 269 types[i],
270 Source<Profile>(profile->GetOffTheRecordProfile()));
275 } 271 }
276 } 272 }
277 273
278 void ExtensionManagementEventRouter::Observe( 274 void ExtensionManagementEventRouter::Observe(
279 NotificationType type, 275 NotificationType type,
280 const NotificationSource& source, 276 const NotificationSource& source,
281 const NotificationDetails& details) { 277 const NotificationDetails& details) {
282 const char* event_name = NULL; 278 const char* event_name = NULL;
283 switch (type.value) { 279 switch (type.value) {
284 case NotificationType::EXTENSION_INSTALLED: 280 case NotificationType::EXTENSION_INSTALLED:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 bool enabled = service->GetExtensionById(extension->id(), false) != NULL; 314 bool enabled = service->GetExtensionById(extension->id(), false) != NULL;
319 args.Append(CreateExtensionInfo(*extension, enabled)); 315 args.Append(CreateExtensionInfo(*extension, enabled));
320 } 316 }
321 317
322 std::string args_json; 318 std::string args_json;
323 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); 319 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json);
324 320
325 profile->GetExtensionEventRouter()->DispatchEventToRenderers( 321 profile->GetExtensionEventRouter()->DispatchEventToRenderers(
326 event_name, args_json, NULL, GURL()); 322 event_name, args_json, NULL, GURL());
327 } 323 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_management_api.h ('k') | chrome/browser/extensions/extension_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698