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 ExtensionSyncService(Profile
* profile
,
38 extensions::ExtensionPrefs
* extension_prefs
,
39 ExtensionService
* extension_service
);
41 ~ExtensionSyncService() override
;
43 // Convenience function to get the ExtensionSyncService for a BrowserContext.
44 static ExtensionSyncService
* Get(content::BrowserContext
* context
);
46 // Notifies Sync that the given |extension| has been uninstalled.
47 void SyncUninstallExtension(const extensions::Extension
& extension
);
49 // Notifies Sync (if needed) of a newly-installed extension or a change to
50 // an existing extension.
51 void SyncExtensionChangeIfNeeded(const extensions::Extension
& extension
);
53 // syncer::SyncableService implementation.
54 syncer::SyncMergeResult
MergeDataAndStartSyncing(
55 syncer::ModelType type
,
56 const syncer::SyncDataList
& initial_sync_data
,
57 scoped_ptr
<syncer::SyncChangeProcessor
> sync_processor
,
58 scoped_ptr
<syncer::SyncErrorFactory
> sync_error_factory
) override
;
59 void StopSyncing(syncer::ModelType type
) override
;
60 syncer::SyncDataList
GetAllSyncData(syncer::ModelType type
) const override
;
61 syncer::SyncError
ProcessSyncChanges(
62 const tracked_objects::Location
& from_here
,
63 const syncer::SyncChangeList
& change_list
) override
;
65 // |flare| provides a StartSyncFlare to the SyncableService. See
66 // sync_start_util for more. Public for testing.
67 void SetSyncStartFlare(const syncer::SyncableService::StartSyncFlare
& flare
);
70 FRIEND_TEST_ALL_PREFIXES(TwoClientAppsSyncTest
, UnexpectedLaunchType
);
71 FRIEND_TEST_ALL_PREFIXES(ExtensionDisabledGlobalErrorTest
,
72 HigherPermissionsFromSync
);
73 FRIEND_TEST_ALL_PREFIXES(ExtensionDisabledGlobalErrorTest
, RemoteInstall
);
74 friend class EphemeralAppBrowserTest
;
76 // Gets the SyncBundle for the given |type|.
77 extensions::SyncBundle
* GetSyncBundle(syncer::ModelType type
);
78 const extensions::SyncBundle
* GetSyncBundle(syncer::ModelType type
) const;
80 // Creates the ExtensionSyncData for the given app/extension.
81 extensions::ExtensionSyncData
CreateSyncData(
82 const extensions::Extension
& extension
) const;
84 // Applies the given change coming in from the server to the local state.
85 // Returns false if the changes were not completely applied and were added
86 // to the pending list.
87 bool ApplySyncData(const extensions::ExtensionSyncData
& extension_sync_data
);
89 // Collects the ExtensionSyncData for all installed apps or extensions.
90 // If |include_everything| is true, includes all installed extensions,
91 // otherwise only those that have the NeedsSync pref set, i.e. which have
92 // local changes that need to be pushed.
93 std::vector
<extensions::ExtensionSyncData
> GetLocalSyncDataList(
94 syncer::ModelType type
, bool include_everything
) const;
96 // Helper for GetLocalSyncDataList.
97 void FillSyncDataList(
98 const extensions::ExtensionSet
& extensions
,
99 syncer::ModelType type
,
100 bool include_everything
,
101 std::vector
<extensions::ExtensionSyncData
>* sync_data_list
) const;
103 // Handles applying the extension specific values in |extension_sync_data| to
105 // Returns false if the changes were not completely applied.
106 bool ApplyExtensionSyncDataHelper(
107 const extensions::ExtensionSyncData
& extension_sync_data
,
108 syncer::ModelType type
);
110 // Processes the bookmark app specific parts of an AppSyncData.
111 void ApplyBookmarkAppSyncData(
112 const extensions::ExtensionSyncData
& extension_sync_data
);
114 // The normal profile associated with this ExtensionService.
117 // Preferences for the owning profile.
118 extensions::ExtensionPrefs
* extension_prefs_
;
120 ExtensionService
* extension_service_
;
122 extensions::SyncBundle app_sync_bundle_
;
123 extensions::SyncBundle extension_sync_bundle_
;
125 // Run()ning tells sync to try and start soon, because syncable changes
126 // have started happening. It will cause sync to call us back
127 // asynchronously via MergeDataAndStartSyncing as soon as possible.
128 syncer::SyncableService::StartSyncFlare flare_
;
130 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncService
);
133 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_