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

Unified Diff: chrome/browser/chromeos/policy/consumer_management_service.cc

Issue 438493002: Added ConsumerManagementService class to handle enroll state and device owner info in boot lockbox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@signin
Patch Set: Call FlushAndSignBootAttributes() in SetOwner(). Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/consumer_management_service.cc
diff --git a/chrome/browser/chromeos/policy/consumer_management_service.cc b/chrome/browser/chromeos/policy/consumer_management_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..63c74bdbd2ce1605cafcec2856d99b5ace122f68
--- /dev/null
+++ b/chrome/browser/chromeos/policy/consumer_management_service.cc
@@ -0,0 +1,114 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/policy/consumer_management_service.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/prefs/pref_registry_simple.h"
+#include "base/prefs/pref_service.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/common/pref_names.h"
+#include "chromeos/dbus/cryptohome/rpc.pb.h"
+#include "chromeos/dbus/cryptohome_client.h"
+
+namespace policy {
+
+const char* ConsumerManagementService::kDeviceOwner =
+ "consumer_management.owner";
+
+// static
+void ConsumerManagementService::RegisterPrefs(PrefRegistrySimple* registry) {
+ registry->RegisterIntegerPref(
+ prefs::kConsumerManagementEnrollState, ENROLL_NONE);
+}
+
+ConsumerManagementService::ConsumerManagementService(
+ chromeos::CryptohomeClient* client) : client_(client),
+ weak_ptr_factory_(this) {
+}
+
+ConsumerManagementService::EnrollState
+ ConsumerManagementService::GetEnrollState() {
bartfab (slow) 2014/08/04 18:44:51 Nit: The style guide says that if you break betwee
davidyu 2014/08/05 07:26:58 Done.
+ PrefService* prefs = g_browser_process->local_state();
+ return static_cast<EnrollState>(prefs->GetInteger(
bartfab (slow) 2014/08/04 18:44:51 What if the pref value is outside the valid range?
davidyu 2014/08/05 07:26:58 Added error handling code.
+ prefs::kConsumerManagementEnrollState));
+}
+
+void ConsumerManagementService::SetEnrollState(EnrollState state) {
+ PrefService* prefs = g_browser_process->local_state();
+ prefs->SetInteger(prefs::kConsumerManagementEnrollState, state);
+ prefs->CommitPendingWrite();
bartfab (slow) 2014/08/04 18:44:51 Why? Prefs get auto-committed for you.
davidyu 2014/08/05 07:26:58 If we call PowerManagementClient::RequestRestart()
bartfab (slow) 2014/08/05 18:07:13 During a clean browser shutdown, pending writes ar
davidyu 2014/08/06 03:04:31 RequestRestart() eventually runs "shutdown -r now"
+}
+
+void ConsumerManagementService::GetOwner(
+ const base::Callback<void(const std::string&)>& callback) {
+ cryptohome::GetBootAttributeRequest request;
+ request.set_name(kDeviceOwner);
+ client_->GetBootAttribute(
+ request,
+ base::Bind(&ConsumerManagementService::OnGetBootAttributeDone,
+ weak_ptr_factory_.GetWeakPtr(), callback));
bartfab (slow) 2014/08/04 18:44:51 Nit: Put each argument on a separate line.
davidyu 2014/08/05 07:26:58 Done.
+}
+
+void ConsumerManagementService::OnGetBootAttributeDone(
+ const base::Callback<void(const std::string&)>& callback,
+ chromeos::DBusMethodCallStatus call_status,
+ bool result,
+ const cryptohome::BaseReply& reply) {
+ if (!result || reply.error() != 0) {
+ LOG(ERROR) << "Failed to get the owner info from boot lockbox.";
+ callback.Run("");
+ return;
+ }
+
+ callback.Run(
+ reply.GetExtension(cryptohome::GetBootAttributeReply::reply).value());
+}
+
+void ConsumerManagementService::SetOwner(
+ const std::string& email,
+ const base::Callback<void(bool)>& callback) {
+ cryptohome::SetBootAttributeRequest request;
+ request.set_name(kDeviceOwner);
+ request.set_value(email.data(), email.size());
+ client_->SetBootAttribute(
+ request,
+ base::Bind(&ConsumerManagementService::OnSetBootAttributeDone,
+ weak_ptr_factory_.GetWeakPtr(), callback));
bartfab (slow) 2014/08/04 18:44:51 Nit: Put each argument on a separate line.
davidyu 2014/08/05 07:26:58 Done.
+}
+
+void ConsumerManagementService::OnSetBootAttributeDone(
+ const base::Callback<void(bool)>& callback,
+ chromeos::DBusMethodCallStatus call_status,
+ bool result,
+ const cryptohome::BaseReply& reply) {
+ if (!result || reply.error() != 0) {
+ LOG(ERROR) << "Failed to set owner info in boot lockbox.";
+ callback.Run(false);
+ return;
+ }
+
+ cryptohome::FlushAndSignBootAttributesRequest request;
+ client_->FlushAndSignBootAttributes(
+ request,
+ base::Bind(&ConsumerManagementService::OnFlushAndSignBootAttributesDone,
+ weak_ptr_factory_.GetWeakPtr(), callback));
bartfab (slow) 2014/08/04 18:44:51 Nit: Put each argument on a separate line.
davidyu 2014/08/05 07:26:58 Done.
+}
+
+void ConsumerManagementService::OnFlushAndSignBootAttributesDone(
+ const base::Callback<void(bool)>& callback,
+ chromeos::DBusMethodCallStatus call_status,
+ bool result,
+ const cryptohome::BaseReply& reply) {
+ if (!result || reply.error() != 0) {
+ LOG(ERROR) << "Failed to flush and sign boot lockbox.";
+ callback.Run(false);
+ return;
+ }
+
+ callback.Run(true);
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698