1 // Copyright (c) 2012 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_EXTENSION_SYNC_BUNDLE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_BUNDLE_H_
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "chrome/browser/extensions/extension_sync_data.h"
16 #include "sync/api/syncable_service.h"
18 class ExtensionService
;
22 class SyncChangeProcessor
;
23 class SyncErrorFactory
;
26 namespace extensions
{
30 // Bundle of extension specific sync stuff.
31 class ExtensionSyncBundle
{
33 explicit ExtensionSyncBundle(ExtensionService
* extension_service
);
34 ~ExtensionSyncBundle();
36 // Setup this bundle to be sync extension data.
37 void SetupSync(syncer::SyncChangeProcessor
* sync_processor
,
38 syncer::SyncErrorFactory
* sync_error_factory
,
39 const syncer::SyncDataList
& initial_sync_data
);
41 // Resets this class back to it default values, which will disable all syncing
42 // until a new sync processor is set.
45 // Returns a syncer::SyncChange that will delete the given extension.
46 syncer::SyncChange
CreateSyncChangeToDelete(const Extension
* extension
) const;
48 // Process the sync deletion of the given extension.
50 std::string extension_id
, const syncer::SyncChange
& sync_change
);
52 // Create a sync change based on |sync_data|.
53 syncer::SyncChange
CreateSyncChange(const syncer::SyncData
& sync_data
);
55 // Get all the sync data contained in this bundle.
56 syncer::SyncDataList
GetAllSyncData() const;
58 // Process the given sync change and apply it.
59 void ProcessSyncChange(ExtensionSyncData extension_sync_data
);
61 // Sync a newly-installed extension or change an existing one.
62 void SyncChangeIfNeeded(const Extension
& extension
);
64 // Process the list of sync changes.
65 void ProcessSyncChangeList(syncer::SyncChangeList sync_change_list
);
67 // Check to see if the given |id| is either synced or pending to be synced.
68 bool HasExtensionId(const std::string
& id
) const;
69 bool HasPendingExtensionId(const std::string
& id
) const;
71 // Add a pending extension to be synced.
72 void AddPendingExtension(const std::string
& id
,
73 const ExtensionSyncData
& extension_sync_data
);
75 // Returns a vector of all the pending sync data.
76 std::vector
<ExtensionSyncData
> GetPendingData() const;
78 // Appends sync data objects for every extension in |extensions|.
79 void GetExtensionSyncDataListHelper(
80 const ExtensionSet
& extensions
,
81 std::vector
<extensions::ExtensionSyncData
>* sync_data_list
) const;
83 // Returns true if SetupSync has been called, false otherwise.
84 bool IsSyncing() const;
87 // Add a synced extension.
88 void AddExtension(const std::string
& id
);
90 // Remove a synced extension.
91 void RemoveExtension(const std::string
& id
);
93 // Change an extension from being pending to synced.
94 void MarkPendingExtensionSynced(const std::string
& id
);
96 ExtensionService
* extension_service_
; // Owns us.
97 scoped_ptr
<syncer::SyncChangeProcessor
> sync_processor_
;
98 scoped_ptr
<syncer::SyncErrorFactory
> sync_error_factory_
;
100 std::set
<std::string
> synced_extensions_
;
101 std::map
<std::string
, ExtensionSyncData
> pending_sync_data_
;
103 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncBundle
);
106 } // namespace extensions
108 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_BUNDLE_H_