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

Side by Side Diff: chromeos/cryptohome/system_salt_getter.cc

Issue 2220433002: ChromeOS: fix crash in HashWallpaperFilesIdStr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: AddOnSystemSaltReady() should immediately run callback if system salt is ready. Created 4 years, 4 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
« no previous file with comments | « chromeos/cryptohome/system_salt_getter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chromeos/cryptohome/system_salt_getter.h" 5 #include "chromeos/cryptohome/system_salt_getter.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 24 matching lines...) Expand all
35 FROM_HERE, base::Bind(callback, system_salt_)); 35 FROM_HERE, base::Bind(callback, system_salt_));
36 return; 36 return;
37 } 37 }
38 38
39 DBusThreadManager::Get()->GetCryptohomeClient()->WaitForServiceToBeAvailable( 39 DBusThreadManager::Get()->GetCryptohomeClient()->WaitForServiceToBeAvailable(
40 base::Bind(&SystemSaltGetter::DidWaitForServiceToBeAvailable, 40 base::Bind(&SystemSaltGetter::DidWaitForServiceToBeAvailable,
41 weak_ptr_factory_.GetWeakPtr(), 41 weak_ptr_factory_.GetWeakPtr(),
42 callback)); 42 callback));
43 } 43 }
44 44
45 void SystemSaltGetter::AddOnSystemSaltReady(const base::Closure& closure) {
46 if (!raw_salt_.empty()) {
47 closure.Run();
48 return;
49 }
50
51 on_system_salt_ready_.push_back(closure);
52 }
53
45 const SystemSaltGetter::RawSalt* SystemSaltGetter::GetRawSalt() const { 54 const SystemSaltGetter::RawSalt* SystemSaltGetter::GetRawSalt() const {
46 return raw_salt_.empty() ? nullptr : &raw_salt_; 55 return raw_salt_.empty() ? nullptr : &raw_salt_;
47 } 56 }
48 57
49 void SystemSaltGetter::SetRawSaltForTesting( 58 void SystemSaltGetter::SetRawSaltForTesting(
50 const SystemSaltGetter::RawSalt& raw_salt) { 59 const SystemSaltGetter::RawSalt& raw_salt) {
51 raw_salt_ = raw_salt; 60 raw_salt_ = raw_salt;
52 } 61 }
53 62
54 void SystemSaltGetter::DidWaitForServiceToBeAvailable( 63 void SystemSaltGetter::DidWaitForServiceToBeAvailable(
(...skipping 12 matching lines...) Expand all
67 76
68 void SystemSaltGetter::DidGetSystemSalt( 77 void SystemSaltGetter::DidGetSystemSalt(
69 const GetSystemSaltCallback& callback, 78 const GetSystemSaltCallback& callback,
70 DBusMethodCallStatus call_status, 79 DBusMethodCallStatus call_status,
71 const std::vector<uint8_t>& system_salt) { 80 const std::vector<uint8_t>& system_salt) {
72 if (call_status == DBUS_METHOD_CALL_SUCCESS && 81 if (call_status == DBUS_METHOD_CALL_SUCCESS &&
73 !system_salt.empty() && 82 !system_salt.empty() &&
74 system_salt.size() % 2 == 0U) { 83 system_salt.size() % 2 == 0U) {
75 raw_salt_ = system_salt; 84 raw_salt_ = system_salt;
76 system_salt_ = ConvertRawSaltToHexString(system_salt); 85 system_salt_ = ConvertRawSaltToHexString(system_salt);
86
87 std::vector<base::Closure> callbacks;
88 callbacks.swap(on_system_salt_ready_);
89 for (const base::Closure& callback : callbacks) {
90 callback.Run();
91 }
77 } else { 92 } else {
78 LOG(WARNING) << "System salt not available"; 93 LOG(WARNING) << "System salt not available";
79 } 94 }
80 95
81 callback.Run(system_salt_); 96 callback.Run(system_salt_);
82 } 97 }
83 98
84 // static 99 // static
85 void SystemSaltGetter::Initialize() { 100 void SystemSaltGetter::Initialize() {
86 CHECK(!g_system_salt_getter); 101 CHECK(!g_system_salt_getter);
(...skipping 20 matching lines...) Expand all
107 } 122 }
108 123
109 // static 124 // static
110 std::string SystemSaltGetter::ConvertRawSaltToHexString( 125 std::string SystemSaltGetter::ConvertRawSaltToHexString(
111 const std::vector<uint8_t>& salt) { 126 const std::vector<uint8_t>& salt) {
112 return base::ToLowerASCII( 127 return base::ToLowerASCII(
113 base::HexEncode(reinterpret_cast<const void*>(salt.data()), salt.size())); 128 base::HexEncode(reinterpret_cast<const void*>(salt.data()), salt.size()));
114 } 129 }
115 130
116 } // namespace chromeos 131 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/cryptohome/system_salt_getter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698