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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/task.h" | 21 #include "base/task.h" |
22 #include "base/time.h" | 22 #include "base/time.h" |
23 #include "base/tuple.h" | 23 #include "base/tuple.h" |
24 #include "chrome/browser/extensions/apps_promo.h" | 24 #include "chrome/browser/extensions/apps_promo.h" |
25 #include "chrome/browser/extensions/extension_app_api.h" | 25 #include "chrome/browser/extensions/extension_app_api.h" |
26 #include "chrome/browser/extensions/extension_icon_manager.h" | 26 #include "chrome/browser/extensions/extension_icon_manager.h" |
27 #include "chrome/browser/extensions/extension_menu_manager.h" | 27 #include "chrome/browser/extensions/extension_menu_manager.h" |
28 #include "chrome/browser/extensions/extension_prefs.h" | 28 #include "chrome/browser/extensions/extension_prefs.h" |
29 #include "chrome/browser/extensions/extension_permissions_api.h" | 29 #include "chrome/browser/extensions/extension_permissions_api.h" |
30 #include "chrome/browser/extensions/extension_process_manager.h" | 30 #include "chrome/browser/extensions/extension_process_manager.h" |
31 #include "chrome/browser/extensions/extension_sync_data.h" | |
32 #include "chrome/browser/extensions/extension_toolbar_model.h" | 31 #include "chrome/browser/extensions/extension_toolbar_model.h" |
33 #include "chrome/browser/extensions/extensions_quota_service.h" | 32 #include "chrome/browser/extensions/extensions_quota_service.h" |
34 #include "chrome/browser/extensions/external_extension_provider_interface.h" | 33 #include "chrome/browser/extensions/external_extension_provider_interface.h" |
35 #include "chrome/browser/extensions/pending_extension_manager.h" | 34 #include "chrome/browser/extensions/pending_extension_manager.h" |
36 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" | 35 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" |
37 #include "chrome/browser/prefs/pref_change_registrar.h" | 36 #include "chrome/browser/prefs/pref_change_registrar.h" |
38 #include "chrome/browser/sync/api/sync_change.h" | |
39 #include "chrome/browser/sync/api/syncable_service.h" | |
40 #include "chrome/common/extensions/extension.h" | |
41 #include "chrome/common/extensions/extension_constants.h" | 37 #include "chrome/common/extensions/extension_constants.h" |
42 #include "content/browser/browser_thread.h" | 38 #include "content/browser/browser_thread.h" |
43 #include "content/common/notification_observer.h" | 39 #include "content/common/notification_observer.h" |
44 #include "content/common/notification_registrar.h" | 40 #include "content/common/notification_registrar.h" |
45 #include "content/common/property_bag.h" | 41 #include "content/common/property_bag.h" |
46 | 42 |
47 class CrxInstaller; | 43 class CrxInstaller; |
48 class ExtensionBookmarkEventRouter; | 44 class ExtensionBookmarkEventRouter; |
49 class ExtensionBrowserEventRouter; | 45 class ExtensionBrowserEventRouter; |
50 class ExtensionContentSettingsStore; | 46 class ExtensionContentSettingsStore; |
51 class ExtensionCookiesEventRouter; | 47 class ExtensionCookiesEventRouter; |
52 class ExtensionFileBrowserEventRouter; | 48 class ExtensionFileBrowserEventRouter; |
53 class ExtensionHistoryEventRouter; | 49 class ExtensionHistoryEventRouter; |
54 class ExtensionInstallUI; | 50 class ExtensionInstallUI; |
55 class ExtensionManagementEventRouter; | 51 class ExtensionManagementEventRouter; |
56 class ExtensionPreferenceEventRouter; | 52 class ExtensionPreferenceEventRouter; |
57 class ExtensionServiceBackend; | 53 class ExtensionServiceBackend; |
58 class ExtensionSettings; | 54 class ExtensionSettings; |
59 class ExtensionSyncData; | 55 struct ExtensionSyncData; |
60 class ExtensionToolbarModel; | 56 class ExtensionToolbarModel; |
61 class ExtensionUpdater; | 57 class ExtensionUpdater; |
62 class ExtensionWebNavigationEventRouter; | 58 class ExtensionWebNavigationEventRouter; |
63 class GURL; | 59 class GURL; |
64 class PendingExtensionManager; | 60 class PendingExtensionManager; |
65 class Profile; | 61 class Profile; |
66 class SyncData; | |
67 class Version; | 62 class Version; |
68 | 63 |
69 // This is an interface class to encapsulate the dependencies that | 64 // This is an interface class to encapsulate the dependencies that |
70 // various classes have on ExtensionService. This allows easy mocking. | 65 // various classes have on ExtensionService. This allows easy mocking. |
71 class ExtensionServiceInterface : public SyncableService { | 66 class ExtensionServiceInterface { |
72 public: | 67 public: |
73 // A function that returns true if the given extension should be | 68 // A function that returns true if the given extension should be |
74 // included and false if it should be filtered out. Identical to | 69 // included and false if it should be filtered out. Identical to |
75 // PendingExtensionInfo::ShouldAllowInstallPredicate. | 70 // PendingExtensionInfo::ShouldAllowInstallPredicate. |
76 typedef bool (*ExtensionFilter)(const Extension&); | 71 typedef bool (*ExtensionFilter)(const Extension&); |
77 | 72 |
78 virtual ~ExtensionServiceInterface() {} | 73 virtual ~ExtensionServiceInterface() {} |
79 virtual const ExtensionList* extensions() const = 0; | 74 virtual const ExtensionList* extensions() const = 0; |
80 virtual PendingExtensionManager* pending_extension_manager() = 0; | 75 virtual PendingExtensionManager* pending_extension_manager() = 0; |
81 | 76 |
(...skipping 15 matching lines...) Expand all Loading... |
97 | 92 |
98 virtual void UpdateExtensionBlacklist( | 93 virtual void UpdateExtensionBlacklist( |
99 const std::vector<std::string>& blacklist) = 0; | 94 const std::vector<std::string>& blacklist) = 0; |
100 virtual void CheckAdminBlacklist() = 0; | 95 virtual void CheckAdminBlacklist() = 0; |
101 | 96 |
102 // Safe to call multiple times in a row. | 97 // Safe to call multiple times in a row. |
103 // | 98 // |
104 // TODO(akalin): Remove this method (and others) once we refactor | 99 // TODO(akalin): Remove this method (and others) once we refactor |
105 // themes sync to not use it directly. | 100 // themes sync to not use it directly. |
106 virtual void CheckForUpdatesSoon() = 0; | 101 virtual void CheckForUpdatesSoon() = 0; |
| 102 |
| 103 // Methods used by sync. |
| 104 // |
| 105 // TODO(akalin): We'll eventually need separate methods for app |
| 106 // sync. See http://crbug.com/58077 and http://crbug.com/61447. |
| 107 |
| 108 // Get the sync data for |extension|. If |extension| passes |
| 109 // |filter|, fill in |extension_sync_data| and return true. |
| 110 // Otherwise, return false. |
| 111 // |
| 112 // Ideally, we'd just have to pass in the extension ID, but the |
| 113 // service may not know about the extension anymore (if it's |
| 114 // unloaded). |
| 115 virtual bool GetSyncData(const Extension& extension, |
| 116 ExtensionFilter filter, |
| 117 ExtensionSyncData* extension_sync_data) const = 0; |
| 118 |
| 119 // Return a list of ExtensionSyncData objects for all extensions |
| 120 // matching |filter|. |
| 121 virtual std::vector<ExtensionSyncData> GetSyncDataList( |
| 122 ExtensionFilter filter) const = 0; |
| 123 |
| 124 // Take any actions required to make the local state of the |
| 125 // extension match the state in |extension_sync_data| (including |
| 126 // installing/uninstalling the extension). |
| 127 virtual void ProcessSyncData( |
| 128 const ExtensionSyncData& extension_sync_data, |
| 129 ExtensionFilter filter) = 0; |
107 }; | 130 }; |
108 | 131 |
109 // Manages installed and running Chromium extensions. | 132 // Manages installed and running Chromium extensions. |
110 class ExtensionService | 133 class ExtensionService |
111 : public ExtensionServiceInterface, | 134 : public ExtensionServiceInterface, |
112 public ExternalExtensionProviderInterface::VisitorInterface, | 135 public ExternalExtensionProviderInterface::VisitorInterface, |
113 public NotificationObserver { | 136 public NotificationObserver { |
114 public: | 137 public: |
115 // Information about a registered component extension. | 138 // Information about a registered component extension. |
116 struct ComponentExtensionInfo { | 139 struct ComponentExtensionInfo { |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 virtual void UpdateExtensionBlacklist( | 422 virtual void UpdateExtensionBlacklist( |
400 const std::vector<std::string>& blacklist) OVERRIDE; | 423 const std::vector<std::string>& blacklist) OVERRIDE; |
401 | 424 |
402 // Go through each extension and unload those that the network admin has | 425 // Go through each extension and unload those that the network admin has |
403 // put on the blacklist (not to be confused with the Google managed blacklist | 426 // put on the blacklist (not to be confused with the Google managed blacklist |
404 // set of extensions. | 427 // set of extensions. |
405 virtual void CheckAdminBlacklist() OVERRIDE; | 428 virtual void CheckAdminBlacklist() OVERRIDE; |
406 | 429 |
407 virtual void CheckForUpdatesSoon() OVERRIDE; | 430 virtual void CheckForUpdatesSoon() OVERRIDE; |
408 | 431 |
409 // SyncableService implementation. | 432 // Sync methods implementation. |
410 virtual SyncError MergeDataAndStartSyncing( | 433 virtual bool GetSyncData( |
411 syncable::ModelType type, | 434 const Extension& extension, |
412 const SyncDataList& initial_sync_data, | 435 ExtensionFilter filter, |
413 SyncChangeProcessor* sync_processor) OVERRIDE; | 436 ExtensionSyncData* extension_sync_data) const OVERRIDE; |
414 virtual void StopSyncing(syncable::ModelType type) OVERRIDE; | 437 virtual std::vector<ExtensionSyncData> GetSyncDataList( |
415 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; | 438 ExtensionFilter filter) const OVERRIDE; |
416 virtual SyncError ProcessSyncChanges( | 439 virtual void ProcessSyncData( |
417 const tracked_objects::Location& from_here, | 440 const ExtensionSyncData& extension_sync_data, |
418 const SyncChangeList& change_list) OVERRIDE; | 441 ExtensionFilter filter) OVERRIDE; |
419 | 442 |
420 void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; } | 443 void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; } |
421 bool extensions_enabled() { return extensions_enabled_; } | 444 bool extensions_enabled() { return extensions_enabled_; } |
422 | 445 |
423 void set_show_extensions_prompts(bool enabled) { | 446 void set_show_extensions_prompts(bool enabled) { |
424 show_extensions_prompts_ = enabled; | 447 show_extensions_prompts_ = enabled; |
425 } | 448 } |
426 | 449 |
427 bool show_extensions_prompts() { | 450 bool show_extensions_prompts() { |
428 return show_extensions_prompts_; | 451 return show_extensions_prompts_; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 // |client| can be NULL for a silent install. | 547 // |client| can be NULL for a silent install. |
525 scoped_refptr<CrxInstaller> MakeCrxInstaller(ExtensionInstallUI* client); | 548 scoped_refptr<CrxInstaller> MakeCrxInstaller(ExtensionInstallUI* client); |
526 | 549 |
527 #if defined(UNIT_TEST) | 550 #if defined(UNIT_TEST) |
528 void TrackTerminatedExtensionForTest(const Extension* extension) { | 551 void TrackTerminatedExtensionForTest(const Extension* extension) { |
529 TrackTerminatedExtension(extension); | 552 TrackTerminatedExtension(extension); |
530 } | 553 } |
531 #endif | 554 #endif |
532 | 555 |
533 private: | 556 private: |
534 // Bundle of type (app or extension)-specific sync stuff. | |
535 struct SyncBundle { | |
536 SyncBundle(); | |
537 ~SyncBundle(); | |
538 | |
539 bool HasExtensionId(const std::string& id) const; | |
540 bool HasPendingExtensionId(const std::string& id) const; | |
541 | |
542 ExtensionFilter filter; | |
543 std::set<std::string> synced_extensions; | |
544 std::map<std::string, ExtensionSyncData> pending_sync_data; | |
545 SyncChangeProcessor* sync_processor; | |
546 }; | |
547 | |
548 // Contains Extension data that can change during the life of the process, | 557 // Contains Extension data that can change during the life of the process, |
549 // but does not persist across restarts. | 558 // but does not persist across restarts. |
550 struct ExtensionRuntimeData { | 559 struct ExtensionRuntimeData { |
551 // True if the background page is ready. | 560 // True if the background page is ready. |
552 bool background_page_ready; | 561 bool background_page_ready; |
553 | 562 |
554 // True while the extension is being upgraded. | 563 // True while the extension is being upgraded. |
555 bool being_upgraded; | 564 bool being_upgraded; |
556 | 565 |
557 // Generic bag of runtime data that users can associate with extensions. | 566 // Generic bag of runtime data that users can associate with extensions. |
558 PropertyBag property_bag; | 567 PropertyBag property_bag; |
559 | 568 |
560 ExtensionRuntimeData(); | 569 ExtensionRuntimeData(); |
561 ~ExtensionRuntimeData(); | 570 ~ExtensionRuntimeData(); |
562 }; | 571 }; |
563 typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap; | 572 typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap; |
564 | 573 |
565 struct NaClModuleInfo { | 574 struct NaClModuleInfo { |
566 NaClModuleInfo(); | 575 NaClModuleInfo(); |
567 ~NaClModuleInfo(); | 576 ~NaClModuleInfo(); |
568 | 577 |
569 GURL url; | 578 GURL url; |
570 std::string mime_type; | 579 std::string mime_type; |
571 }; | 580 }; |
572 typedef std::list<NaClModuleInfo> NaClModuleInfoList; | 581 typedef std::list<NaClModuleInfo> NaClModuleInfoList; |
573 | 582 |
574 // Notifies Sync (if needed) of a newly-installed extension or a change to | 583 // Gets the sync data for the given extension. |
575 // an existing extension. | 584 ExtensionSyncData GetSyncDataHelper(const Extension& extension) const; |
576 void SyncExtensionChangeIfNeeded(const Extension& extension); | |
577 | |
578 // Get the appropriate SyncBundle, given some representation of Sync data. | |
579 SyncBundle* GetSyncBundleForExtension(const Extension& extension); | |
580 SyncBundle* GetSyncBundleForExtensionSyncData( | |
581 const ExtensionSyncData& extension_sync_data); | |
582 SyncBundle* GetSyncBundleForModelType(syncable::ModelType type); | |
583 const SyncBundle* GetSyncBundleForModelTypeConst(syncable::ModelType type) | |
584 const; | |
585 | |
586 // Gets the ExtensionSyncData for all extensions. | |
587 std::vector<ExtensionSyncData> GetSyncDataList( | |
588 const SyncBundle& bundle) const; | |
589 | |
590 // Gets the sync data for the given extension, assuming that the extension is | |
591 // syncable. | |
592 ExtensionSyncData GetSyncData(const Extension& extension) const; | |
593 | 585 |
594 // Appends sync data objects for every extension in |extensions| | 586 // Appends sync data objects for every extension in |extensions| |
595 // that passes |filter|. | 587 // that passes |filter|. |
596 void GetSyncDataListHelper( | 588 void GetSyncDataListHelper( |
597 const ExtensionList& extensions, | 589 const ExtensionList& extensions, |
598 const SyncBundle& bundle, | 590 ExtensionFilter filter, |
599 std::vector<ExtensionSyncData>* sync_data_list) const; | 591 std::vector<ExtensionSyncData>* sync_data_list) const; |
600 | 592 |
601 // Applies the change specified in an ExtensionSyncData to the current system. | |
602 void ProcessExtensionSyncData( | |
603 const ExtensionSyncData& extension_sync_data, | |
604 SyncBundle& bundle); | |
605 | |
606 // Clear all persistent data that may have been stored by the extension. | 593 // Clear all persistent data that may have been stored by the extension. |
607 void ClearExtensionData(const GURL& extension_url); | 594 void ClearExtensionData(const GURL& extension_url); |
608 | 595 |
609 // Look up an extension by ID, optionally including either or both of enabled | 596 // Look up an extension by ID, optionally including either or both of enabled |
610 // and disabled extensions. | 597 // and disabled extensions. |
611 const Extension* GetExtensionByIdInternal(const std::string& id, | 598 const Extension* GetExtensionByIdInternal(const std::string& id, |
612 bool include_enabled, | 599 bool include_enabled, |
613 bool include_disabled, | 600 bool include_disabled, |
614 bool include_terminated) const; | 601 bool include_terminated) const; |
615 | 602 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 // windows registry and external_extensions.json. | 764 // windows registry and external_extensions.json. |
778 ProviderCollection external_extension_providers_; | 765 ProviderCollection external_extension_providers_; |
779 | 766 |
780 // Set to true by OnExternalExtensionUpdateUrlFound() when an external | 767 // Set to true by OnExternalExtensionUpdateUrlFound() when an external |
781 // extension URL is found. Used in CheckForExternalUpdates() to see | 768 // extension URL is found. Used in CheckForExternalUpdates() to see |
782 // if an update check is needed to install pending extensions. | 769 // if an update check is needed to install pending extensions. |
783 bool external_extension_url_added_; | 770 bool external_extension_url_added_; |
784 | 771 |
785 NaClModuleInfoList nacl_module_list_; | 772 NaClModuleInfoList nacl_module_list_; |
786 | 773 |
787 SyncBundle app_sync_bundle_; | |
788 SyncBundle extension_sync_bundle_; | |
789 | |
790 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 774 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
791 InstallAppsWithUnlimtedStorage); | 775 InstallAppsWithUnlimtedStorage); |
792 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 776 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
793 InstallAppsAndCheckStorageProtection); | 777 InstallAppsAndCheckStorageProtection); |
794 DISALLOW_COPY_AND_ASSIGN(ExtensionService); | 778 DISALLOW_COPY_AND_ASSIGN(ExtensionService); |
795 }; | 779 }; |
796 | 780 |
797 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ | 781 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
OLD | NEW |