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

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: (b); hackfix sync_integration_tests 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 SyncBundle();
26 ~SyncBundle(); 25 ~SyncBundle();
27 26
28 void MergeDataAndStartSyncing( 27 void StartSyncing(scoped_ptr<syncer::SyncChangeProcessor> sync_processor);
29 const syncer::SyncDataList& initial_sync_data,
30 scoped_ptr<syncer::SyncChangeProcessor> sync_processor);
31 28
32 // Resets this class back to its default values, which will disable all 29 // Resets this class back to its default values, which will disable all
33 // syncing until StartSyncing is called again. 30 // syncing until StartSyncing is called again.
34 void Reset(); 31 void Reset();
35 32
36 // Has this bundle started syncing yet? 33 // Has this bundle started syncing yet?
37 // Returns true if MergeDataAndStartSyncing has been called, false otherwise. 34 // Returns true if StartSyncing has been called, false otherwise.
38 bool IsSyncing() const; 35 bool IsSyncing() const;
39 36
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 37 // Handles the given list of local SyncDatas. This updates the set of synced
49 // extensions as appropriate, and then pushes the corresponding SyncChanges 38 // extensions as appropriate, and then pushes the corresponding SyncChanges
50 // to the server. 39 // to the server.
51 void PushSyncDataList(const syncer::SyncDataList& sync_data_list); 40 void PushSyncDataList(const syncer::SyncDataList& sync_data_list);
52 41
53 // Handles the sync deletion of the given extension. This updates the set of 42 // 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 43 // synced extensions as appropriate, and then pushes a SyncChange to the
55 // server. 44 // server.
56 void PushSyncDeletion(const std::string& extension_id, 45 void PushSyncDeletion(const std::string& extension_id,
57 const syncer::SyncData& sync_data); 46 const syncer::SyncData& sync_data);
58 47
59 // Pushes any sync changes to |extension| to the server. 48 // Pushes any sync changes to |extension| to the server.
60 void PushSyncAddOrUpdate(const Extension& extension); 49 void PushSyncAddOrUpdate(const std::string& extension_id,
50 const syncer::SyncData& sync_data);
61 51
62 // Applies the given SyncChange coming from the server. 52 // Applies the given sync change coming in from the server. This just updates
63 void ApplySyncChange(const syncer::SyncChange& sync_change); 53 // the list of synced extensions.
54 void ApplySyncData(const ExtensionSyncData& extension_sync_data);
64 55
65 // Checks if the extension with the given |id| is pending to be synced. 56 // Checks if there is pending sync data for the extension with the given |id|
57 // that should be sent to the server instead of the local state.
66 bool HasPendingExtensionId(const std::string& id) const; 58 bool HasPendingExtensionId(const std::string& id) const;
67 59
68 // Adds a pending extension to be synced. 60 // Adds a pending extension to be synced.
69 void AddPendingExtension(const std::string& id, 61 void AddPendingExtension(const std::string& id,
70 const ExtensionSyncData& sync_data); 62 const ExtensionSyncData& sync_data);
71 63
72 // Returns a vector of all the pending sync data. 64 // Returns a vector of all the pending sync data.
73 std::vector<ExtensionSyncData> GetPendingData() const; 65 std::vector<ExtensionSyncData> GetPendingData() const;
74 66
75 private: 67 private:
76 // Creates a SyncChange to add or update an extension. 68 // Creates a SyncChange to add or update an extension.
77 syncer::SyncChange CreateSyncChange(const std::string& extension_id, 69 syncer::SyncChange CreateSyncChange(const std::string& extension_id,
78 const syncer::SyncData& sync_data) const; 70 const syncer::SyncData& sync_data) const;
79 71
80 // Pushes the given list of SyncChanges to the server. 72 // Pushes the given list of SyncChanges to the server.
81 void PushSyncChanges(const syncer::SyncChangeList& sync_change_list); 73 void PushSyncChanges(const syncer::SyncChangeList& sync_change_list);
82 74
83 void AddSyncedExtension(const std::string& id); 75 void AddSyncedExtension(const std::string& id);
84 void RemoveSyncedExtension(const std::string& id); 76 void RemoveSyncedExtension(const std::string& id);
85 77 bool HasSyncedExtension(const std::string& id) const;
86 // Changes an extension from being pending to synced.
87 void MarkPendingExtensionSynced(const std::string& id);
88
89 ExtensionSyncService* sync_service_; // Owns us.
90 78
91 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; 79 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
92 80
81 // Stores the set of extensions we know about. Used to decide if a sync change
82 // should be ACTION_ADD or ACTION_UPDATE.
93 std::set<std::string> synced_extensions_; 83 std::set<std::string> synced_extensions_;
94 84
85 // This stores changes we got from sync that we couldn't apply immediately
86 // (such as installing a new extension, or an update). We'll send this back
87 // to the server instead of the local state, to prevent the sync state from
88 // flipping back and forth until all clients are on the same state.
95 std::map<std::string, ExtensionSyncData> pending_sync_data_; 89 std::map<std::string, ExtensionSyncData> pending_sync_data_;
96 90
97 DISALLOW_COPY_AND_ASSIGN(SyncBundle); 91 DISALLOW_COPY_AND_ASSIGN(SyncBundle);
98 }; 92 };
99 93
100 } // namespace extensions 94 } // namespace extensions
101 95
102 #endif // CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_ 96 #endif // CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698