Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / extensions / sync_bundle.h
blob2e34a1003e65bf03572db74feefd5db33ca1e61c
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_
6 #define CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_
8 #include <set>
9 #include <string>
11 #include "base/memory/scoped_ptr.h"
12 #include "sync/api/sync_change.h"
13 #include "sync/api/sync_change_processor.h"
14 #include "sync/api/sync_data.h"
16 class ExtensionSyncService;
18 namespace extensions {
20 class ExtensionSyncData;
22 class SyncBundle {
23 public:
24 SyncBundle();
25 ~SyncBundle();
27 void StartSyncing(scoped_ptr<syncer::SyncChangeProcessor> sync_processor);
29 // Resets this class back to its default values, which will disable all
30 // syncing until StartSyncing is called again.
31 void Reset();
33 // Has this bundle started syncing yet?
34 // Returns true if StartSyncing has been called, false otherwise.
35 bool IsSyncing() const;
37 // 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);
42 // Updates the set of synced extensions as appropriate, and then pushes a
43 // SyncChange to the server.
44 void PushSyncDeletion(const std::string& extension_id,
45 const syncer::SyncData& sync_data);
47 // 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.
50 void PushSyncAddOrUpdate(const std::string& extension_id,
51 const syncer::SyncData& sync_data);
53 // 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);
57 // 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;
62 // Adds pending data for the extension with the given |id|.
63 void AddPendingExtensionData(const std::string& id,
64 const ExtensionSyncData& sync_data);
66 // Returns a vector of all the pending extension data.
67 std::vector<ExtensionSyncData> GetPendingExtensionData() const;
69 private:
70 // Creates a SyncChange to add or update an extension.
71 syncer::SyncChange CreateSyncChange(const std::string& extension_id,
72 const syncer::SyncData& sync_data) const;
74 // Pushes the given list of SyncChanges to the server.
75 void PushSyncChanges(const syncer::SyncChangeList& sync_change_list);
77 void AddSyncedExtension(const std::string& id);
78 void RemoveSyncedExtension(const std::string& id);
79 bool HasSyncedExtension(const std::string& id) const;
81 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
83 // Stores the set of extensions we know about. Used to decide if a sync change
84 // should be ACTION_ADD or ACTION_UPDATE.
85 std::set<std::string> synced_extensions_;
87 // This stores pending installs we got from sync. We'll send this back to the
88 // server until we've installed the extension locally, to prevent the sync
89 // state from flipping back and forth until all clients are up to date.
90 std::map<std::string, ExtensionSyncData> pending_sync_data_;
92 DISALLOW_COPY_AND_ASSIGN(SyncBundle);
95 } // namespace extensions
97 #endif // CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_