- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / extension_sync_bundle.h
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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_BUNDLE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_BUNDLE_H_
7
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "chrome/browser/extensions/extension_sync_data.h"
16 #include "chrome/browser/extensions/sync_bundle.h"
17 #include "sync/api/syncable_service.h"
18
19 class ExtensionSyncService;
20 class ExtensionSet;
21
22 namespace syncer {
23 class SyncChangeProcessor;
24 class SyncErrorFactory;
25 }
26
27 namespace extensions {
28
29 class Extension;
30
31 // Bundle of extension specific sync stuff.
32 class ExtensionSyncBundle : public SyncBundle {
33  public:
34   explicit ExtensionSyncBundle(ExtensionSyncService* extension_sync_service);
35   virtual ~ExtensionSyncBundle();
36
37   // Setup this bundle to be sync extension data.
38   void SetupSync(syncer::SyncChangeProcessor* sync_processor,
39                  syncer::SyncErrorFactory* sync_error_factory,
40                  const syncer::SyncDataList& initial_sync_data);
41
42   // Resets this class back to it default values, which will disable all syncing
43   // until a new sync processor is set.
44   void Reset();
45
46   // Returns a syncer::SyncChange that will delete the given extension.
47   syncer::SyncChange CreateSyncChangeToDelete(const Extension* extension) const;
48
49   // Process the sync deletion of the given extension.
50   void ProcessDeletion(
51       std::string extension_id, const syncer::SyncChange& sync_change);
52
53   // Create a sync change based on |sync_data|.
54   syncer::SyncChange CreateSyncChange(const syncer::SyncData& sync_data);
55
56   // Get all the sync data contained in this bundle.
57   syncer::SyncDataList GetAllSyncData() const;
58
59   // Process the given sync change and apply it.
60   void ProcessSyncChange(ExtensionSyncData extension_sync_data);
61
62   // Process the list of sync changes.
63   void ProcessSyncChangeList(syncer::SyncChangeList sync_change_list);
64
65   // Check to see if the given |id| is either synced or pending to be synced.
66   bool HasExtensionId(const std::string& id) const;
67   bool HasPendingExtensionId(const std::string& id) const;
68
69   // Add a pending extension to be synced.
70   void AddPendingExtension(const std::string& id,
71                            const ExtensionSyncData& extension_sync_data);
72
73   // Returns a vector of all the pending sync data.
74   std::vector<ExtensionSyncData> GetPendingData() const;
75
76   // Appends sync data objects for every extension in |extensions|.
77   void GetExtensionSyncDataListHelper(
78       const ExtensionSet* extensions,
79       std::vector<extensions::ExtensionSyncData>* sync_data_list) const;
80
81   // Overrides for SyncBundle.
82   // Returns true if SetupSync has been called, false otherwise.
83   virtual bool IsSyncing() const OVERRIDE;
84
85   // Sync a newly-installed extension or change an existing one.
86   virtual void SyncChangeIfNeeded(const Extension& extension) OVERRIDE;
87
88  private:
89   // Add a synced extension.
90   void AddExtension(const std::string& id);
91
92   // Remove a synced extension.
93   void RemoveExtension(const std::string& id);
94
95   // Change an extension from being pending to synced.
96   void MarkPendingExtensionSynced(const std::string& id);
97
98   ExtensionSyncService* extension_sync_service_;  // Owns us.
99   scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
100   scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_;
101
102   std::set<std::string> synced_extensions_;
103   std::map<std::string, ExtensionSyncData> pending_sync_data_;
104
105   DISALLOW_COPY_AND_ASSIGN(ExtensionSyncBundle);
106 };
107
108 }  // namespace extensions
109
110 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_BUNDLE_H_