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

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

Issue 2297373002: Refactor PrefHashStore's BeginTransaction to take a rawptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments on #1 Created 4 years, 3 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 std::unique_ptr<HashStoreContents> storage); 23 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;
34 void StoreSplitHash(const std::string& path, 34 void StoreSplitHash(const std::string& path,
35 const base::DictionaryValue* split_value) override; 35 const base::DictionaryValue* split_value) override;
36 bool HasHash(const std::string& path) const override; 36 bool HasHash(const std::string& path) const override;
37 void ImportHash(const std::string& path, const base::Value* hash) override; 37 void ImportHash(const std::string& path, const base::Value* hash) override;
38 void ClearHash(const std::string& path) override; 38 void ClearHash(const std::string& path) override;
39 bool IsSuperMACValid() const override; 39 bool IsSuperMACValid() const override;
40 bool StampSuperMac() override; 40 bool StampSuperMac() override;
41 41
42 private: 42 private:
43 PrefHashStoreImpl* outer_; 43 PrefHashStoreImpl* outer_;
44 std::unique_ptr<HashStoreContents> contents_; 44 HashStoreContents* contents_;
45 45
46 bool super_mac_valid_; 46 bool super_mac_valid_;
47 bool super_mac_dirty_; 47 bool super_mac_dirty_;
48 48
49 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreTransactionImpl); 49 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreTransactionImpl);
50 }; 50 };
51 51
52 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& seed, 52 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& seed,
53 const std::string& device_id, 53 const std::string& device_id,
54 bool use_super_mac) 54 bool use_super_mac)
55 : pref_hash_calculator_(seed, device_id), use_super_mac_(use_super_mac) { 55 : pref_hash_calculator_(seed, device_id), use_super_mac_(use_super_mac) {
56 } 56 }
57 57
58 PrefHashStoreImpl::~PrefHashStoreImpl() { 58 PrefHashStoreImpl::~PrefHashStoreImpl() {
59 } 59 }
60 60
61 std::unique_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction( 61 std::unique_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction(
62 std::unique_ptr<HashStoreContents> storage) { 62 HashStoreContents* storage) {
63 return std::unique_ptr<PrefHashStoreTransaction>( 63 return std::unique_ptr<PrefHashStoreTransaction>(
64 new PrefHashStoreTransactionImpl(this, std::move(storage))); 64 new PrefHashStoreTransactionImpl(this, std::move(storage)));
65 } 65 }
66 66
67 PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl( 67 PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl(
68 PrefHashStoreImpl* outer, 68 PrefHashStoreImpl* outer,
69 std::unique_ptr<HashStoreContents> storage) 69 HashStoreContents* storage)
70 : outer_(outer), 70 : outer_(outer),
71 contents_(std::move(storage)), 71 contents_(std::move(storage)),
72 super_mac_valid_(false), 72 super_mac_valid_(false),
73 super_mac_dirty_(false) { 73 super_mac_dirty_(false) {
74 if (!outer_->use_super_mac_) 74 if (!outer_->use_super_mac_)
75 return; 75 return;
76 76
77 // The store must have a valid super MAC to be trusted. 77 // The store must have a valid super MAC to be trusted.
78 std::string super_mac = contents_->GetSuperMac(); 78 std::string super_mac = contents_->GetSuperMac();
79 if (super_mac.empty()) 79 if (super_mac.empty())
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::IsSuperMACValid() const { 252 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::IsSuperMACValid() const {
253 return super_mac_valid_; 253 return super_mac_valid_;
254 } 254 }
255 255
256 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::StampSuperMac() { 256 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::StampSuperMac() {
257 if (!outer_->use_super_mac_ || super_mac_valid_) 257 if (!outer_->use_super_mac_ || super_mac_valid_)
258 return false; 258 return false;
259 super_mac_dirty_ = true; 259 super_mac_dirty_ = true;
260 return true; 260 return true;
261 } 261 }
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