blob: 5a1b53a745dde52d310a1a0522a6e6da743129e4 [file] [log] [blame]
[email protected]50736a12013-09-26 08:58:341// 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.
4
5#ifndef CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_
6#define CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_
7
dchengc963c7142016-04-08 03:55:228#include <memory>
treib0c714f7c2015-07-08 10:04:589#include <set>
10#include <string>
11
avia2f4804a2015-12-24 23:11:1312#include "base/macros.h"
skym71603842016-10-10 18:17:3113#include "components/sync/model/sync_change.h"
14#include "components/sync/model/sync_change_processor.h"
15#include "components/sync/model/sync_data.h"
treib0c714f7c2015-07-08 10:04:5816
[email protected]50736a12013-09-26 08:58:3417namespace extensions {
18
treib0c714f7c2015-07-08 10:04:5819class ExtensionSyncData;
[email protected]50736a12013-09-26 08:58:3420
[email protected]50736a12013-09-26 08:58:3421class SyncBundle {
22 public:
treibc3494532015-07-21 14:51:4523 SyncBundle();
treib0c714f7c2015-07-08 10:04:5824 ~SyncBundle();
25
dchengc963c7142016-04-08 03:55:2226 void StartSyncing(
27 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor);
treib0c714f7c2015-07-08 10:04:5828
29 // Resets this class back to its default values, which will disable all
30 // syncing until StartSyncing is called again.
31 void Reset();
[email protected]50736a12013-09-26 08:58:3432
33 // Has this bundle started syncing yet?
treibc3494532015-07-21 14:51:4534 // Returns true if StartSyncing has been called, false otherwise.
treib0c714f7c2015-07-08 10:04:5835 bool IsSyncing() const;
[email protected]50736a12013-09-26 08:58:3436
treib0c714f7c2015-07-08 10:04:5837 // Handles the given list of local SyncDatas. This updates the set of synced
38 // extensions as appropriate, and then pushes the corresponding SyncChanges
39 // to the server.
40 void PushSyncDataList(const syncer::SyncDataList& sync_data_list);
41
treibecc63c8d2015-09-07 16:34:4742 // Updates the set of synced extensions as appropriate, and then pushes a
43 // SyncChange to the server.
treib0c714f7c2015-07-08 10:04:5844 void PushSyncDeletion(const std::string& extension_id,
45 const syncer::SyncData& sync_data);
46
treibecc63c8d2015-09-07 16:34:4747 // Pushes any sync changes to an extension to the server and, if necessary,
48 // updates the set of synced extension. This also clears any pending data for
49 // the extension.
treibc3494532015-07-21 14:51:4550 void PushSyncAddOrUpdate(const std::string& extension_id,
51 const syncer::SyncData& sync_data);
treib0c714f7c2015-07-08 10:04:5852
treibc3494532015-07-21 14:51:4553 // Applies the given sync change coming in from the server. This just updates
54 // the list of synced extensions.
55 void ApplySyncData(const ExtensionSyncData& extension_sync_data);
treib0c714f7c2015-07-08 10:04:5856
treibecc63c8d2015-09-07 16:34:4757 // Checks if there is pending sync data for the extension with the given |id|,
58 // i.e. data to be sent to the sync server until the extension is installed
59 // locally.
60 bool HasPendingExtensionData(const std::string& id) const;
treib0c714f7c2015-07-08 10:04:5861
treib227b2582015-12-09 09:28:2662 // Adds pending data for the given extension.
63 void AddPendingExtensionData(const ExtensionSyncData& extension_sync_data);
treib0c714f7c2015-07-08 10:04:5864
treibecc63c8d2015-09-07 16:34:4765 // Returns a vector of all the pending extension data.
66 std::vector<ExtensionSyncData> GetPendingExtensionData() const;
treib0c714f7c2015-07-08 10:04:5867
68 private:
69 // Creates a SyncChange to add or update an extension.
70 syncer::SyncChange CreateSyncChange(const std::string& extension_id,
71 const syncer::SyncData& sync_data) const;
72
73 // Pushes the given list of SyncChanges to the server.
74 void PushSyncChanges(const syncer::SyncChangeList& sync_change_list);
75
76 void AddSyncedExtension(const std::string& id);
77 void RemoveSyncedExtension(const std::string& id);
treibc3494532015-07-21 14:51:4578 bool HasSyncedExtension(const std::string& id) const;
treib0c714f7c2015-07-08 10:04:5879
dchengc963c7142016-04-08 03:55:2280 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_;
treib0c714f7c2015-07-08 10:04:5881
treibc3494532015-07-21 14:51:4582 // Stores the set of extensions we know about. Used to decide if a sync change
83 // should be ACTION_ADD or ACTION_UPDATE.
treib0c714f7c2015-07-08 10:04:5884 std::set<std::string> synced_extensions_;
85
treibecc63c8d2015-09-07 16:34:4786 // This stores pending installs we got from sync. We'll send this back to the
87 // server until we've installed the extension locally, to prevent the sync
88 // state from flipping back and forth until all clients are up to date.
treib0c714f7c2015-07-08 10:04:5889 std::map<std::string, ExtensionSyncData> pending_sync_data_;
90
91 DISALLOW_COPY_AND_ASSIGN(SyncBundle);
[email protected]50736a12013-09-26 08:58:3492};
93
94} // namespace extensions
95
96#endif // CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_