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

Side by Side 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 unified diff | Download patch
OLDNEW
(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/logging.h"
9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/common/pref_names.h"
13 #include "chromeos/dbus/cryptohome/rpc.pb.h"
14 #include "chromeos/dbus/cryptohome_client.h"
15
16 namespace policy {
17
18 const char* ConsumerManagementService::kDeviceOwner =
19 "consumer_management.owner";
20
21 // static
22 void ConsumerManagementService::RegisterPrefs(PrefRegistrySimple* registry) {
23 registry->RegisterIntegerPref(
24 prefs::kConsumerManagementEnrollState, ENROLL_NONE);
25 }
26
27 ConsumerManagementService::ConsumerManagementService(
28 chromeos::CryptohomeClient* client) : client_(client),
29 weak_ptr_factory_(this) {
30 }
31
32 ConsumerManagementService::EnrollState
33 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.
34 PrefService* prefs = g_browser_process->local_state();
35 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.
36 prefs::kConsumerManagementEnrollState));
37 }
38
39 void ConsumerManagementService::SetEnrollState(EnrollState state) {
40 PrefService* prefs = g_browser_process->local_state();
41 prefs->SetInteger(prefs::kConsumerManagementEnrollState, state);
42 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"
43 }
44
45 void ConsumerManagementService::GetOwner(
46 const base::Callback<void(const std::string&)>& callback) {
47 cryptohome::GetBootAttributeRequest request;
48 request.set_name(kDeviceOwner);
49 client_->GetBootAttribute(
50 request,
51 base::Bind(&ConsumerManagementService::OnGetBootAttributeDone,
52 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.
53 }
54
55 void ConsumerManagementService::OnGetBootAttributeDone(
56 const base::Callback<void(const std::string&)>& callback,
57 chromeos::DBusMethodCallStatus call_status,
58 bool result,
59 const cryptohome::BaseReply& reply) {
60 if (!result || reply.error() != 0) {
61 LOG(ERROR) << "Failed to get the owner info from boot lockbox.";
62 callback.Run("");
63 return;
64 }
65
66 callback.Run(
67 reply.GetExtension(cryptohome::GetBootAttributeReply::reply).value());
68 }
69
70 void ConsumerManagementService::SetOwner(
71 const std::string& email,
72 const base::Callback<void(bool)>& callback) {
73 cryptohome::SetBootAttributeRequest request;
74 request.set_name(kDeviceOwner);
75 request.set_value(email.data(), email.size());
76 client_->SetBootAttribute(
77 request,
78 base::Bind(&ConsumerManagementService::OnSetBootAttributeDone,
79 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.
80 }
81
82 void ConsumerManagementService::OnSetBootAttributeDone(
83 const base::Callback<void(bool)>& callback,
84 chromeos::DBusMethodCallStatus call_status,
85 bool result,
86 const cryptohome::BaseReply& reply) {
87 if (!result || reply.error() != 0) {
88 LOG(ERROR) << "Failed to set owner info in boot lockbox.";
89 callback.Run(false);
90 return;
91 }
92
93 cryptohome::FlushAndSignBootAttributesRequest request;
94 client_->FlushAndSignBootAttributes(
95 request,
96 base::Bind(&ConsumerManagementService::OnFlushAndSignBootAttributesDone,
97 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.
98 }
99
100 void ConsumerManagementService::OnFlushAndSignBootAttributesDone(
101 const base::Callback<void(bool)>& callback,
102 chromeos::DBusMethodCallStatus call_status,
103 bool result,
104 const cryptohome::BaseReply& reply) {
105 if (!result || reply.error() != 0) {
106 LOG(ERROR) << "Failed to flush and sign boot lockbox.";
107 callback.Run(false);
108 return;
109 }
110
111 callback.Run(true);
112 }
113
114 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698