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

Side by Side Diff: chrome/browser/extensions/api/management/management_api.cc

Issue 14238037: Made it possible to tell whether an extension is being installed or updated. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added extra check. Created 7 years, 7 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
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/extensions/api/management/management_api.h" 5 #include "chrome/browser/extensions/api/management/management_api.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 } 637 }
638 } 638 }
639 639
640 ManagementEventRouter::~ManagementEventRouter() {} 640 ManagementEventRouter::~ManagementEventRouter() {}
641 641
642 void ManagementEventRouter::Observe( 642 void ManagementEventRouter::Observe(
643 int type, 643 int type,
644 const content::NotificationSource& source, 644 const content::NotificationSource& source,
645 const content::NotificationDetails& details) { 645 const content::NotificationDetails& details) {
646 const char* event_name = NULL; 646 const char* event_name = NULL;
647 const Extension* extension = NULL;
647 Profile* profile = content::Source<Profile>(source).ptr(); 648 Profile* profile = content::Source<Profile>(source).ptr();
648 CHECK(profile); 649 CHECK(profile);
649 CHECK(profile_->IsSameProfile(profile)); 650 CHECK(profile_->IsSameProfile(profile));
650 651
651 switch (type) { 652 switch (type) {
652 case chrome::NOTIFICATION_EXTENSION_INSTALLED: 653 case chrome::NOTIFICATION_EXTENSION_INSTALLED:
653 event_name = events::kOnExtensionInstalled; 654 event_name = events::kOnExtensionInstalled;
655 extension =
656 content::Details<const InstalledExtensionInfo>(details)->extension;
654 break; 657 break;
655 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: 658 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED:
656 event_name = events::kOnExtensionUninstalled; 659 event_name = events::kOnExtensionUninstalled;
660 extension = content::Details<const Extension>(details).ptr();
657 break; 661 break;
658 case chrome::NOTIFICATION_EXTENSION_LOADED: 662 case chrome::NOTIFICATION_EXTENSION_LOADED:
659 event_name = events::kOnExtensionEnabled; 663 event_name = events::kOnExtensionEnabled;
664 extension = content::Details<const Extension>(details).ptr();
660 break; 665 break;
661 case chrome::NOTIFICATION_EXTENSION_UNLOADED: 666 case chrome::NOTIFICATION_EXTENSION_UNLOADED:
662 event_name = events::kOnExtensionDisabled; 667 event_name = events::kOnExtensionDisabled;
668 extension =
669 content::Details<const UnloadedExtensionInfo>(details)->extension;
663 break; 670 break;
664 default: 671 default:
665 NOTREACHED(); 672 NOTREACHED();
666 return; 673 return;
667 } 674 }
675 DCHECK(event_name);
676 DCHECK(extension);
668 677
669 scoped_ptr<ListValue> args(new ListValue()); 678 scoped_ptr<ListValue> args(new ListValue());
670 if (event_name == events::kOnExtensionUninstalled) { 679 if (event_name == events::kOnExtensionUninstalled) {
671 args->Append(Value::CreateStringValue( 680 args->Append(Value::CreateStringValue(extension->id()));
672 content::Details<const Extension>(details).ptr()->id()));
673 } else { 681 } else {
674 const Extension* extension = NULL;
675 if (event_name == events::kOnExtensionDisabled) {
676 extension = content::Details<UnloadedExtensionInfo>(details)->extension;
677 } else {
678 extension = content::Details<const Extension>(details).ptr();
679 }
680 CHECK(extension);
681 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo( 682 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo(
682 *extension, ExtensionSystem::Get(profile)); 683 *extension, ExtensionSystem::Get(profile));
683 args->Append(info->ToValue().release()); 684 args->Append(info->ToValue().release());
684 } 685 }
685 686
686 scoped_ptr<Event> event(new Event(event_name, args.Pass())); 687 scoped_ptr<Event> event(new Event(event_name, args.Pass()));
687 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); 688 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass());
688 } 689 }
689 690
690 ManagementAPI::ManagementAPI(Profile* profile) 691 ManagementAPI::ManagementAPI(Profile* profile)
(...skipping 22 matching lines...) Expand all
713 ProfileKeyedAPIFactory<ManagementAPI>* ManagementAPI::GetFactoryInstance() { 714 ProfileKeyedAPIFactory<ManagementAPI>* ManagementAPI::GetFactoryInstance() {
714 return &g_factory.Get(); 715 return &g_factory.Get();
715 } 716 }
716 717
717 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) { 718 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) {
718 management_event_router_.reset(new ManagementEventRouter(profile_)); 719 management_event_router_.reset(new ManagementEventRouter(profile_));
719 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); 720 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
720 } 721 }
721 722
722 } // namespace extensions 723 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698