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/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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 using base::IntToString; | 51 using base::IntToString; |
52 using content::BrowserThread; | 52 using content::BrowserThread; |
53 using content::UtilityProcessHost; | 53 using content::UtilityProcessHost; |
54 using content::UtilityProcessHostClient; | 54 using content::UtilityProcessHostClient; |
55 | 55 |
56 namespace keys = extension_management_api_constants; | 56 namespace keys = extension_management_api_constants; |
57 | 57 |
58 namespace extensions { | 58 namespace extensions { |
59 | 59 |
60 namespace events = event_names; | |
61 namespace management = api::management; | 60 namespace management = api::management; |
62 | 61 |
63 namespace { | 62 namespace { |
64 | 63 |
65 typedef std::vector<linked_ptr<management::ExtensionInfo> > ExtensionInfoList; | 64 typedef std::vector<linked_ptr<management::ExtensionInfo> > ExtensionInfoList; |
66 typedef std::vector<linked_ptr<management::IconInfo> > IconInfoList; | 65 typedef std::vector<linked_ptr<management::IconInfo> > IconInfoList; |
67 | 66 |
68 enum AutoConfirmForTest { | 67 enum AutoConfirmForTest { |
69 DO_NOT_SKIP = 0, | 68 DO_NOT_SKIP = 0, |
70 PROCEED, | 69 PROCEED, |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 int type, | 641 int type, |
643 const content::NotificationSource& source, | 642 const content::NotificationSource& source, |
644 const content::NotificationDetails& details) { | 643 const content::NotificationDetails& details) { |
645 const char* event_name = NULL; | 644 const char* event_name = NULL; |
646 Profile* profile = content::Source<Profile>(source).ptr(); | 645 Profile* profile = content::Source<Profile>(source).ptr(); |
647 CHECK(profile); | 646 CHECK(profile); |
648 CHECK(profile_->IsSameProfile(profile)); | 647 CHECK(profile_->IsSameProfile(profile)); |
649 | 648 |
650 switch (type) { | 649 switch (type) { |
651 case chrome::NOTIFICATION_EXTENSION_INSTALLED: | 650 case chrome::NOTIFICATION_EXTENSION_INSTALLED: |
652 event_name = events::kOnExtensionInstalled; | 651 event_name = event_names::kOnExtensionInstalled; |
653 break; | 652 break; |
654 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: | 653 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: |
655 event_name = events::kOnExtensionUninstalled; | 654 event_name = event_names::kOnExtensionUninstalled; |
656 break; | 655 break; |
657 case chrome::NOTIFICATION_EXTENSION_LOADED: | 656 case chrome::NOTIFICATION_EXTENSION_LOADED: |
658 event_name = events::kOnExtensionEnabled; | 657 event_name = event_names::kOnExtensionEnabled; |
659 break; | 658 break; |
660 case chrome::NOTIFICATION_EXTENSION_UNLOADED: | 659 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
661 event_name = events::kOnExtensionDisabled; | 660 event_name = event_names::kOnExtensionDisabled; |
662 break; | 661 break; |
663 default: | 662 default: |
664 NOTREACHED(); | 663 NOTREACHED(); |
665 return; | 664 return; |
666 } | 665 } |
667 | 666 |
668 scoped_ptr<ListValue> args(new ListValue()); | 667 scoped_ptr<ListValue> args(new ListValue()); |
669 if (event_name == events::kOnExtensionUninstalled) { | 668 if (event_name == event_names::kOnExtensionUninstalled) { |
670 args->Append(Value::CreateStringValue( | 669 args->Append(Value::CreateStringValue( |
671 content::Details<const Extension>(details).ptr()->id())); | 670 content::Details<const Extension>(details).ptr()->id())); |
672 } else { | 671 } else { |
673 const Extension* extension = NULL; | 672 const Extension* extension = NULL; |
674 if (event_name == events::kOnExtensionDisabled) { | 673 if (event_name == event_names::kOnExtensionDisabled) { |
675 extension = content::Details<UnloadedExtensionInfo>(details)->extension; | 674 extension = content::Details<UnloadedExtensionInfo>(details)->extension; |
676 } else { | 675 } else { |
677 extension = content::Details<const Extension>(details).ptr(); | 676 extension = content::Details<const Extension>(details).ptr(); |
678 } | 677 } |
679 CHECK(extension); | 678 CHECK(extension); |
680 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo( | 679 scoped_ptr<management::ExtensionInfo> info = CreateExtensionInfo( |
681 *extension, ExtensionSystem::Get(profile)); | 680 *extension, ExtensionSystem::Get(profile)); |
682 args->Append(info->ToValue().release()); | 681 args->Append(info->ToValue().release()); |
683 } | 682 } |
684 | 683 |
685 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 684 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
686 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); | 685 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); |
687 } | 686 } |
688 | 687 |
689 ManagementAPI::ManagementAPI(Profile* profile) | 688 ManagementAPI::ManagementAPI(Profile* profile) |
690 : profile_(profile) { | 689 : profile_(profile) { |
691 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 690 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
692 this, events::kOnExtensionInstalled); | 691 this, event_names::kOnExtensionInstalled); |
693 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 692 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
694 this, events::kOnExtensionUninstalled); | 693 this, event_names::kOnExtensionUninstalled); |
695 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 694 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
696 this, events::kOnExtensionEnabled); | 695 this, event_names::kOnExtensionEnabled); |
697 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 696 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
698 this, events::kOnExtensionDisabled); | 697 this, event_names::kOnExtensionDisabled); |
699 } | 698 } |
700 | 699 |
701 ManagementAPI::~ManagementAPI() { | 700 ManagementAPI::~ManagementAPI() { |
702 } | 701 } |
703 | 702 |
704 void ManagementAPI::Shutdown() { | 703 void ManagementAPI::Shutdown() { |
705 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 704 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
706 } | 705 } |
707 | 706 |
708 static base::LazyInstance<ProfileKeyedAPIFactory<ManagementAPI> > | 707 static base::LazyInstance<ProfileKeyedAPIFactory<ManagementAPI> > |
709 g_factory = LAZY_INSTANCE_INITIALIZER; | 708 g_factory = LAZY_INSTANCE_INITIALIZER; |
710 | 709 |
711 // static | 710 // static |
712 ProfileKeyedAPIFactory<ManagementAPI>* ManagementAPI::GetFactoryInstance() { | 711 ProfileKeyedAPIFactory<ManagementAPI>* ManagementAPI::GetFactoryInstance() { |
713 return &g_factory.Get(); | 712 return &g_factory.Get(); |
714 } | 713 } |
715 | 714 |
716 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) { | 715 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) { |
717 management_event_router_.reset(new ManagementEventRouter(profile_)); | 716 management_event_router_.reset(new ManagementEventRouter(profile_)); |
718 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 717 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
719 } | 718 } |
720 | 719 |
721 } // namespace extensions | 720 } // namespace extensions |
OLD | NEW |