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

Side by Side Diff: chrome/browser/extensions/extension_service.h

Issue 7564037: Apps/Extensions Sync refactoring -- delete most of the old glue, implement new sync API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
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
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"
37 #include "chrome/common/extensions/extension.h" 40 #include "chrome/common/extensions/extension.h"
38 #include "content/browser/browser_thread.h" 41 #include "content/browser/browser_thread.h"
39 #include "content/common/notification_observer.h" 42 #include "content/common/notification_observer.h"
40 #include "content/common/notification_registrar.h" 43 #include "content/common/notification_registrar.h"
41 #include "content/common/property_bag.h" 44 #include "content/common/property_bag.h"
42 45
43 class CrxInstaller; 46 class CrxInstaller;
44 class ExtensionBookmarkEventRouter; 47 class ExtensionBookmarkEventRouter;
45 class ExtensionBrowserEventRouter; 48 class ExtensionBrowserEventRouter;
46 class ExtensionContentSettingsStore; 49 class ExtensionContentSettingsStore;
47 class ExtensionCookiesEventRouter; 50 class ExtensionCookiesEventRouter;
48 class ExtensionFileBrowserEventRouter; 51 class ExtensionFileBrowserEventRouter;
49 class ExtensionHistoryEventRouter; 52 class ExtensionHistoryEventRouter;
50 class ExtensionInstallUI; 53 class ExtensionInstallUI;
51 class ExtensionManagementEventRouter; 54 class ExtensionManagementEventRouter;
52 class ExtensionPreferenceEventRouter; 55 class ExtensionPreferenceEventRouter;
53 class ExtensionServiceBackend; 56 class ExtensionServiceBackend;
54 class ExtensionSettings; 57 class ExtensionSettings;
55 struct ExtensionSyncData; 58 class ExtensionSyncData;
56 class ExtensionToolbarModel; 59 class ExtensionToolbarModel;
57 class ExtensionUpdater; 60 class ExtensionUpdater;
58 class ExtensionWebNavigationEventRouter; 61 class ExtensionWebNavigationEventRouter;
59 class GURL; 62 class GURL;
60 class PendingExtensionManager; 63 class PendingExtensionManager;
61 class Profile; 64 class Profile;
65 class SyncData;
62 class Version; 66 class Version;
63 67
64 // This is an interface class to encapsulate the dependencies that 68 // This is an interface class to encapsulate the dependencies that
65 // various classes have on ExtensionService. This allows easy mocking. 69 // various classes have on ExtensionService. This allows easy mocking.
66 class ExtensionServiceInterface { 70 class ExtensionServiceInterface : public SyncableService {
67 public: 71 public:
68 // A function that returns true if the given extension should be 72 // A function that returns true if the given extension should be
69 // included and false if it should be filtered out. Identical to 73 // included and false if it should be filtered out. Identical to
70 // PendingExtensionInfo::ShouldAllowInstallPredicate. 74 // PendingExtensionInfo::ShouldAllowInstallPredicate.
71 typedef bool (*ExtensionFilter)(const Extension&); 75 typedef bool (*ExtensionFilter)(const Extension&);
72 76
73 virtual ~ExtensionServiceInterface() {} 77 virtual ~ExtensionServiceInterface() {}
74 virtual const ExtensionList* extensions() const = 0; 78 virtual const ExtensionList* extensions() const = 0;
75 virtual PendingExtensionManager* pending_extension_manager() = 0; 79 virtual PendingExtensionManager* pending_extension_manager() = 0;
76 80
(...skipping 15 matching lines...) Expand all
92 96
93 virtual void UpdateExtensionBlacklist( 97 virtual void UpdateExtensionBlacklist(
94 const std::vector<std::string>& blacklist) = 0; 98 const std::vector<std::string>& blacklist) = 0;
95 virtual void CheckAdminBlacklist() = 0; 99 virtual void CheckAdminBlacklist() = 0;
96 100
97 // Safe to call multiple times in a row. 101 // Safe to call multiple times in a row.
98 // 102 //
99 // TODO(akalin): Remove this method (and others) once we refactor 103 // TODO(akalin): Remove this method (and others) once we refactor
100 // themes sync to not use it directly. 104 // themes sync to not use it directly.
101 virtual void CheckForUpdatesSoon() = 0; 105 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 }; 106 };
131 107
132 // Manages installed and running Chromium extensions. 108 // Manages installed and running Chromium extensions.
133 class ExtensionService 109 class ExtensionService
134 : public ExtensionServiceInterface, 110 : public ExtensionServiceInterface,
135 public ExternalExtensionProviderInterface::VisitorInterface, 111 public ExternalExtensionProviderInterface::VisitorInterface,
136 public NotificationObserver { 112 public NotificationObserver {
137 public: 113 public:
138 // Information about a registered component extension. 114 // Information about a registered component extension.
139 struct ComponentExtensionInfo { 115 struct ComponentExtensionInfo {
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 virtual void UpdateExtensionBlacklist( 405 virtual void UpdateExtensionBlacklist(
430 const std::vector<std::string>& blacklist) OVERRIDE; 406 const std::vector<std::string>& blacklist) OVERRIDE;
431 407
432 // Go through each extension and unload those that the network admin has 408 // Go through each extension and unload those that the network admin has
433 // put on the blacklist (not to be confused with the Google managed blacklist 409 // put on the blacklist (not to be confused with the Google managed blacklist
434 // set of extensions. 410 // set of extensions.
435 virtual void CheckAdminBlacklist() OVERRIDE; 411 virtual void CheckAdminBlacklist() OVERRIDE;
436 412
437 virtual void CheckForUpdatesSoon() OVERRIDE; 413 virtual void CheckForUpdatesSoon() OVERRIDE;
438 414
439 // Sync methods implementation. 415 // Sync methods implementation.
akalin 2011/08/12 03:35:02 Sync methods -> SyncableService
440 virtual bool GetSyncData( 416 virtual SyncError MergeDataAndStartSyncing(
441 const Extension& extension, 417 syncable::ModelType type,
442 ExtensionFilter filter, 418 const SyncDataList& initial_sync_data,
443 ExtensionSyncData* extension_sync_data) const OVERRIDE; 419 SyncChangeProcessor* sync_processor) OVERRIDE;
444 virtual std::vector<ExtensionSyncData> GetSyncDataList( 420 virtual void StopSyncing(syncable::ModelType type) OVERRIDE;
445 ExtensionFilter filter) const OVERRIDE; 421 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE;
446 virtual void ProcessSyncData( 422 virtual SyncError ProcessSyncChanges(
447 const ExtensionSyncData& extension_sync_data, 423 const tracked_objects::Location& from_here,
448 ExtensionFilter filter) OVERRIDE; 424 const SyncChangeList& change_list) OVERRIDE;
449 425
450 void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; } 426 void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
451 bool extensions_enabled() { return extensions_enabled_; } 427 bool extensions_enabled() { return extensions_enabled_; }
452 428
453 void set_show_extensions_prompts(bool enabled) { 429 void set_show_extensions_prompts(bool enabled) {
454 show_extensions_prompts_ = enabled; 430 show_extensions_prompts_ = enabled;
455 } 431 }
456 432
457 bool show_extensions_prompts() { 433 bool show_extensions_prompts() {
458 return show_extensions_prompts_; 434 return show_extensions_prompts_;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 // |client| can be NULL for a silent install. 530 // |client| can be NULL for a silent install.
555 scoped_refptr<CrxInstaller> MakeCrxInstaller(ExtensionInstallUI* client); 531 scoped_refptr<CrxInstaller> MakeCrxInstaller(ExtensionInstallUI* client);
556 532
557 #if defined(UNIT_TEST) 533 #if defined(UNIT_TEST)
558 void TrackTerminatedExtensionForTest(const Extension* extension) { 534 void TrackTerminatedExtensionForTest(const Extension* extension) {
559 TrackTerminatedExtension(extension); 535 TrackTerminatedExtension(extension);
560 } 536 }
561 #endif 537 #endif
562 538
563 private: 539 private:
540 // Bundle of type (app or extension)-specific sync stuff.
541 struct SyncBundle {
542 static bool IsSyncableNone(const Extension& extension) { return false; }
543 SyncBundle() : filter(IsSyncableNone), sync_processor(NULL) { }
akalin 2011/08/12 03:35:02 clang will probably complain about complex inline
544
545 bool HasExtensionId(const std::string& id) const {
546 return synced_extensions.find(id) != synced_extensions.end();
547 }
548
549 bool HasPendingExtensionId(const std::string& id) const {
550 return pending_sync_data.find(id) != pending_sync_data.end();
551 }
552
553 ExtensionFilter filter;
554 std::set<std::string> synced_extensions;
555 std::map<std::string, ExtensionSyncData> pending_sync_data;
556 SyncChangeProcessor* sync_processor;
557 };
558
564 // Contains Extension data that can change during the life of the process, 559 // Contains Extension data that can change during the life of the process,
565 // but does not persist across restarts. 560 // but does not persist across restarts.
566 struct ExtensionRuntimeData { 561 struct ExtensionRuntimeData {
567 // True if the background page is ready. 562 // True if the background page is ready.
568 bool background_page_ready; 563 bool background_page_ready;
569 564
570 // True while the extension is being upgraded. 565 // True while the extension is being upgraded.
571 bool being_upgraded; 566 bool being_upgraded;
572 567
573 // Generic bag of runtime data that users can associate with extensions. 568 // Generic bag of runtime data that users can associate with extensions.
574 PropertyBag property_bag; 569 PropertyBag property_bag;
575 570
576 ExtensionRuntimeData(); 571 ExtensionRuntimeData();
577 ~ExtensionRuntimeData(); 572 ~ExtensionRuntimeData();
578 }; 573 };
579 typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap; 574 typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap;
580 575
581 struct NaClModuleInfo { 576 struct NaClModuleInfo {
582 NaClModuleInfo(); 577 NaClModuleInfo();
583 ~NaClModuleInfo(); 578 ~NaClModuleInfo();
584 579
585 GURL url; 580 GURL url;
586 std::string mime_type; 581 std::string mime_type;
587 }; 582 };
588 typedef std::list<NaClModuleInfo> NaClModuleInfoList; 583 typedef std::list<NaClModuleInfo> NaClModuleInfoList;
589 584
590 // Gets the sync data for the given extension. 585 // Notifies Sync (if needed) of a newly-installed or updated extension.
asargent_no_longer_on_chrome 2011/08/12 20:50:39 In the .cc file I see you also call this when an e
591 ExtensionSyncData GetSyncDataHelper(const Extension& extension) const; 586 void SyncExtensionUpdateIfNeeded(const Extension& extension);
587
588 // Get the appropriate SyncBundle, given some representation of Sync data.
589 SyncBundle* GetSyncBundleForExtension(const Extension& extension);
590 SyncBundle* GetSyncBundleForExtensionSyncData(
591 const ExtensionSyncData& extension_sync_data);
592 SyncBundle* GetSyncBundleForModelType(syncable::ModelType type);
593 const SyncBundle* GetSyncBundleForModelType(syncable::ModelType type) const;
akalin 2011/08/12 03:35:02 maybe append Const to this fn name to avoid overlo
594
595 // Gets the ExtensionSyncData for all extensions.
596 std::vector<ExtensionSyncData> GetSyncDataList(
597 const SyncBundle& bundle) const;
598
599 // Gets the sync data for the given extension, assuming that the extension is
600 // syncable.
601 ExtensionSyncData GetSyncData(const Extension& extension) const;
592 602
593 // Appends sync data objects for every extension in |extensions| 603 // Appends sync data objects for every extension in |extensions|
594 // that passes |filter|. 604 // that passes |filter|.
595 void GetSyncDataListHelper( 605 void GetSyncDataListHelper(
596 const ExtensionList& extensions, 606 const ExtensionList& extensions,
597 ExtensionFilter filter, 607 const SyncBundle& bundle,
598 std::vector<ExtensionSyncData>* sync_data_list) const; 608 std::vector<ExtensionSyncData>* sync_data_list) const;
599 609
610 // Applies the change specified in an ExtensionSyncData to the current system.
611 void ProcessExtensionSyncData(
asargent_no_longer_on_chrome 2011/08/12 20:50:39 optional naming suggestion: consider just "Process
Ben Olmstead 2011/08/15 20:20:12 Unfortunately, SyncData is a different class used
612 const ExtensionSyncData& extension_sync_data,
613 SyncBundle& bundle);
614
600 // Clear all persistent data that may have been stored by the extension. 615 // Clear all persistent data that may have been stored by the extension.
601 void ClearExtensionData(const GURL& extension_url); 616 void ClearExtensionData(const GURL& extension_url);
602 617
603 // Look up an extension by ID, optionally including either or both of enabled 618 // Look up an extension by ID, optionally including either or both of enabled
604 // and disabled extensions. 619 // and disabled extensions.
605 const Extension* GetExtensionByIdInternal(const std::string& id, 620 const Extension* GetExtensionByIdInternal(const std::string& id,
606 bool include_enabled, 621 bool include_enabled,
607 bool include_disabled, 622 bool include_disabled,
608 bool include_terminated) const; 623 bool include_terminated) const;
609 624
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 // windows registry and external_extensions.json. 786 // windows registry and external_extensions.json.
772 ProviderCollection external_extension_providers_; 787 ProviderCollection external_extension_providers_;
773 788
774 // Set to true by OnExternalExtensionUpdateUrlFound() when an external 789 // Set to true by OnExternalExtensionUpdateUrlFound() when an external
775 // extension URL is found. Used in CheckForExternalUpdates() to see 790 // extension URL is found. Used in CheckForExternalUpdates() to see
776 // if an update check is needed to install pending extensions. 791 // if an update check is needed to install pending extensions.
777 bool external_extension_url_added_; 792 bool external_extension_url_added_;
778 793
779 NaClModuleInfoList nacl_module_list_; 794 NaClModuleInfoList nacl_module_list_;
780 795
796 SyncBundle app_sync_bundle_;
797 SyncBundle extension_sync_bundle_;
asargent_no_longer_on_chrome 2011/08/12 20:50:39 A question for you to ponder - would it be easier
Ben Olmstead 2011/08/15 20:20:12 That's actually where I started, but I added the S
asargent_no_longer_on_chrome 2011/08/15 23:34:29 Ok
798
781 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 799 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
782 InstallAppsWithUnlimtedStorage); 800 InstallAppsWithUnlimtedStorage);
783 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 801 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
784 InstallAppsAndCheckStorageProtection); 802 InstallAppsAndCheckStorageProtection);
785 DISALLOW_COPY_AND_ASSIGN(ExtensionService); 803 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
786 }; 804 };
787 805
788 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ 806 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_service.cc » ('j') | chrome/browser/extensions/extension_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698