Update V8 to version 4.6.22.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_sync_service.h
blob773a51657837c502e4f0904bf6f888bf62b00ea5
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 "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;
18 class Profile;
20 namespace extensions {
21 class Extension;
22 class ExtensionSet;
23 class ExtensionSyncData;
24 } // namespace extensions
26 namespace syncer {
27 class SyncChange;
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,
35 public KeyedService {
36 public:
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 void SyncOrderingChange(const std::string& extension_id);
51 // Notifies Sync (if needed) of a newly-installed extension or a change to
52 // an existing extension.
53 void SyncExtensionChangeIfNeeded(const extensions::Extension& extension);
55 // syncer::SyncableService implementation.
56 syncer::SyncMergeResult MergeDataAndStartSyncing(
57 syncer::ModelType type,
58 const syncer::SyncDataList& initial_sync_data,
59 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
60 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) override;
61 void StopSyncing(syncer::ModelType type) override;
62 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override;
63 syncer::SyncError ProcessSyncChanges(
64 const tracked_objects::Location& from_here,
65 const syncer::SyncChangeList& change_list) override;
67 // |flare| provides a StartSyncFlare to the SyncableService. See
68 // sync_start_util for more. Public for testing.
69 void SetSyncStartFlare(const syncer::SyncableService::StartSyncFlare& flare);
71 private:
72 FRIEND_TEST_ALL_PREFIXES(TwoClientAppsSyncTest, UnexpectedLaunchType);
73 FRIEND_TEST_ALL_PREFIXES(ExtensionDisabledGlobalErrorTest,
74 HigherPermissionsFromSync);
75 FRIEND_TEST_ALL_PREFIXES(ExtensionDisabledGlobalErrorTest, RemoteInstall);
76 friend class EphemeralAppBrowserTest;
78 // Gets the SyncBundle for the given |type|.
79 extensions::SyncBundle* GetSyncBundle(syncer::ModelType type);
80 const extensions::SyncBundle* GetSyncBundle(syncer::ModelType type) const;
82 // Creates the ExtensionSyncData for the given app/extension.
83 extensions::ExtensionSyncData CreateSyncData(
84 const extensions::Extension& extension) const;
86 // Applies the given change coming in from the server to the local state.
87 // Returns false if the changes were not completely applied and were added
88 // to the pending list.
89 bool ApplySyncData(const extensions::ExtensionSyncData& extension_sync_data);
91 // Collects the ExtensionSyncData for all installed apps or extensions.
92 // If |include_everything| is true, includes all installed extensions,
93 // otherwise only those that have the NeedsSync pref set, i.e. which have
94 // local changes that need to be pushed.
95 std::vector<extensions::ExtensionSyncData> GetLocalSyncDataList(
96 syncer::ModelType type, bool include_everything) const;
98 // Helper for GetLocalSyncDataList.
99 void FillSyncDataList(
100 const extensions::ExtensionSet& extensions,
101 syncer::ModelType type,
102 bool include_everything,
103 std::vector<extensions::ExtensionSyncData>* sync_data_list) const;
105 // Handles applying the extension specific values in |extension_sync_data| to
106 // the local state.
107 // Returns false if the changes were not completely applied.
108 bool ApplyExtensionSyncDataHelper(
109 const extensions::ExtensionSyncData& extension_sync_data,
110 syncer::ModelType type);
112 // Processes the bookmark app specific parts of an AppSyncData.
113 void ApplyBookmarkAppSyncData(
114 const extensions::ExtensionSyncData& extension_sync_data);
116 // The normal profile associated with this ExtensionService.
117 Profile* profile_;
119 // Preferences for the owning profile.
120 extensions::ExtensionPrefs* extension_prefs_;
122 ExtensionService* extension_service_;
124 extensions::SyncBundle app_sync_bundle_;
125 extensions::SyncBundle extension_sync_bundle_;
127 // Run()ning tells sync to try and start soon, because syncable changes
128 // have started happening. It will cause sync to call us back
129 // asynchronously via MergeDataAndStartSyncing as soon as possible.
130 syncer::SyncableService::StartSyncFlare flare_;
132 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncService);
135 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_