| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNCABLE_SETTINGS_STORAGE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNCABLE_SETTINGS_STORAGE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNCABLE_SETTINGS_STORAGE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNCABLE_SETTINGS_STORAGE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> |
| 10 #include <string> | 11 #include <string> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/observer_list_threadsafe.h" | 17 #include "base/observer_list_threadsafe.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/extensions/api/storage/setting_sync_data.h" | 19 #include "chrome/browser/extensions/api/storage/setting_sync_data.h" |
| 20 #include "extensions/browser/api/storage/settings_observer.h" | 20 #include "extensions/browser/api/storage/settings_observer.h" |
| 21 #include "extensions/browser/value_store/value_store.h" | 21 #include "extensions/browser/value_store/value_store.h" |
| 22 #include "sync/api/sync_change.h" | 22 #include "sync/api/sync_change.h" |
| 23 #include "sync/api/syncable_service.h" | 23 #include "sync/api/syncable_service.h" |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 | 26 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // Sync-related methods, analogous to those on SyncableService (handled by | 58 // Sync-related methods, analogous to those on SyncableService (handled by |
| 59 // ExtensionSettings), but with looser guarantees about when the methods | 59 // ExtensionSettings), but with looser guarantees about when the methods |
| 60 // can be called. | 60 // can be called. |
| 61 | 61 |
| 62 // Starts syncing this storage area. Must only be called if sync isn't | 62 // Starts syncing this storage area. Must only be called if sync isn't |
| 63 // already active. | 63 // already active. |
| 64 // |sync_state| is the current state of the extension settings in sync. | 64 // |sync_state| is the current state of the extension settings in sync. |
| 65 // |sync_processor| is used to write out any changes. | 65 // |sync_processor| is used to write out any changes. |
| 66 // Returns any error when trying to sync, or an empty error on success. | 66 // Returns any error when trying to sync, or an empty error on success. |
| 67 syncer::SyncError StartSyncing( | 67 syncer::SyncError StartSyncing( |
| 68 scoped_ptr<base::DictionaryValue> sync_state, | 68 std::unique_ptr<base::DictionaryValue> sync_state, |
| 69 scoped_ptr<SettingsSyncProcessor> sync_processor); | 69 std::unique_ptr<SettingsSyncProcessor> sync_processor); |
| 70 | 70 |
| 71 // Stops syncing this storage area. May be called at any time (idempotent). | 71 // Stops syncing this storage area. May be called at any time (idempotent). |
| 72 void StopSyncing(); | 72 void StopSyncing(); |
| 73 | 73 |
| 74 // Pushes a list of sync changes into this storage area. May be called at any | 74 // Pushes a list of sync changes into this storage area. May be called at any |
| 75 // time, changes will be ignored if sync isn't active. | 75 // time, changes will be ignored if sync isn't active. |
| 76 // Returns any error when trying to sync, or an empty error on success. | 76 // Returns any error when trying to sync, or an empty error on success. |
| 77 syncer::SyncError ProcessSyncChanges( | 77 syncer::SyncError ProcessSyncChanges( |
| 78 scoped_ptr<SettingSyncDataList> sync_changes); | 78 std::unique_ptr<SettingSyncDataList> sync_changes); |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 // Sends the changes from |result| to sync if it's enabled. | 81 // Sends the changes from |result| to sync if it's enabled. |
| 82 void SyncResultIfEnabled(const ValueStore::WriteResult& result); | 82 void SyncResultIfEnabled(const ValueStore::WriteResult& result); |
| 83 | 83 |
| 84 // Analyze the result returned by a call to the delegate, and take appropriate | 84 // Analyze the result returned by a call to the delegate, and take appropriate |
| 85 // measures. | 85 // measures. |
| 86 template <class T> | 86 template <class T> |
| 87 T HandleResult(T result); | 87 T HandleResult(T result); |
| 88 | 88 |
| 89 // Sends all local settings to sync. This assumes that there are no settings | 89 // Sends all local settings to sync. This assumes that there are no settings |
| 90 // in sync yet. | 90 // in sync yet. |
| 91 // Returns any error when trying to sync, or an empty error on success. | 91 // Returns any error when trying to sync, or an empty error on success. |
| 92 syncer::SyncError SendLocalSettingsToSync( | 92 syncer::SyncError SendLocalSettingsToSync( |
| 93 scoped_ptr<base::DictionaryValue> local_state); | 93 std::unique_ptr<base::DictionaryValue> local_state); |
| 94 | 94 |
| 95 // Overwrites local state with sync state. | 95 // Overwrites local state with sync state. |
| 96 // Returns any error when trying to sync, or an empty error on success. | 96 // Returns any error when trying to sync, or an empty error on success. |
| 97 syncer::SyncError OverwriteLocalSettingsWithSync( | 97 syncer::SyncError OverwriteLocalSettingsWithSync( |
| 98 scoped_ptr<base::DictionaryValue> sync_state, | 98 std::unique_ptr<base::DictionaryValue> sync_state, |
| 99 scoped_ptr<base::DictionaryValue> local_state); | 99 std::unique_ptr<base::DictionaryValue> local_state); |
| 100 | 100 |
| 101 // Called when an Add/Update/Remove comes from sync. Ownership of Value*s | 101 // Called when an Add/Update/Remove comes from sync. Ownership of Value*s |
| 102 // are taken. | 102 // are taken. |
| 103 syncer::SyncError OnSyncAdd( | 103 syncer::SyncError OnSyncAdd( |
| 104 const std::string& key, | 104 const std::string& key, |
| 105 base::Value* new_value, | 105 base::Value* new_value, |
| 106 ValueStoreChangeList* changes); | 106 ValueStoreChangeList* changes); |
| 107 syncer::SyncError OnSyncUpdate( | 107 syncer::SyncError OnSyncUpdate( |
| 108 const std::string& key, | 108 const std::string& key, |
| 109 base::Value* old_value, | 109 base::Value* old_value, |
| 110 base::Value* new_value, | 110 base::Value* new_value, |
| 111 ValueStoreChangeList* changes); | 111 ValueStoreChangeList* changes); |
| 112 syncer::SyncError OnSyncDelete( | 112 syncer::SyncError OnSyncDelete( |
| 113 const std::string& key, | 113 const std::string& key, |
| 114 base::Value* old_value, | 114 base::Value* old_value, |
| 115 ValueStoreChangeList* changes); | 115 ValueStoreChangeList* changes); |
| 116 | 116 |
| 117 // List of observers to settings changes. | 117 // List of observers to settings changes. |
| 118 const scoped_refptr<SettingsObserverList> observers_; | 118 const scoped_refptr<SettingsObserverList> observers_; |
| 119 | 119 |
| 120 // Id of the extension these settings are for. | 120 // Id of the extension these settings are for. |
| 121 std::string const extension_id_; | 121 std::string const extension_id_; |
| 122 | 122 |
| 123 // Storage area to sync. | 123 // Storage area to sync. |
| 124 const scoped_ptr<ValueStore> delegate_; | 124 const std::unique_ptr<ValueStore> delegate_; |
| 125 | 125 |
| 126 // Object which sends changes to sync. | 126 // Object which sends changes to sync. |
| 127 scoped_ptr<SettingsSyncProcessor> sync_processor_; | 127 std::unique_ptr<SettingsSyncProcessor> sync_processor_; |
| 128 | 128 |
| 129 const syncer::ModelType sync_type_; | 129 const syncer::ModelType sync_type_; |
| 130 const syncer::SyncableService::StartSyncFlare flare_; | 130 const syncer::SyncableService::StartSyncFlare flare_; |
| 131 | 131 |
| 132 DISALLOW_COPY_AND_ASSIGN(SyncableSettingsStorage); | 132 DISALLOW_COPY_AND_ASSIGN(SyncableSettingsStorage); |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 } // namespace extensions | 135 } // namespace extensions |
| 136 | 136 |
| 137 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNCABLE_SETTINGS_STORAGE_H_ | 137 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNCABLE_SETTINGS_STORAGE_H_ |
| OLD | NEW |