OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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_SETTING_SYNC_DATA_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTING_SYNC_DATA_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/values.h" |
| 12 #include "chrome/browser/sync/api/sync_data.h" |
| 13 #include "chrome/browser/sync/api/sync_change.h" |
| 14 |
| 15 // Container for data interpreted from sync data/changes. Safe and efficient |
| 16 // to copy. |
| 17 class ExtensionSettingSyncData { |
| 18 public: |
| 19 // Creates from a sync change. |
| 20 explicit ExtensionSettingSyncData(const SyncChange& sync_change); |
| 21 |
| 22 // Creates from sync data. change_type will be ACTION_INVALID. |
| 23 explicit ExtensionSettingSyncData(const SyncData& sync_data); |
| 24 |
| 25 // Creates explicitly. |
| 26 ExtensionSettingSyncData( |
| 27 SyncChange::SyncChangeType change_type, |
| 28 const std::string& extension_id, |
| 29 const std::string& key, |
| 30 // May NOT be NULL. Ownership taken. |
| 31 Value* value); |
| 32 |
| 33 ~ExtensionSettingSyncData(); |
| 34 |
| 35 // Returns the type of the sync change; may be ACTION_INVALID. |
| 36 SyncChange::SyncChangeType change_type() const; |
| 37 |
| 38 // Returns the extension id the setting is for. |
| 39 const std::string& extension_id() const; |
| 40 |
| 41 // Returns the settings key. |
| 42 const std::string& key() const; |
| 43 |
| 44 // Returns the value of the setting. |
| 45 const Value& value() const; |
| 46 |
| 47 private: |
| 48 // Ref-counted container for the data. |
| 49 // TODO(kalman): Use browser_sync::Immutable<Internal>. |
| 50 class Internal : public base::RefCountedThreadSafe<Internal> { |
| 51 public: |
| 52 explicit Internal( |
| 53 SyncChange::SyncChangeType change_type, |
| 54 const std::string& extension_id, |
| 55 const std::string& key, |
| 56 Value* value); |
| 57 |
| 58 SyncChange::SyncChangeType change_type_; |
| 59 std::string extension_id_; |
| 60 std::string key_; |
| 61 scoped_ptr<Value> value_; |
| 62 |
| 63 private: |
| 64 friend class base::RefCountedThreadSafe<Internal>; |
| 65 ~Internal(); |
| 66 }; |
| 67 |
| 68 // Initializes internal_ from sync data. |
| 69 void Init(SyncChange::SyncChangeType change_type, const SyncData& sync_data); |
| 70 |
| 71 scoped_refptr<Internal> internal_; |
| 72 }; |
| 73 |
| 74 typedef std::vector<ExtensionSettingSyncData> ExtensionSettingSyncDataList; |
| 75 |
| 76 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTING_SYNC_DATA_H_ |
OLD | NEW |