Rename CoalescedPermissionMessage to PermissionMessage
[chromium-blink-merge.git] / chrome / browser / extensions / extension_sync_service.h
blobbd0e2e4f6fa784b7a780936877ec3621b44e573c
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_
8 #include <string>
9 #include <vector>
11 #include "base/scoped_observer.h"
12 #include "chrome/browser/extensions/sync_bundle.h"
13 #include "components/keyed_service/core/keyed_service.h"
14 #include "extensions/browser/extension_prefs_observer.h"
15 #include "extensions/browser/extension_registry_observer.h"
16 #include "sync/api/syncable_service.h"
18 class ExtensionService;
19 class Profile;
21 namespace extensions {
22 class Extension;
23 class ExtensionSet;
24 class ExtensionSyncData;
25 } // namespace extensions
27 // SyncableService implementation responsible for the APPS and EXTENSIONS data
28 // types, i.e. "proper" apps/extensions (not themes).
29 class ExtensionSyncService : public syncer::SyncableService,
30 public KeyedService,
31 public extensions::ExtensionRegistryObserver,
32 public extensions::ExtensionPrefsObserver {
33 public:
34 explicit ExtensionSyncService(Profile* profile);
35 ~ExtensionSyncService() override;
37 // Convenience function to get the ExtensionSyncService for a BrowserContext.
38 static ExtensionSyncService* Get(content::BrowserContext* context);
40 // Notifies Sync (if needed) of a newly-installed extension or a change to
41 // an existing extension. Call this when you change an extension setting that
42 // is synced as part of ExtensionSyncData (e.g. incognito_enabled or
43 // all_urls_enabled).
44 void SyncExtensionChangeIfNeeded(const extensions::Extension& extension);
46 // syncer::SyncableService implementation.
47 syncer::SyncMergeResult MergeDataAndStartSyncing(
48 syncer::ModelType type,
49 const syncer::SyncDataList& initial_sync_data,
50 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
51 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) override;
52 void StopSyncing(syncer::ModelType type) override;
53 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override;
54 syncer::SyncError ProcessSyncChanges(
55 const tracked_objects::Location& from_here,
56 const syncer::SyncChangeList& change_list) override;
58 private:
59 FRIEND_TEST_ALL_PREFIXES(TwoClientAppsSyncTest, UnexpectedLaunchType);
60 FRIEND_TEST_ALL_PREFIXES(ExtensionDisabledGlobalErrorTest,
61 HigherPermissionsFromSync);
62 FRIEND_TEST_ALL_PREFIXES(ExtensionDisabledGlobalErrorTest, RemoteInstall);
63 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
64 DeferredSyncStartupPreInstalledComponent);
65 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
66 DeferredSyncStartupPreInstalledNormal);
67 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
68 DeferredSyncStartupOnInstall);
69 friend class EphemeralAppBrowserTest;
71 void SetSyncStartFlareForTesting(
72 const syncer::SyncableService::StartSyncFlare& flare);
74 ExtensionService* extension_service() const;
76 // extensions::ExtensionRegistryObserver:
77 void OnExtensionInstalled(content::BrowserContext* browser_context,
78 const extensions::Extension* extension,
79 bool is_update) override;
80 void OnExtensionUninstalled(content::BrowserContext* browser_context,
81 const extensions::Extension* extension,
82 extensions::UninstallReason reason) override;
84 // extensions::ExtensionPrefsObserver:
85 void OnExtensionStateChanged(const std::string& extension_id,
86 bool state) override;
87 void OnExtensionDisableReasonsChanged(const std::string& extension_id,
88 int disabled_reasons) override;
90 // Gets the SyncBundle for the given |type|.
91 extensions::SyncBundle* GetSyncBundle(syncer::ModelType type);
92 const extensions::SyncBundle* GetSyncBundle(syncer::ModelType type) const;
94 // Creates the ExtensionSyncData for the given app/extension.
95 extensions::ExtensionSyncData CreateSyncData(
96 const extensions::Extension& extension) const;
98 // Applies the given change coming in from the server to the local state.
99 // Returns false if the changes were not completely applied and were added
100 // to the pending list.
101 bool ApplySyncData(const extensions::ExtensionSyncData& extension_sync_data);
103 // Collects the ExtensionSyncData for all installed apps or extensions.
104 // If |include_everything| is true, includes all installed extensions,
105 // otherwise only those that have the NeedsSync pref set, i.e. which have
106 // local changes that need to be pushed.
107 std::vector<extensions::ExtensionSyncData> GetLocalSyncDataList(
108 syncer::ModelType type, bool include_everything) const;
110 // Helper for GetLocalSyncDataList.
111 void FillSyncDataList(
112 const extensions::ExtensionSet& extensions,
113 syncer::ModelType type,
114 bool include_everything,
115 std::vector<extensions::ExtensionSyncData>* sync_data_list) const;
117 // Handles applying the extension specific values in |extension_sync_data| to
118 // the local state.
119 // Returns false if the changes were not completely applied.
120 bool ApplyExtensionSyncDataHelper(
121 const extensions::ExtensionSyncData& extension_sync_data,
122 syncer::ModelType type);
124 // Processes the bookmark app specific parts of an AppSyncData.
125 void ApplyBookmarkAppSyncData(
126 const extensions::ExtensionSyncData& extension_sync_data);
128 // The normal profile associated with this ExtensionSyncService.
129 Profile* profile_;
131 ScopedObserver<extensions::ExtensionRegistry,
132 extensions::ExtensionRegistryObserver> registry_observer_;
133 ScopedObserver<extensions::ExtensionPrefs,
134 extensions::ExtensionPrefsObserver> prefs_observer_;
136 extensions::SyncBundle app_sync_bundle_;
137 extensions::SyncBundle extension_sync_bundle_;
139 // Run()ning tells sync to try and start soon, because syncable changes
140 // have started happening. It will cause sync to call us back
141 // asynchronously via MergeDataAndStartSyncing as soon as possible.
142 syncer::SyncableService::StartSyncFlare flare_;
144 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncService);
147 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_