Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: chrome/browser/extensions/api/storage/setting_sync_data.h

Issue 1141963002: Remove a bunch of DeepCopy() calls in the chrome.storage API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fun times Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_SETTING_SYNC_DATA_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTING_SYNC_DATA_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTING_SYNC_DATA_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTING_SYNC_DATA_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include <string>
9
10 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
10 #include "base/values.h" 13 #include "base/values.h"
11 #include "sync/api/sync_change.h" 14 #include "sync/api/sync_change.h"
12 15
13 namespace syncer { 16 namespace syncer {
14 class SyncData; 17 class SyncData;
15 } 18 }
16 19
17 namespace sync_pb { 20 namespace sync_pb {
18 class ExtensionSettingSpecifics; 21 class ExtensionSettingSpecifics;
19 } 22 }
(...skipping 12 matching lines...) Expand all
32 35
33 // Creates explicitly. 36 // Creates explicitly.
34 SettingSyncData( 37 SettingSyncData(
35 syncer::SyncChange::SyncChangeType change_type, 38 syncer::SyncChange::SyncChangeType change_type,
36 const std::string& extension_id, 39 const std::string& extension_id,
37 const std::string& key, 40 const std::string& key,
38 scoped_ptr<base::Value> value); 41 scoped_ptr<base::Value> value);
39 42
40 ~SettingSyncData(); 43 ~SettingSyncData();
41 44
42 // Returns the type of the sync change; may be ACTION_INVALID. 45 // Returns the type of the sync change; may be ACTION_INVALID.
Devlin 2015/05/19 15:41:55 nit: We almost never document simple accessors. M
not at google - send to devlin 2015/05/19 19:43:58 This comment serves a purpose.
43 syncer::SyncChange::SyncChangeType change_type() const; 46 syncer::SyncChange::SyncChangeType change_type() const {
47 return change_type_;
48 }
44 49
45 // Returns the extension id the setting is for. 50 // Returns the extension id the setting is for.
not at google - send to devlin 2015/05/19 19:43:58 this does not
46 const std::string& extension_id() const; 51 const std::string& extension_id() const { return extension_id_; }
47 52
48 // Returns the settings key. 53 // Returns the settings key.
not at google - send to devlin 2015/05/19 19:43:58 nor does this
49 const std::string& key() const; 54 const std::string& key() const { return key_; }
50 55
51 // Returns the value of the setting. 56 // Returns the value of the setting. Cannot be called if PassValue() has been
52 const base::Value& value() const; 57 // called.
not at google - send to devlin 2015/05/19 19:43:57 this does.
58 const base::Value& value() const { return *value_; }
59
60 // Releases ownership of the value to the caller.
not at google - send to devlin 2015/05/19 19:43:58 I should improve this comment because it's importa
61 scoped_ptr<base::Value> PassValue();
53 62
54 private: 63 private:
55 // Ref-counted container for the data. 64 // Populates the extension ID, key, and value from |sync_data|. This will be
56 // TODO(kalman): Use browser_sync::Immutable<Internal>. 65 // either an extension or app settings data type.
57 class Internal : public base::RefCountedThreadSafe<Internal> { 66 void Init(const syncer::SyncData& sync_data);
58 public:
59 Internal(
60 syncer::SyncChange::SyncChangeType change_type,
61 const std::string& extension_id,
62 const std::string& key,
63 scoped_ptr<base::Value> value);
64 67
65 syncer::SyncChange::SyncChangeType change_type_; 68 syncer::SyncChange::SyncChangeType change_type_;
66 std::string extension_id_; 69 std::string extension_id_;
67 std::string key_; 70 std::string key_;
68 scoped_ptr<base::Value> value_; 71 scoped_ptr<base::Value> value_;
69 72
70 private: 73 DISALLOW_COPY_AND_ASSIGN(SettingSyncData);
Devlin 2015/05/15 23:58:18 Woo!
71 friend class base::RefCountedThreadSafe<Internal>;
72 ~Internal();
73 };
74
75 // Initializes internal_ from sync data for an extension or app setting.
76 void Init(syncer::SyncChange::SyncChangeType change_type,
77 const syncer::SyncData& sync_data);
78
79 // Initializes internal_ from extension specifics.
80 void InitFromExtensionSettingSpecifics(
81 syncer::SyncChange::SyncChangeType change_type,
82 const sync_pb::ExtensionSettingSpecifics& specifics);
83
84 scoped_refptr<Internal> internal_;
85 }; 74 };
86 75
87 typedef std::vector<SettingSyncData> SettingSyncDataList; 76 typedef ScopedVector<SettingSyncData> SettingSyncDataList;
88 77
89 } // namespace extensions 78 } // namespace extensions
90 79
91 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTING_SYNC_DATA_H_ 80 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTING_SYNC_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698