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