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

Side by Side Diff: components/user_prefs/tracked/pref_hash_store_impl.cc

Issue 1908143002: Convert //components/user_prefs from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore the rightful glory of <windows.h> Created 4 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "components/user_prefs/tracked/pref_hash_store_impl.h" 5 #include "components/user_prefs/tracked/pref_hash_store_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "components/user_prefs/tracked/hash_store_contents.h" 14 #include "components/user_prefs/tracked/hash_store_contents.h"
15 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" 15 #include "components/user_prefs/tracked/pref_hash_store_transaction.h"
16 16
17 class PrefHashStoreImpl::PrefHashStoreTransactionImpl 17 class PrefHashStoreImpl::PrefHashStoreTransactionImpl
18 : public PrefHashStoreTransaction { 18 : public PrefHashStoreTransaction {
19 public: 19 public:
20 // Constructs a PrefHashStoreTransactionImpl which can use the private 20 // Constructs a PrefHashStoreTransactionImpl which can use the private
21 // members of its |outer| PrefHashStoreImpl. 21 // members of its |outer| PrefHashStoreImpl.
22 PrefHashStoreTransactionImpl(PrefHashStoreImpl* outer, 22 PrefHashStoreTransactionImpl(PrefHashStoreImpl* outer,
23 scoped_ptr<HashStoreContents> storage); 23 std::unique_ptr<HashStoreContents> storage);
24 ~PrefHashStoreTransactionImpl() override; 24 ~PrefHashStoreTransactionImpl() override;
25 25
26 // PrefHashStoreTransaction implementation. 26 // PrefHashStoreTransaction implementation.
27 ValueState CheckValue(const std::string& path, 27 ValueState CheckValue(const std::string& path,
28 const base::Value* value) const override; 28 const base::Value* value) const override;
29 void StoreHash(const std::string& path, const base::Value* value) override; 29 void StoreHash(const std::string& path, const base::Value* value) override;
30 ValueState CheckSplitValue( 30 ValueState CheckSplitValue(
31 const std::string& path, 31 const std::string& path,
32 const base::DictionaryValue* initial_split_value, 32 const base::DictionaryValue* initial_split_value,
33 std::vector<std::string>* invalid_keys) const override; 33 std::vector<std::string>* invalid_keys) const override;
(...skipping 15 matching lines...) Expand all
49 : contents_.get(); 49 : contents_.get();
50 } 50 }
51 51
52 const HashStoreContents* contents() const { 52 const HashStoreContents* contents() const {
53 return outer_->legacy_hash_store_contents_ 53 return outer_->legacy_hash_store_contents_
54 ? outer_->legacy_hash_store_contents_.get() 54 ? outer_->legacy_hash_store_contents_.get()
55 : contents_.get(); 55 : contents_.get();
56 } 56 }
57 57
58 PrefHashStoreImpl* outer_; 58 PrefHashStoreImpl* outer_;
59 scoped_ptr<HashStoreContents> contents_; 59 std::unique_ptr<HashStoreContents> contents_;
60 60
61 bool super_mac_valid_; 61 bool super_mac_valid_;
62 bool super_mac_dirty_; 62 bool super_mac_dirty_;
63 63
64 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreTransactionImpl); 64 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreTransactionImpl);
65 }; 65 };
66 66
67 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& seed, 67 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& seed,
68 const std::string& device_id, 68 const std::string& device_id,
69 bool use_super_mac) 69 bool use_super_mac)
70 : pref_hash_calculator_(seed, device_id), use_super_mac_(use_super_mac) { 70 : pref_hash_calculator_(seed, device_id), use_super_mac_(use_super_mac) {
71 } 71 }
72 72
73 PrefHashStoreImpl::~PrefHashStoreImpl() { 73 PrefHashStoreImpl::~PrefHashStoreImpl() {
74 } 74 }
75 75
76 void PrefHashStoreImpl::set_legacy_hash_store_contents( 76 void PrefHashStoreImpl::set_legacy_hash_store_contents(
77 scoped_ptr<HashStoreContents> legacy_hash_store_contents) { 77 std::unique_ptr<HashStoreContents> legacy_hash_store_contents) {
78 legacy_hash_store_contents_ = std::move(legacy_hash_store_contents); 78 legacy_hash_store_contents_ = std::move(legacy_hash_store_contents);
79 } 79 }
80 80
81 scoped_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction( 81 std::unique_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction(
82 scoped_ptr<HashStoreContents> storage) { 82 std::unique_ptr<HashStoreContents> storage) {
83 return scoped_ptr<PrefHashStoreTransaction>( 83 return std::unique_ptr<PrefHashStoreTransaction>(
84 new PrefHashStoreTransactionImpl(this, std::move(storage))); 84 new PrefHashStoreTransactionImpl(this, std::move(storage)));
85 } 85 }
86 86
87 PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl( 87 PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl(
88 PrefHashStoreImpl* outer, 88 PrefHashStoreImpl* outer,
89 scoped_ptr<HashStoreContents> storage) 89 std::unique_ptr<HashStoreContents> storage)
90 : outer_(outer), 90 : outer_(outer),
91 contents_(std::move(storage)), 91 contents_(std::move(storage)),
92 super_mac_valid_(false), 92 super_mac_valid_(false),
93 super_mac_dirty_(false) { 93 super_mac_dirty_(false) {
94 if (!outer_->use_super_mac_) 94 if (!outer_->use_super_mac_)
95 return; 95 return;
96 96
97 // The store must be initialized and have a valid super MAC to be trusted. 97 // The store must be initialized and have a valid super MAC to be trusted.
98 98
99 const base::DictionaryValue* store_contents = contents()->GetContents(); 99 const base::DictionaryValue* store_contents = contents()->GetContents();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 225 }
226 226
227 return invalid_keys->empty() 227 return invalid_keys->empty()
228 ? (has_secure_legacy_id_hashes ? SECURE_LEGACY : UNCHANGED) 228 ? (has_secure_legacy_id_hashes ? SECURE_LEGACY : UNCHANGED)
229 : CHANGED; 229 : CHANGED;
230 } 230 }
231 231
232 void PrefHashStoreImpl::PrefHashStoreTransactionImpl::StoreSplitHash( 232 void PrefHashStoreImpl::PrefHashStoreTransactionImpl::StoreSplitHash(
233 const std::string& path, 233 const std::string& path,
234 const base::DictionaryValue* split_value) { 234 const base::DictionaryValue* split_value) {
235 scoped_ptr<HashStoreContents::MutableDictionary> mutable_dictionary = 235 std::unique_ptr<HashStoreContents::MutableDictionary> mutable_dictionary =
236 contents()->GetMutableContents(); 236 contents()->GetMutableContents();
237 (*mutable_dictionary)->Remove(path, NULL); 237 (*mutable_dictionary)->Remove(path, NULL);
238 238
239 if (split_value) { 239 if (split_value) {
240 std::string keyed_path(path); 240 std::string keyed_path(path);
241 keyed_path.push_back('.'); 241 keyed_path.push_back('.');
242 const size_t common_part_length = keyed_path.length(); 242 const size_t common_part_length = keyed_path.length();
243 for (base::DictionaryValue::Iterator it(*split_value); !it.IsAtEnd(); 243 for (base::DictionaryValue::Iterator it(*split_value); !it.IsAtEnd();
244 it.Advance()) { 244 it.Advance()) {
245 // Keep the common part from the old |keyed_path| and replace the key to 245 // Keep the common part from the old |keyed_path| and replace the key to
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::IsSuperMACValid() const { 303 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::IsSuperMACValid() const {
304 return super_mac_valid_; 304 return super_mac_valid_;
305 } 305 }
306 306
307 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::StampSuperMac() { 307 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::StampSuperMac() {
308 if (!outer_->use_super_mac_ || super_mac_valid_) 308 if (!outer_->use_super_mac_ || super_mac_valid_)
309 return false; 309 return false;
310 super_mac_dirty_ = true; 310 super_mac_dirty_ = true;
311 return true; 311 return true;
312 } 312 }
OLDNEW
« no previous file with comments | « components/user_prefs/tracked/pref_hash_store_impl.h ('k') | components/user_prefs/tracked/pref_hash_store_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698