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

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: Fixed the broken test. 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/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* kAttributeOwnerId = "consumer_management.owner_id";
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 ConsumerManagementService::~ConsumerManagementService() {
31 }
32
33 // static
34 void ConsumerManagementService::RegisterPrefs(PrefRegistrySimple* registry) {
35 registry->RegisterIntegerPref(
36 prefs::kConsumerManagementEnrollmentState, ENROLLMENT_NONE);
37 }
38
39 ConsumerManagementService::EnrollmentState
40 ConsumerManagementService::GetEnrollmentState() const {
41 const PrefService* prefs = g_browser_process->local_state();
42 int state = prefs->GetInteger(prefs::kConsumerManagementEnrollmentState);
43 if (state < 0 || state >= ENROLLMENT_LAST) {
44 LOG(ERROR) << "Unknown enrollment state: " << state;
45 state = 0;
46 }
47 return static_cast<EnrollmentState>(state);
48 }
49
50 void ConsumerManagementService::SetEnrollmentState(EnrollmentState state) {
51 PrefService* prefs = g_browser_process->local_state();
52 prefs->SetInteger(prefs::kConsumerManagementEnrollmentState, state);
53 }
54
55 void ConsumerManagementService::GetOwner(const GetOwnerCallback& callback) {
56 cryptohome::GetBootAttributeRequest request;
57 request.set_name(kAttributeOwnerId);
58 client_->GetBootAttribute(
59 request,
60 base::Bind(&ConsumerManagementService::OnGetBootAttributeDone,
61 weak_ptr_factory_.GetWeakPtr(),
62 callback));
63 }
64
65 void ConsumerManagementService::OnGetBootAttributeDone(
66 const GetOwnerCallback& callback,
67 chromeos::DBusMethodCallStatus call_status,
68 bool dbus_success,
69 const cryptohome::BaseReply& reply) {
70 if (!dbus_success || reply.error() != 0) {
71 LOG(ERROR) << "Failed to get the owner info from boot lockbox.";
72 callback.Run("");
73 return;
74 }
75
76 callback.Run(
77 reply.GetExtension(cryptohome::GetBootAttributeReply::reply).value());
78 }
79
80 void ConsumerManagementService::SetOwner(const std::string& user_id,
81 const SetOwnerCallback& callback) {
82 cryptohome::SetBootAttributeRequest request;
83 request.set_name(kAttributeOwnerId);
84 request.set_value(user_id.data(), user_id.size());
85 client_->SetBootAttribute(
86 request,
87 base::Bind(&ConsumerManagementService::OnSetBootAttributeDone,
88 weak_ptr_factory_.GetWeakPtr(),
89 callback));
90 }
91
92 void ConsumerManagementService::OnSetBootAttributeDone(
93 const SetOwnerCallback& callback,
94 chromeos::DBusMethodCallStatus call_status,
95 bool dbus_success,
96 const cryptohome::BaseReply& reply) {
97 if (!dbus_success || reply.error() != 0) {
98 LOG(ERROR) << "Failed to set owner info in boot lockbox.";
99 callback.Run(false);
100 return;
101 }
102
103 cryptohome::FlushAndSignBootAttributesRequest request;
104 client_->FlushAndSignBootAttributes(
105 request,
106 base::Bind(&ConsumerManagementService::OnFlushAndSignBootAttributesDone,
107 weak_ptr_factory_.GetWeakPtr(),
108 callback));
109 }
110
111 void ConsumerManagementService::OnFlushAndSignBootAttributesDone(
112 const SetOwnerCallback& callback,
113 chromeos::DBusMethodCallStatus call_status,
114 bool dbus_success,
115 const cryptohome::BaseReply& reply) {
116 if (!dbus_success || reply.error() != 0) {
117 LOG(ERROR) << "Failed to flush and sign boot lockbox.";
118 callback.Run(false);
119 return;
120 }
121
122 callback.Run(true);
123 }
124
125 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698