Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/policy/consumer_management_service.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/callback.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/prefs/pref_registry_simple.h" | |
| 11 #include "base/prefs/pref_service.h" | |
| 12 #include "chrome/browser/browser_process.h" | |
| 13 #include "chrome/common/pref_names.h" | |
| 14 #include "chromeos/dbus/cryptohome/rpc.pb.h" | |
| 15 #include "chromeos/dbus/cryptohome_client.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 const char* kAttrOwnerId = "consumer_management.owner_id"; | |
|
bartfab (slow)
2014/08/05 18:07:13
Nit: Avoid abbreviations like "Attr."
davidyu
2014/08/06 03:04:31
Done.
| |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 namespace policy { | |
| 24 | |
| 25 ConsumerManagementService::ConsumerManagementService( | |
| 26 chromeos::CryptohomeClient* client) : client_(client), | |
| 27 weak_ptr_factory_(this) { | |
| 28 } | |
| 29 | |
| 30 // static | |
| 31 void ConsumerManagementService::RegisterPrefs(PrefRegistrySimple* registry) { | |
| 32 registry->RegisterIntegerPref( | |
| 33 prefs::kConsumerManagementEnrollmentState, ENROLLMENT_NONE); | |
| 34 } | |
| 35 | |
| 36 ConsumerManagementService::EnrollmentState | |
| 37 ConsumerManagementService::GetEnrollmentState() const { | |
| 38 const PrefService* prefs = g_browser_process->local_state(); | |
| 39 int state = prefs->GetInteger(prefs::kConsumerManagementEnrollmentState); | |
| 40 if (state < 0 || state >= ENROLLMENT_LAST) { | |
| 41 LOG(ERROR) << "Unknown enrollment state: " << state; | |
| 42 state = 0; | |
| 43 } | |
| 44 return static_cast<EnrollmentState>(state); | |
| 45 } | |
| 46 | |
| 47 void ConsumerManagementService::SetEnrollmentState(EnrollmentState state) { | |
| 48 PrefService* prefs = g_browser_process->local_state(); | |
| 49 prefs->SetInteger(prefs::kConsumerManagementEnrollmentState, state); | |
| 50 } | |
| 51 | |
| 52 void ConsumerManagementService::GetOwner(const GetOwnerCallback& callback) { | |
| 53 cryptohome::GetBootAttributeRequest request; | |
| 54 request.set_name(kAttrOwnerId); | |
| 55 client_->GetBootAttribute( | |
| 56 request, | |
| 57 base::Bind(&ConsumerManagementService::OnGetBootAttributeDone, | |
| 58 weak_ptr_factory_.GetWeakPtr(), | |
| 59 callback)); | |
| 60 } | |
| 61 | |
| 62 void ConsumerManagementService::OnGetBootAttributeDone( | |
| 63 const GetOwnerCallback& callback, | |
| 64 chromeos::DBusMethodCallStatus call_status, | |
| 65 bool dbus_success, | |
| 66 const cryptohome::BaseReply& reply) { | |
| 67 if (!dbus_success || reply.error() != 0) { | |
| 68 LOG(ERROR) << "Failed to get the owner info from boot lockbox."; | |
| 69 callback.Run(""); | |
| 70 return; | |
| 71 } | |
| 72 | |
| 73 callback.Run( | |
| 74 reply.GetExtension(cryptohome::GetBootAttributeReply::reply).value()); | |
| 75 } | |
| 76 | |
| 77 void ConsumerManagementService::SetOwner(const std::string& user_id, | |
| 78 const SetOwnerCallback& callback) { | |
| 79 cryptohome::SetBootAttributeRequest request; | |
| 80 request.set_name(kAttrOwnerId); | |
| 81 request.set_value(user_id.data(), user_id.size()); | |
| 82 client_->SetBootAttribute( | |
| 83 request, | |
| 84 base::Bind(&ConsumerManagementService::OnSetBootAttributeDone, | |
| 85 weak_ptr_factory_.GetWeakPtr(), | |
| 86 callback)); | |
| 87 } | |
| 88 | |
| 89 void ConsumerManagementService::OnSetBootAttributeDone( | |
| 90 const SetOwnerCallback& callback, | |
| 91 chromeos::DBusMethodCallStatus call_status, | |
| 92 bool dbus_success, | |
| 93 const cryptohome::BaseReply& reply) { | |
| 94 if (!dbus_success || reply.error() != 0) { | |
| 95 LOG(ERROR) << "Failed to set owner info in boot lockbox."; | |
| 96 callback.Run(false); | |
| 97 return; | |
| 98 } | |
| 99 | |
| 100 cryptohome::FlushAndSignBootAttributesRequest request; | |
| 101 client_->FlushAndSignBootAttributes( | |
| 102 request, | |
| 103 base::Bind(&ConsumerManagementService::OnFlushAndSignBootAttributesDone, | |
| 104 weak_ptr_factory_.GetWeakPtr(), | |
| 105 callback)); | |
| 106 } | |
| 107 | |
| 108 void ConsumerManagementService::OnFlushAndSignBootAttributesDone( | |
| 109 const SetOwnerCallback& callback, | |
| 110 chromeos::DBusMethodCallStatus call_status, | |
| 111 bool dbus_success, | |
| 112 const cryptohome::BaseReply& reply) { | |
| 113 if (!dbus_success || reply.error() != 0) { | |
| 114 LOG(ERROR) << "Failed to flush and sign boot lockbox."; | |
| 115 callback.Run(false); | |
| 116 return; | |
| 117 } | |
| 118 | |
| 119 callback.Run(true); | |
| 120 } | |
| 121 | |
| 122 } // namespace policy | |
| OLD | NEW |