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_
11 #include "chrome/browser/extensions/sync_bundle.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "extensions/browser/extension_prefs.h"
14 #include "extensions/common/extension.h"
15 #include "sync/api/syncable_service.h"
17 class ExtensionService
;
20 namespace extensions
{
23 class ExtensionSyncData
;
24 } // namespace extensions
28 class SyncChangeProcessor
;
29 class SyncErrorFactory
;
32 // SyncableService implementation responsible for the APPS and EXTENSIONS data
33 // types, i.e. "proper" apps/extensions (not themes).
34 class ExtensionSyncService
: public syncer::SyncableService
,
37 explicit ExtensionSyncService(Profile
* profile
);
38 ~ExtensionSyncService() override
;
40 // Convenience function to get the ExtensionSyncService for a BrowserContext.
41 static ExtensionSyncService
* Get(content::BrowserContext
* context
);
43 // Notifies Sync that the given |extension| has been uninstalled.
44 void SyncUninstallExtension(const extensions::Extension
& extension
);
46 // Notifies Sync (if needed) of a newly-installed extension or a change to
47 // an existing extension.
48 void SyncExtensionChangeIfNeeded(const extensions::Extension
& extension
);
50 // syncer::SyncableService implementation.
51 syncer::SyncMergeResult
MergeDataAndStartSyncing(
52 syncer::ModelType type
,
53 const syncer::SyncDataList
& initial_sync_data
,
54 scoped_ptr
<syncer::SyncChangeProcessor
> sync_processor
,
55 scoped_ptr
<syncer::SyncErrorFactory
> sync_error_factory
) override
;
56 void StopSyncing(syncer::ModelType type
) override
;
57 syncer::SyncDataList
GetAllSyncData(syncer::ModelType type
) const override
;
58 syncer::SyncError
ProcessSyncChanges(
59 const tracked_objects::Location
& from_here
,
60 const syncer::SyncChangeList
& change_list
) override
;
63 FRIEND_TEST_ALL_PREFIXES(TwoClientAppsSyncTest
, UnexpectedLaunchType
);
64 FRIEND_TEST_ALL_PREFIXES(ExtensionDisabledGlobalErrorTest
,
65 HigherPermissionsFromSync
);
66 FRIEND_TEST_ALL_PREFIXES(ExtensionDisabledGlobalErrorTest
, RemoteInstall
);
67 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest
,
68 DeferredSyncStartupPreInstalledComponent
);
69 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest
,
70 DeferredSyncStartupPreInstalledNormal
);
71 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest
,
72 DeferredSyncStartupOnInstall
);
73 friend class EphemeralAppBrowserTest
;
75 void SetSyncStartFlareForTesting(
76 const syncer::SyncableService::StartSyncFlare
& flare
);
78 ExtensionService
* extension_service() const;
80 // Gets the SyncBundle for the given |type|.
81 extensions::SyncBundle
* GetSyncBundle(syncer::ModelType type
);
82 const extensions::SyncBundle
* GetSyncBundle(syncer::ModelType type
) const;
84 // Creates the ExtensionSyncData for the given app/extension.
85 extensions::ExtensionSyncData
CreateSyncData(
86 const extensions::Extension
& extension
) const;
88 // Applies the given change coming in from the server to the local state.
89 // Returns false if the changes were not completely applied and were added
90 // to the pending list.
91 bool ApplySyncData(const extensions::ExtensionSyncData
& extension_sync_data
);
93 // Collects the ExtensionSyncData for all installed apps or extensions.
94 // If |include_everything| is true, includes all installed extensions,
95 // otherwise only those that have the NeedsSync pref set, i.e. which have
96 // local changes that need to be pushed.
97 std::vector
<extensions::ExtensionSyncData
> GetLocalSyncDataList(
98 syncer::ModelType type
, bool include_everything
) const;
100 // Helper for GetLocalSyncDataList.
101 void FillSyncDataList(
102 const extensions::ExtensionSet
& extensions
,
103 syncer::ModelType type
,
104 bool include_everything
,
105 std::vector
<extensions::ExtensionSyncData
>* sync_data_list
) const;
107 // Handles applying the extension specific values in |extension_sync_data| to
109 // Returns false if the changes were not completely applied.
110 bool ApplyExtensionSyncDataHelper(
111 const extensions::ExtensionSyncData
& extension_sync_data
,
112 syncer::ModelType type
);
114 // Processes the bookmark app specific parts of an AppSyncData.
115 void ApplyBookmarkAppSyncData(
116 const extensions::ExtensionSyncData
& extension_sync_data
);
118 // The normal profile associated with this ExtensionSyncService.
121 extensions::SyncBundle app_sync_bundle_
;
122 extensions::SyncBundle extension_sync_bundle_
;
124 // Run()ning tells sync to try and start soon, because syncable changes
125 // have started happening. It will cause sync to call us back
126 // asynchronously via MergeDataAndStartSyncing as soon as possible.
127 syncer::SyncableService::StartSyncFlare flare_
;
129 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncService
);
132 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_