OLD | NEW |
---|---|
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 Loading... | |
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). | |
269 if (registrar_.IsEmpty()) { | 263 if (registrar_.IsEmpty()) { |
asargent_no_longer_on_chrome
2011/06/23 22:18:38
same question here - if we now expect to have one
Yoyo Zhou
2011/06/24 17:21:38
Done.
| |
270 for (size_t i = 0; i < arraysize(types); i++) { | 264 for (size_t i = 0; i < arraysize(types); i++) { |
271 registrar_.Add(this, | 265 registrar_.Add(this, |
272 types[i], | 266 types[i], |
273 NotificationService::AllSources()); | 267 Source<Profile>(profile)); |
268 registrar_.Add(this, | |
269 types[i], | |
270 Source<Profile>(profile->GetOffTheRecordProfile())); | |
274 } | 271 } |
275 } | 272 } |
276 } | 273 } |
277 | 274 |
278 void ExtensionManagementEventRouter::Observe( | 275 void ExtensionManagementEventRouter::Observe( |
279 NotificationType type, | 276 NotificationType type, |
280 const NotificationSource& source, | 277 const NotificationSource& source, |
281 const NotificationDetails& details) { | 278 const NotificationDetails& details) { |
282 const char* event_name = NULL; | 279 const char* event_name = NULL; |
283 switch (type.value) { | 280 switch (type.value) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 bool enabled = service->GetExtensionById(extension->id(), false) != NULL; | 315 bool enabled = service->GetExtensionById(extension->id(), false) != NULL; |
319 args.Append(CreateExtensionInfo(*extension, enabled)); | 316 args.Append(CreateExtensionInfo(*extension, enabled)); |
320 } | 317 } |
321 | 318 |
322 std::string args_json; | 319 std::string args_json; |
323 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 320 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); |
324 | 321 |
325 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 322 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
326 event_name, args_json, NULL, GURL()); | 323 event_name, args_json, NULL, GURL()); |
327 } | 324 } |
OLD | NEW |