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_
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
;
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.
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
40 void PushSyncDataList(const syncer::SyncDataList
& sync_data_list
);
42 // Handles the sync deletion of the given extension. This updates the set of
43 // synced extensions as appropriate, and then pushes a SyncChange to the
45 void PushSyncDeletion(const std::string
& extension_id
,
46 const syncer::SyncData
& sync_data
);
48 // Pushes any sync changes to |extension| to the server.
49 void PushSyncAddOrUpdate(const std::string
& extension_id
,
50 const syncer::SyncData
& sync_data
);
52 // Applies the given sync change coming in from the server. This just updates
53 // the list of synced extensions.
54 void ApplySyncData(const ExtensionSyncData
& extension_sync_data
);
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.
58 bool HasPendingExtensionId(const std::string
& id
) const;
60 // Adds a pending extension to be synced.
61 void AddPendingExtension(const std::string
& id
,
62 const ExtensionSyncData
& sync_data
);
64 // Returns a vector of all the pending sync data.
65 std::vector
<ExtensionSyncData
> GetPendingData() const;
68 // Creates a SyncChange to add or update an extension.
69 syncer::SyncChange
CreateSyncChange(const std::string
& extension_id
,
70 const syncer::SyncData
& sync_data
) const;
72 // Pushes the given list of SyncChanges to the server.
73 void PushSyncChanges(const syncer::SyncChangeList
& sync_change_list
);
75 void AddSyncedExtension(const std::string
& id
);
76 void RemoveSyncedExtension(const std::string
& id
);
77 bool HasSyncedExtension(const std::string
& id
) const;
79 scoped_ptr
<syncer::SyncChangeProcessor
> sync_processor_
;
81 // Stores the set of extensions we know about. Used to decide if a sync change
82 // should be ACTION_ADD or ACTION_UPDATE.
83 std::set
<std::string
> synced_extensions_
;
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.
89 std::map
<std::string
, ExtensionSyncData
> pending_sync_data_
;
91 DISALLOW_COPY_AND_ASSIGN(SyncBundle
);
94 } // namespace extensions
96 #endif // CHROME_BROWSER_EXTENSIONS_SYNC_BUNDLE_H_