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_API_STORAGE_SETTINGS_SYNC_PROCESSOR_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_SYNC_PROCESSOR_H_
11 #include "extensions/browser/value_store/value_store_change.h"
12 #include "sync/api/sync_error.h"
15 class SyncChangeProcessor
;
18 namespace extensions
{
20 // A wrapper for a SyncChangeProcessor that deals specifically with the syncing
21 // of a single extension's settings. Handles:
22 // - translating SettingChanges into calls into the Sync API.
23 // - deciding whether to ADD/REMOVE/SET depending on the current state of
25 // - rate limiting (inherently per-extension, which is what we want).
26 class SettingsSyncProcessor
{
28 SettingsSyncProcessor(const std::string
& extension_id
,
29 syncer::ModelType type
,
30 syncer::SyncChangeProcessor
* sync_processor
);
31 ~SettingsSyncProcessor();
33 // Initializes this with the initial state of sync.
34 void Init(const base::DictionaryValue
& initial_state
);
36 // Sends |changes| to sync.
37 syncer::SyncError
SendChanges(const ValueStoreChangeList
& changes
);
39 // Informs this that |changes| have been receieved from sync. No action will
40 // be taken, but this must be notified for internal bookkeeping.
41 void NotifyChanges(const ValueStoreChangeList
& changes
);
43 syncer::ModelType
type() { return type_
; }
46 // ID of the extension the changes are for.
47 const std::string extension_id_
;
49 // Sync model type. Either EXTENSION_SETTING or APP_SETTING.
50 const syncer::ModelType type_
;
52 // The sync processor used to send changes to sync.
53 syncer::SyncChangeProcessor
* const sync_processor_
;
55 // Whether Init() has been called.
58 // Keys of the settings that are currently being synced. Used to decide what
59 // kind of action (ADD, UPDATE, REMOVE) to send to sync.
60 std::set
<std::string
> synced_keys_
;
62 DISALLOW_COPY_AND_ASSIGN(SettingsSyncProcessor
);
65 } // namespace extensions
67 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_SYNC_PROCESSOR_H_