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

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

Issue 34303002: chromeos: Wait for service to be available when getting system salt (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comment Created 7 years, 2 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 | Annotate | Revision Log
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "chromeos/dbus/cryptohome_client.h" 12 #include "chromeos/dbus/cryptohome_client.h"
13 #include "chromeos/dbus/dbus_thread_manager.h" 13 #include "chromeos/dbus/dbus_thread_manager.h"
14 14
15 namespace chromeos { 15 namespace chromeos {
16 namespace { 16 namespace {
17 17
18 SystemSaltGetter* g_system_salt_getter = NULL; 18 SystemSaltGetter* g_system_salt_getter = NULL;
19 19
20 } // namespace 20 } // namespace
21 21
22 SystemSaltGetter::SystemSaltGetter() { 22 SystemSaltGetter::SystemSaltGetter() : weak_ptr_factory_(this) {
23 } 23 }
24 24
25 SystemSaltGetter::~SystemSaltGetter() { 25 SystemSaltGetter::~SystemSaltGetter() {
26 } 26 }
27 27
28 void SystemSaltGetter::GetSystemSalt( 28 void SystemSaltGetter::GetSystemSalt(
29 const GetSystemSaltCallback& callback) { 29 const GetSystemSaltCallback& callback) {
30 // TODO(hashimoto): Stop using GetSystemSaltSynt(). crbug.com/141009 30 DBusThreadManager::Get()->GetCryptohomeClient()->WaitForServiceToBeAvailable(
31 base::MessageLoopProxy::current()->PostTask( 31 base::Bind(&SystemSaltGetter::GetSystemSaltInternal,
32 FROM_HERE, base::Bind(callback, GetSystemSaltSync())); 32 weak_ptr_factory_.GetWeakPtr(),
33 callback));
33 } 34 }
34 35
35 std::string SystemSaltGetter::GetSystemSaltSync() { 36 std::string SystemSaltGetter::GetSystemSaltSync() {
36 LoadSystemSalt(); // no-op if it's already loaded. 37 LoadSystemSalt(); // no-op if it's already loaded.
37 return system_salt_; 38 return system_salt_;
38 } 39 }
39 40
40 std::string SystemSaltGetter::GetCachedSystemSalt() { 41 std::string SystemSaltGetter::GetCachedSystemSalt() {
41 return system_salt_; 42 return system_salt_;
42 } 43 }
43 44
45 void SystemSaltGetter::GetSystemSaltInternal(
46 const GetSystemSaltCallback& callback,
47 bool service_is_available) {
48 LOG_IF(ERROR, !service_is_available) << "WaitForServiceToBeAvailable failed.";
49 // TODO(hashimoto): Stop using GetSystemSaltSync(). crbug.com/141009
50 callback.Run(GetSystemSaltSync());
51 }
52
44 void SystemSaltGetter::LoadSystemSalt() { 53 void SystemSaltGetter::LoadSystemSalt() {
45 if (!system_salt_.empty()) 54 if (!system_salt_.empty())
46 return; 55 return;
47 std::vector<uint8> salt; 56 std::vector<uint8> salt;
48 DBusThreadManager::Get()->GetCryptohomeClient()->GetSystemSalt(&salt); 57 DBusThreadManager::Get()->GetCryptohomeClient()->GetSystemSalt(&salt);
49 if (salt.empty() || salt.size() % 2 != 0U) { 58 if (salt.empty() || salt.size() % 2 != 0U) {
50 LOG(WARNING) << "System salt not available"; 59 LOG(WARNING) << "System salt not available";
51 return; 60 return;
52 } 61 }
53 system_salt_ = ConvertRawSaltToHexString(salt); 62 system_salt_ = ConvertRawSaltToHexString(salt);
(...skipping 25 matching lines...) Expand all
79 } 88 }
80 89
81 // static 90 // static
82 std::string SystemSaltGetter::ConvertRawSaltToHexString( 91 std::string SystemSaltGetter::ConvertRawSaltToHexString(
83 const std::vector<uint8>& salt) { 92 const std::vector<uint8>& salt) {
84 return StringToLowerASCII(base::HexEncode( 93 return StringToLowerASCII(base::HexEncode(
85 reinterpret_cast<const void*>(salt.data()), salt.size())); 94 reinterpret_cast<const void*>(salt.data()), salt.size()));
86 } 95 }
87 96
88 } // namespace chromeos 97 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/cryptohome/system_salt_getter.h ('k') | chromeos/cryptohome/system_salt_getter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698