Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "components/user_prefs/tracked/device_id.h" | |
| 13 #include "components/user_prefs/tracked/hash_store_contents.h" | 14 #include "components/user_prefs/tracked/hash_store_contents.h" |
| 14 | 15 |
| 16 namespace { | |
| 17 | |
| 18 // Returns a deterministic ID for this machine. | |
| 19 std::string GenerateDeviceId() { | |
|
proberge
2017/01/18 16:10:58
Possible optimization:
This method is called up t
gab
2017/01/19 18:52:05
Ah yes, that's a great idea let's do it. A static
proberge
2017/01/19 20:42:59
Done.
| |
| 20 std::string device_id; | |
| 21 if (GetDeterministicMachineSpecificId(&device_id) == MachineIdStatus::SUCCESS) | |
|
proberge
2017/01/18 16:10:58
One thing I worry about is the stability of this m
gab
2017/01/19 18:52:05
It better be 100% deterministic and non-flaky. I'm
proberge
2017/01/19 20:42:59
Done.
| |
| 22 return device_id; | |
| 23 | |
| 24 return std::string(); | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 15 class PrefHashStoreImpl::PrefHashStoreTransactionImpl | 29 class PrefHashStoreImpl::PrefHashStoreTransactionImpl |
| 16 : public PrefHashStoreTransaction { | 30 : public PrefHashStoreTransaction { |
| 17 public: | 31 public: |
| 18 // Constructs a PrefHashStoreTransactionImpl which can use the private | 32 // Constructs a PrefHashStoreTransactionImpl which can use the private |
| 19 // members of its |outer| PrefHashStoreImpl. | 33 // members of its |outer| PrefHashStoreImpl. |
| 20 PrefHashStoreTransactionImpl(PrefHashStoreImpl* outer, | 34 PrefHashStoreTransactionImpl(PrefHashStoreImpl* outer, |
| 21 HashStoreContents* storage); | 35 HashStoreContents* storage); |
| 22 ~PrefHashStoreTransactionImpl() override; | 36 ~PrefHashStoreTransactionImpl() override; |
| 23 | 37 |
| 24 // PrefHashStoreTransaction implementation. | 38 // PrefHashStoreTransaction implementation. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 42 PrefHashStoreImpl* outer_; | 56 PrefHashStoreImpl* outer_; |
| 43 HashStoreContents* contents_; | 57 HashStoreContents* contents_; |
| 44 | 58 |
| 45 bool super_mac_valid_; | 59 bool super_mac_valid_; |
| 46 bool super_mac_dirty_; | 60 bool super_mac_dirty_; |
| 47 | 61 |
| 48 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreTransactionImpl); | 62 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreTransactionImpl); |
| 49 }; | 63 }; |
| 50 | 64 |
| 51 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& seed, | 65 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& seed, |
| 52 const std::string& device_id, | 66 const std::string& legacy_device_id, |
| 53 bool use_super_mac) | 67 bool use_super_mac) |
| 54 : pref_hash_calculator_(seed, device_id), use_super_mac_(use_super_mac) { | 68 : pref_hash_calculator_(seed, GenerateDeviceId(), legacy_device_id), |
| 55 } | 69 use_super_mac_(use_super_mac) {} |
| 56 | 70 |
| 57 PrefHashStoreImpl::~PrefHashStoreImpl() { | 71 PrefHashStoreImpl::~PrefHashStoreImpl() { |
| 58 } | 72 } |
| 59 | 73 |
| 60 std::unique_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction( | 74 std::unique_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction( |
| 61 HashStoreContents* storage) { | 75 HashStoreContents* storage) { |
| 62 return std::unique_ptr<PrefHashStoreTransaction>( | 76 return std::unique_ptr<PrefHashStoreTransaction>( |
| 63 new PrefHashStoreTransactionImpl(this, std::move(storage))); | 77 new PrefHashStoreTransactionImpl(this, std::move(storage))); |
| 64 } | 78 } |
| 65 | 79 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::IsSuperMACValid() const { | 296 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::IsSuperMACValid() const { |
| 283 return super_mac_valid_; | 297 return super_mac_valid_; |
| 284 } | 298 } |
| 285 | 299 |
| 286 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::StampSuperMac() { | 300 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::StampSuperMac() { |
| 287 if (!outer_->use_super_mac_ || super_mac_valid_) | 301 if (!outer_->use_super_mac_ || super_mac_valid_) |
| 288 return false; | 302 return false; |
| 289 super_mac_dirty_ = true; | 303 super_mac_dirty_ = true; |
| 290 return true; | 304 return true; |
| 291 } | 305 } |
| OLD | NEW |