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; |
| 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 |
557 // Contains Extension data that can change during the life of the process, | 548 // Contains Extension data that can change during the life of the process, |
558 // but does not persist across restarts. | 549 // but does not persist across restarts. |
559 struct ExtensionRuntimeData { | 550 struct ExtensionRuntimeData { |
560 // True if the background page is ready. | 551 // True if the background page is ready. |
561 bool background_page_ready; | 552 bool background_page_ready; |
562 | 553 |
563 // True while the extension is being upgraded. | 554 // True while the extension is being upgraded. |
564 bool being_upgraded; | 555 bool being_upgraded; |
565 | 556 |
566 // Generic bag of runtime data that users can associate with extensions. | 557 // Generic bag of runtime data that users can associate with extensions. |
567 PropertyBag property_bag; | 558 PropertyBag property_bag; |
568 | 559 |
569 ExtensionRuntimeData(); | 560 ExtensionRuntimeData(); |
570 ~ExtensionRuntimeData(); | 561 ~ExtensionRuntimeData(); |
571 }; | 562 }; |
572 typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap; | 563 typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap; |
573 | 564 |
574 struct NaClModuleInfo { | 565 struct NaClModuleInfo { |
575 NaClModuleInfo(); | 566 NaClModuleInfo(); |
576 ~NaClModuleInfo(); | 567 ~NaClModuleInfo(); |
577 | 568 |
578 GURL url; | 569 GURL url; |
579 std::string mime_type; | 570 std::string mime_type; |
580 }; | 571 }; |
581 typedef std::list<NaClModuleInfo> NaClModuleInfoList; | 572 typedef std::list<NaClModuleInfo> NaClModuleInfoList; |
582 | 573 |
583 // Gets the sync data for the given extension. | 574 // Notifies Sync (if needed) of a newly-installed extension or a change to |
584 ExtensionSyncData GetSyncDataHelper(const Extension& extension) const; | 575 // an existing extension. |
| 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; |
585 | 593 |
586 // Appends sync data objects for every extension in |extensions| | 594 // Appends sync data objects for every extension in |extensions| |
587 // that passes |filter|. | 595 // that passes |filter|. |
588 void GetSyncDataListHelper( | 596 void GetSyncDataListHelper( |
589 const ExtensionList& extensions, | 597 const ExtensionList& extensions, |
590 ExtensionFilter filter, | 598 const SyncBundle& bundle, |
591 std::vector<ExtensionSyncData>* sync_data_list) const; | 599 std::vector<ExtensionSyncData>* sync_data_list) const; |
592 | 600 |
| 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 |
593 // Clear all persistent data that may have been stored by the extension. | 606 // Clear all persistent data that may have been stored by the extension. |
594 void ClearExtensionData(const GURL& extension_url); | 607 void ClearExtensionData(const GURL& extension_url); |
595 | 608 |
596 // Look up an extension by ID, optionally including either or both of enabled | 609 // Look up an extension by ID, optionally including either or both of enabled |
597 // and disabled extensions. | 610 // and disabled extensions. |
598 const Extension* GetExtensionByIdInternal(const std::string& id, | 611 const Extension* GetExtensionByIdInternal(const std::string& id, |
599 bool include_enabled, | 612 bool include_enabled, |
600 bool include_disabled, | 613 bool include_disabled, |
601 bool include_terminated) const; | 614 bool include_terminated) const; |
602 | 615 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 // windows registry and external_extensions.json. | 777 // windows registry and external_extensions.json. |
765 ProviderCollection external_extension_providers_; | 778 ProviderCollection external_extension_providers_; |
766 | 779 |
767 // Set to true by OnExternalExtensionUpdateUrlFound() when an external | 780 // Set to true by OnExternalExtensionUpdateUrlFound() when an external |
768 // extension URL is found. Used in CheckForExternalUpdates() to see | 781 // extension URL is found. Used in CheckForExternalUpdates() to see |
769 // if an update check is needed to install pending extensions. | 782 // if an update check is needed to install pending extensions. |
770 bool external_extension_url_added_; | 783 bool external_extension_url_added_; |
771 | 784 |
772 NaClModuleInfoList nacl_module_list_; | 785 NaClModuleInfoList nacl_module_list_; |
773 | 786 |
| 787 SyncBundle app_sync_bundle_; |
| 788 SyncBundle extension_sync_bundle_; |
| 789 |
774 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 790 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
775 InstallAppsWithUnlimtedStorage); | 791 InstallAppsWithUnlimtedStorage); |
776 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 792 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
777 InstallAppsAndCheckStorageProtection); | 793 InstallAppsAndCheckStorageProtection); |
778 DISALLOW_COPY_AND_ASSIGN(ExtensionService); | 794 DISALLOW_COPY_AND_ASSIGN(ExtensionService); |
779 }; | 795 }; |
780 | 796 |
781 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ | 797 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
OLD | NEW |