| 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_macros.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() { |
| 20 static std::string cached_device_id; |
| 21 if (!cached_device_id.empty()) |
| 22 return cached_device_id; |
| 23 |
| 24 std::string device_id; |
| 25 MachineIdStatus status = GetDeterministicMachineSpecificId(&device_id); |
| 26 if (status != MachineIdStatus::NOT_IMPLEMENTED) { |
| 27 // TODO(proberge): Remove this histogram once we validate that machine id |
| 28 // generation is not flaky and consider adding a CHECK or DCHECK. |
| 29 UMA_HISTOGRAM_BOOLEAN("Settings.MachineIdGenerationSuccess", |
| 30 status == MachineIdStatus::SUCCESS); |
| 31 } |
| 32 |
| 33 if (status == MachineIdStatus::SUCCESS) { |
| 34 cached_device_id = device_id; |
| 35 return device_id; |
| 36 } |
| 37 |
| 38 return std::string(); |
| 39 } |
| 40 |
| 41 } // namespace |
| 42 |
| 15 class PrefHashStoreImpl::PrefHashStoreTransactionImpl | 43 class PrefHashStoreImpl::PrefHashStoreTransactionImpl |
| 16 : public PrefHashStoreTransaction { | 44 : public PrefHashStoreTransaction { |
| 17 public: | 45 public: |
| 18 // Constructs a PrefHashStoreTransactionImpl which can use the private | 46 // Constructs a PrefHashStoreTransactionImpl which can use the private |
| 19 // members of its |outer| PrefHashStoreImpl. | 47 // members of its |outer| PrefHashStoreImpl. |
| 20 PrefHashStoreTransactionImpl(PrefHashStoreImpl* outer, | 48 PrefHashStoreTransactionImpl(PrefHashStoreImpl* outer, |
| 21 HashStoreContents* storage); | 49 HashStoreContents* storage); |
| 22 ~PrefHashStoreTransactionImpl() override; | 50 ~PrefHashStoreTransactionImpl() override; |
| 23 | 51 |
| 24 // PrefHashStoreTransaction implementation. | 52 // PrefHashStoreTransaction implementation. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 42 PrefHashStoreImpl* outer_; | 70 PrefHashStoreImpl* outer_; |
| 43 HashStoreContents* contents_; | 71 HashStoreContents* contents_; |
| 44 | 72 |
| 45 bool super_mac_valid_; | 73 bool super_mac_valid_; |
| 46 bool super_mac_dirty_; | 74 bool super_mac_dirty_; |
| 47 | 75 |
| 48 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreTransactionImpl); | 76 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreTransactionImpl); |
| 49 }; | 77 }; |
| 50 | 78 |
| 51 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& seed, | 79 PrefHashStoreImpl::PrefHashStoreImpl(const std::string& seed, |
| 52 const std::string& device_id, | 80 const std::string& legacy_device_id, |
| 53 bool use_super_mac) | 81 bool use_super_mac) |
| 54 : pref_hash_calculator_(seed, device_id), use_super_mac_(use_super_mac) { | 82 : pref_hash_calculator_(seed, GenerateDeviceId(), legacy_device_id), |
| 55 } | 83 use_super_mac_(use_super_mac) {} |
| 56 | 84 |
| 57 PrefHashStoreImpl::~PrefHashStoreImpl() { | 85 PrefHashStoreImpl::~PrefHashStoreImpl() { |
| 58 } | 86 } |
| 59 | 87 |
| 60 std::unique_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction( | 88 std::unique_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction( |
| 61 HashStoreContents* storage) { | 89 HashStoreContents* storage) { |
| 62 return std::unique_ptr<PrefHashStoreTransaction>( | 90 return std::unique_ptr<PrefHashStoreTransaction>( |
| 63 new PrefHashStoreTransactionImpl(this, std::move(storage))); | 91 new PrefHashStoreTransactionImpl(this, std::move(storage))); |
| 64 } | 92 } |
| 65 | 93 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::IsSuperMACValid() const { | 310 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::IsSuperMACValid() const { |
| 283 return super_mac_valid_; | 311 return super_mac_valid_; |
| 284 } | 312 } |
| 285 | 313 |
| 286 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::StampSuperMac() { | 314 bool PrefHashStoreImpl::PrefHashStoreTransactionImpl::StampSuperMac() { |
| 287 if (!outer_->use_super_mac_ || super_mac_valid_) | 315 if (!outer_->use_super_mac_ || super_mac_valid_) |
| 288 return false; | 316 return false; |
| 289 super_mac_dirty_ = true; | 317 super_mac_dirty_ = true; |
| 290 return true; | 318 return true; |
| 291 } | 319 } |
| OLD | NEW |