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