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