Chromium Code Reviews| OLD | NEW |
|---|---|
| 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. | 39 // Checks if the extension with the given |id| is synced. |
| 41 bool HasExtensionId(const std::string& id) const; | 40 bool HasExtensionId(const std::string& id) const; |
| 42 | 41 |
| 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 | 42 // Handles the given list of local SyncDatas. This updates the set of synced |
| 49 // extensions as appropriate, and then pushes the corresponding SyncChanges | 43 // extensions as appropriate, and then pushes the corresponding SyncChanges |
| 50 // to the server. | 44 // to the server. |
| 51 void PushSyncDataList(const syncer::SyncDataList& sync_data_list); | 45 void PushSyncDataList(const syncer::SyncDataList& sync_data_list); |
| 52 | 46 |
| 53 // Handles the sync deletion of the given extension. This updates the set of | 47 // 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 | 48 // synced extensions as appropriate, and then pushes a SyncChange to the |
| 55 // server. | 49 // server. |
| 56 void PushSyncDeletion(const std::string& extension_id, | 50 void PushSyncDeletion(const std::string& extension_id, |
| 57 const syncer::SyncData& sync_data); | 51 const syncer::SyncData& sync_data); |
| 58 | 52 |
| 59 // Pushes any sync changes to |extension| to the server. | 53 // Pushes any sync changes to |extension| to the server. |
| 60 void PushSyncChangeIfNeeded(const Extension& extension); | 54 void PushSyncChange(const std::string& extension_id, |
|
not at google - send to devlin
2015/07/15 20:27:57
I see that some of my comments in the other CL wer
| |
| 55 const syncer::SyncData& sync_data); | |
| 61 | 56 |
| 62 // Applies the given SyncChange coming from the server. | 57 // Applies the given SyncChange coming from the server. |
| 63 void ApplySyncChange(const syncer::SyncChange& sync_change); | 58 void ApplySyncChange(const syncer::SyncChange& sync_change); |
| 64 | 59 |
| 65 // Checks if the extension with the given |id| is pending to be synced. | 60 // Checks if there is pending sync data for the extension with the given |id| |
| 61 // that should be sent to the server instead of the local state. | |
| 66 bool HasPendingExtensionId(const std::string& id) const; | 62 bool HasPendingExtensionId(const std::string& id) const; |
| 67 | 63 |
| 68 // Adds a pending extension to be synced. | 64 // Adds a pending extension to be synced. |
| 69 void AddPendingExtension(const std::string& id, | 65 void AddPendingExtension(const std::string& id, |
| 70 const ExtensionSyncData& sync_data); | 66 const ExtensionSyncData& sync_data); |
| 71 | 67 |
| 72 // Returns a vector of all the pending sync data. | 68 // Returns a vector of all the pending sync data. |
| 73 std::vector<ExtensionSyncData> GetPendingData() const; | 69 std::vector<ExtensionSyncData> GetPendingData() const; |
| 74 | 70 |
| 75 private: | 71 private: |
| 76 // Creates a SyncChange to add or update an extension. | 72 // Creates a SyncChange to add or update an extension. |
| 77 syncer::SyncChange CreateSyncChange(const std::string& extension_id, | 73 syncer::SyncChange CreateSyncChange(const std::string& extension_id, |
| 78 const syncer::SyncData& sync_data) const; | 74 const syncer::SyncData& sync_data) const; |
| 79 | 75 |
| 80 // Pushes the given list of SyncChanges to the server. | 76 // Pushes the given list of SyncChanges to the server. |
| 81 void PushSyncChanges(const syncer::SyncChangeList& sync_change_list); | 77 void PushSyncChanges(const syncer::SyncChangeList& sync_change_list); |
| 82 | 78 |
| 83 void AddSyncedExtension(const std::string& id); | 79 void AddSyncedExtension(const std::string& id); |
| 84 void RemoveSyncedExtension(const std::string& id); | 80 void RemoveSyncedExtension(const std::string& id); |
| 85 | 81 |
| 86 // Changes an extension from being pending to synced. | 82 // Changes an extension from being pending to synced. |
| 87 void MarkPendingExtensionSynced(const std::string& id); | 83 void MarkPendingExtensionSynced(const std::string& id); |
| 88 | 84 |
| 89 ExtensionSyncService* sync_service_; // Owns us. | 85 ExtensionSyncService* sync_service_; // Owns us. |
| 90 | 86 |
| 91 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 87 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 92 | 88 |
| 93 std::set<std::string> synced_extensions_; | 89 std::set<std::string> synced_extensions_; |
| 94 | 90 |
| 95 std::map<std::string, ExtensionSyncData> pending_sync_data_; | 91 std::map<std::string, ExtensionSyncData> pending_sync_data_; |
|
not at google - send to devlin
2015/07/15 20:27:57
Could you add comments for this and |synced_extens
Marc Treib
2015/07/16 09:22:34
Added comments to explain. I don't think we can ge
| |
| 96 | 92 |
| 97 DISALLOW_COPY_AND_ASSIGN(SyncBundle); | 93 DISALLOW_COPY_AND_ASSIGN(SyncBundle); |
| 98 }; | 94 }; |
| 99 | 95 |
| 100 } // namespace extensions | 96 } // namespace extensions |
| 101 | 97 |
| 102 #endif // CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_ | 98 #endif // CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_ |
| OLD | NEW |