Make default apps cache multiprofile friendly
[chromium-blink-merge.git] / chrome / browser / extensions / app_sync_bundle.h
blobd5172ff71c52a33a29ad15c51af53da28d39f2a6
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_APP_SYNC_BUNDLE_H_
6 #define CHROME_BROWSER_EXTENSIONS_APP_SYNC_BUNDLE_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "chrome/browser/extensions/app_sync_data.h"
16 #include "sync/api/syncable_service.h"
18 class ExtensionService;
19 class ExtensionSet;
21 namespace syncer {
22 class SyncChangeProcessor;
23 class SyncErrorFactory;
26 namespace extensions {
28 class Extension;
30 // Bundle of app specific sync stuff.
31 class AppSyncBundle {
32 public:
33 explicit AppSyncBundle(ExtensionService* extension_service);
34 virtual ~AppSyncBundle();
36 // Setup this bundle to be sync application data.
37 void SetupSync(syncer::SyncChangeProcessor* sync_proccessor,
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.
43 void Reset();
45 // Returns a syncer::SyncChange that will delete the given application.
46 syncer::SyncChange CreateSyncChangeToDelete(const Extension* extension) const;
48 // Process the sync deletion of the given application.
49 void ProcessDeletion(
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 // Sync a newly-installed application or change an existing one.
59 void SyncChangeIfNeeded(const Extension& extension);
61 // Process the given sync change and apply it.
62 void ProcessSyncChange(AppSyncData app_sync_data);
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 app to be synced.
72 void AddPendingApp(const std::string& id,
73 const AppSyncData& app_sync_data);
75 // Returns a vector of all the pending sync data.
76 std::vector<AppSyncData> GetPendingData() const;
78 // Appends sync data objects for every app in |extensions|.
79 void GetAppSyncDataListHelper(
80 const ExtensionSet& extensions,
81 std::vector<extensions::AppSyncData>* sync_data_list) const;
83 // Returns true if SetupSync has been called, false otherwise.
84 bool IsSyncing() const;
86 private:
87 // Add a synced app.
88 void AddApp(const std::string& id);
90 // Remove a synced app.
91 void RemoveApp(const std::string& id); // make private
93 // Change an app from being pending to synced.
94 void MarkPendingAppSynced(const std::string& id);
96 ExtensionService* extension_service_; // Own us.
97 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
98 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_;
100 std::set<std::string> synced_apps_;
101 std::map<std::string, AppSyncData> pending_sync_data_;
103 DISALLOW_COPY_AND_ASSIGN(AppSyncBundle);
106 } // namespace extensions
108 #endif // CHROME_BROWSER_EXTENSIONS_APP_SYNC_BUNDLE_H_