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_SETTINGS_SETTING_SYNC_DATA_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTING_SYNC_DATA_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTING_SYNC_DATA_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTING_SYNC_DATA_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "sync/api/sync_change.h" | 12 #include "sync/api/sync_change.h" |
13 | 13 |
| 14 namespace csync { |
14 class SyncData; | 15 class SyncData; |
| 16 } |
| 17 |
15 namespace sync_pb { | 18 namespace sync_pb { |
16 class ExtensionSettingSpecifics; | 19 class ExtensionSettingSpecifics; |
17 } | 20 } |
18 | 21 |
19 namespace extensions { | 22 namespace extensions { |
20 | 23 |
21 // Container for data interpreted from sync data/changes for an extension or | 24 // Container for data interpreted from sync data/changes for an extension or |
22 // app setting. Safe and efficient to copy. | 25 // app setting. Safe and efficient to copy. |
23 class SettingSyncData { | 26 class SettingSyncData { |
24 public: | 27 public: |
25 // Creates from a sync change. | 28 // Creates from a sync change. |
26 explicit SettingSyncData(const SyncChange& sync_change); | 29 explicit SettingSyncData(const csync::SyncChange& sync_change); |
27 | 30 |
28 // Creates from sync data. |change_type| will be ACTION_INVALID. | 31 // Creates from sync data. |change_type| will be ACTION_INVALID. |
29 explicit SettingSyncData(const SyncData& sync_data); | 32 explicit SettingSyncData(const csync::SyncData& sync_data); |
30 | 33 |
31 // Creates explicitly. | 34 // Creates explicitly. |
32 SettingSyncData( | 35 SettingSyncData( |
33 SyncChange::SyncChangeType change_type, | 36 csync::SyncChange::SyncChangeType change_type, |
34 const std::string& extension_id, | 37 const std::string& extension_id, |
35 const std::string& key, | 38 const std::string& key, |
36 scoped_ptr<Value> value); | 39 scoped_ptr<Value> value); |
37 | 40 |
38 ~SettingSyncData(); | 41 ~SettingSyncData(); |
39 | 42 |
40 // Returns the type of the sync change; may be ACTION_INVALID. | 43 // Returns the type of the sync change; may be ACTION_INVALID. |
41 SyncChange::SyncChangeType change_type() const; | 44 csync::SyncChange::SyncChangeType change_type() const; |
42 | 45 |
43 // Returns the extension id the setting is for. | 46 // Returns the extension id the setting is for. |
44 const std::string& extension_id() const; | 47 const std::string& extension_id() const; |
45 | 48 |
46 // Returns the settings key. | 49 // Returns the settings key. |
47 const std::string& key() const; | 50 const std::string& key() const; |
48 | 51 |
49 // Returns the value of the setting. | 52 // Returns the value of the setting. |
50 const Value& value() const; | 53 const Value& value() const; |
51 | 54 |
52 private: | 55 private: |
53 // Ref-counted container for the data. | 56 // Ref-counted container for the data. |
54 // TODO(kalman): Use browser_sync::Immutable<Internal>. | 57 // TODO(kalman): Use browser_sync::Immutable<Internal>. |
55 class Internal : public base::RefCountedThreadSafe<Internal> { | 58 class Internal : public base::RefCountedThreadSafe<Internal> { |
56 public: | 59 public: |
57 Internal( | 60 Internal( |
58 SyncChange::SyncChangeType change_type, | 61 csync::SyncChange::SyncChangeType change_type, |
59 const std::string& extension_id, | 62 const std::string& extension_id, |
60 const std::string& key, | 63 const std::string& key, |
61 scoped_ptr<Value> value); | 64 scoped_ptr<Value> value); |
62 | 65 |
63 SyncChange::SyncChangeType change_type_; | 66 csync::SyncChange::SyncChangeType change_type_; |
64 std::string extension_id_; | 67 std::string extension_id_; |
65 std::string key_; | 68 std::string key_; |
66 scoped_ptr<Value> value_; | 69 scoped_ptr<Value> value_; |
67 | 70 |
68 private: | 71 private: |
69 friend class base::RefCountedThreadSafe<Internal>; | 72 friend class base::RefCountedThreadSafe<Internal>; |
70 ~Internal(); | 73 ~Internal(); |
71 }; | 74 }; |
72 | 75 |
73 // Initializes internal_ from sync data for an extension or app setting. | 76 // Initializes internal_ from sync data for an extension or app setting. |
74 void Init(SyncChange::SyncChangeType change_type, const SyncData& sync_data); | 77 void Init(csync::SyncChange::SyncChangeType change_type, |
| 78 const csync::SyncData& sync_data); |
75 | 79 |
76 // Initializes internal_ from extension specifics. | 80 // Initializes internal_ from extension specifics. |
77 void InitFromExtensionSettingSpecifics( | 81 void InitFromExtensionSettingSpecifics( |
78 SyncChange::SyncChangeType change_type, | 82 csync::SyncChange::SyncChangeType change_type, |
79 const sync_pb::ExtensionSettingSpecifics& specifics); | 83 const sync_pb::ExtensionSettingSpecifics& specifics); |
80 | 84 |
81 scoped_refptr<Internal> internal_; | 85 scoped_refptr<Internal> internal_; |
82 }; | 86 }; |
83 | 87 |
84 typedef std::vector<SettingSyncData> SettingSyncDataList; | 88 typedef std::vector<SettingSyncData> SettingSyncDataList; |
85 | 89 |
86 } // namespace extensions | 90 } // namespace extensions |
87 | 91 |
88 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTING_SYNC_DATA_H_ | 92 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTING_SYNC_DATA_H_ |
OLD | NEW |