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

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: comments 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/storage/setting_sync_data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // May return ACTION_INVALID if this object represents sync data that isn't
43 syncer::SyncChange::SyncChangeType change_type() const; 46 // associated with a sync operation.
47 syncer::SyncChange::SyncChangeType change_type() const {
48 return change_type_;
49 }
50 const std::string& extension_id() const { return extension_id_; }
51 const std::string& key() const { return key_; }
52 // value() cannot be called if PassValue() has been called.
53 const base::Value& value() const { return *value_; }
44 54
45 // Returns the extension id the setting is for. 55 // Releases ownership of the value to the caller. Neither value() nor
46 const std::string& extension_id() const; 56 // PassValue() can be after this.
47 57 scoped_ptr<base::Value> PassValue();
48 // Returns the settings key.
49 const std::string& key() const;
50
51 // Returns the value of the setting.
52 const base::Value& value() const;
53 58
54 private: 59 private:
55 // Ref-counted container for the data. 60 // Populates the extension ID, key, and value from |sync_data|. This will be
56 // TODO(kalman): Use browser_sync::Immutable<Internal>. 61 // either an extension or app settings data type.
57 class Internal : public base::RefCountedThreadSafe<Internal> { 62 void ExtractSyncData(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 63
65 syncer::SyncChange::SyncChangeType change_type_; 64 syncer::SyncChange::SyncChangeType change_type_;
66 std::string extension_id_; 65 std::string extension_id_;
67 std::string key_; 66 std::string key_;
68 scoped_ptr<base::Value> value_; 67 scoped_ptr<base::Value> value_;
69 68
70 private: 69 DISALLOW_COPY_AND_ASSIGN(SettingSyncData);
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 }; 70 };
86 71
87 typedef std::vector<SettingSyncData> SettingSyncDataList; 72 typedef ScopedVector<SettingSyncData> SettingSyncDataList;
88 73
89 } // namespace extensions 74 } // namespace extensions
90 75
91 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTING_SYNC_DATA_H_ 76 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTING_SYNC_DATA_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/storage/setting_sync_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698