Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: chrome/browser/extensions/sync_bundle.h

Issue 1240573012: Extension syncing: Introduce a NeedsSync pref (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext_sync_uninstall
Patch Set: more cleanup; fix test Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_
6 #define CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "sync/api/sync_change.h" 12 #include "sync/api/sync_change.h"
13 #include "sync/api/sync_change_processor.h" 13 #include "sync/api/sync_change_processor.h"
14 #include "sync/api/sync_data.h" 14 #include "sync/api/sync_data.h"
15 15
16 class ExtensionSyncService; 16 class ExtensionSyncService;
17 17
18 namespace extensions { 18 namespace extensions {
19 19
20 class Extension;
21 class ExtensionSyncData; 20 class ExtensionSyncData;
22 21
23 class SyncBundle { 22 class SyncBundle {
24 public: 23 public:
25 explicit SyncBundle(ExtensionSyncService* sync_service); 24 explicit SyncBundle(ExtensionSyncService* sync_service);
26 ~SyncBundle(); 25 ~SyncBundle();
27 26
28 void MergeDataAndStartSyncing( 27 void MergeDataAndStartSyncing(
29 const syncer::SyncDataList& initial_sync_data, 28 const syncer::SyncDataList& initial_sync_data,
30 scoped_ptr<syncer::SyncChangeProcessor> sync_processor); 29 scoped_ptr<syncer::SyncChangeProcessor> sync_processor);
31 30
32 // Resets this class back to its default values, which will disable all 31 // Resets this class back to its default values, which will disable all
33 // syncing until StartSyncing is called again. 32 // syncing until StartSyncing is called again.
34 void Reset(); 33 void Reset();
35 34
36 // Has this bundle started syncing yet? 35 // Has this bundle started syncing yet?
37 // Returns true if MergeDataAndStartSyncing has been called, false otherwise. 36 // Returns true if MergeDataAndStartSyncing has been called, false otherwise.
38 bool IsSyncing() const; 37 bool IsSyncing() const;
39 38
40 // Checks if the extension with the given |id| is synced.
41 bool HasExtensionId(const std::string& id) const;
42
43 // Whether the given extension should be included in the SyncDataList to be
44 // sent to the server. Returns false if there is pending data that should be
45 // used instead.
46 bool ShouldIncludeInLocalSyncDataList(const Extension& extension) const;
47
48 // Handles the given list of local SyncDatas. This updates the set of synced 39 // Handles the given list of local SyncDatas. This updates the set of synced
49 // extensions as appropriate, and then pushes the corresponding SyncChanges 40 // extensions as appropriate, and then pushes the corresponding SyncChanges
50 // to the server. 41 // to the server.
51 void PushSyncDataList(const syncer::SyncDataList& sync_data_list); 42 void PushSyncDataList(const syncer::SyncDataList& sync_data_list);
52 43
53 // Handles the sync deletion of the given extension. This updates the set of 44 // Handles the sync deletion of the given extension. This updates the set of
54 // synced extensions as appropriate, and then pushes a SyncChange to the 45 // synced extensions as appropriate, and then pushes a SyncChange to the
55 // server. 46 // server.
56 void PushSyncDeletion(const std::string& extension_id, 47 void PushSyncDeletion(const std::string& extension_id,
57 const syncer::SyncData& sync_data); 48 const syncer::SyncData& sync_data);
58 49
59 // Pushes any sync changes to |extension| to the server. 50 // Pushes any sync changes to |extension| to the server.
60 void PushSyncAddOrUpdate(const Extension& extension); 51 void PushSyncAddOrUpdate(const std::string& extension_id,
52 const syncer::SyncData& sync_data);
61 53
62 // Applies the given SyncChange coming from the server. 54 // Applies the given SyncChange coming from the server.
63 void ApplySyncChange(const syncer::SyncChange& sync_change); 55 void ApplySyncChange(const syncer::SyncChange& sync_change);
64 56
65 // Checks if the extension with the given |id| is pending to be synced. 57 // Checks if there is pending sync data for the extension with the given |id|
58 // that should be sent to the server instead of the local state.
66 bool HasPendingExtensionId(const std::string& id) const; 59 bool HasPendingExtensionId(const std::string& id) const;
67 60
68 // Adds a pending extension to be synced. 61 // Adds a pending extension to be synced.
69 void AddPendingExtension(const std::string& id, 62 void AddPendingExtension(const std::string& id,
70 const ExtensionSyncData& sync_data); 63 const ExtensionSyncData& sync_data);
71 64
72 // Returns a vector of all the pending sync data. 65 // Returns a vector of all the pending sync data.
73 std::vector<ExtensionSyncData> GetPendingData() const; 66 std::vector<ExtensionSyncData> GetPendingData() const;
74 67
75 private: 68 private:
76 // Creates a SyncChange to add or update an extension. 69 // Creates a SyncChange to add or update an extension.
77 syncer::SyncChange CreateSyncChange(const std::string& extension_id, 70 syncer::SyncChange CreateSyncChange(const std::string& extension_id,
78 const syncer::SyncData& sync_data) const; 71 const syncer::SyncData& sync_data) const;
79 72
80 // Pushes the given list of SyncChanges to the server. 73 // Pushes the given list of SyncChanges to the server.
81 void PushSyncChanges(const syncer::SyncChangeList& sync_change_list); 74 void PushSyncChanges(const syncer::SyncChangeList& sync_change_list);
82 75
83 void AddSyncedExtension(const std::string& id); 76 void AddSyncedExtension(const std::string& id);
84 void RemoveSyncedExtension(const std::string& id); 77 void RemoveSyncedExtension(const std::string& id);
85 78 bool HasSyncedExtension(const std::string& id) const;
86 // Changes an extension from being pending to synced.
87 void MarkPendingExtensionSynced(const std::string& id);
88 79
89 ExtensionSyncService* sync_service_; // Owns us. 80 ExtensionSyncService* sync_service_; // Owns us.
90 81
91 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; 82 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
92 83
84 // Stores the set of extensions we know about. Used to decide if a sync change
85 // should be ACTION_ADD or ACTION_UPDATE.
93 std::set<std::string> synced_extensions_; 86 std::set<std::string> synced_extensions_;
94 87
88 // This stores changes we got from sync that we couldn't apply immediately
89 // (such as installing a new extension, or an update). We'll send this back
90 // to the server instead of the local state, to prevent the sync state from
91 // flipping back and forth until all clients are on the same state.
95 std::map<std::string, ExtensionSyncData> pending_sync_data_; 92 std::map<std::string, ExtensionSyncData> pending_sync_data_;
96 93
97 DISALLOW_COPY_AND_ASSIGN(SyncBundle); 94 DISALLOW_COPY_AND_ASSIGN(SyncBundle);
98 }; 95 };
99 96
100 } // namespace extensions 97 } // namespace extensions
101 98
102 #endif // CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_ 99 #endif // CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698