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

Side by Side Diff: chrome/browser/policy/device_policy_identity_strategy.cc

Issue 7298012: Consolidate data storage and notifications in the cloud policy subsystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 5 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
(Empty)
1 // Copyright (c) 2011 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/policy/device_policy_identity_strategy.h"
6
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/chromeos/cros/cros_library.h"
9 #include "chrome/browser/chromeos/login/ownership_service.h"
10 #include "chrome/browser/chromeos/login/user_manager.h"
11 #include "chrome/browser/chromeos/system_access.h"
12 #include "chrome/browser/net/gaia/token_service.h"
13 #include "chrome/browser/policy/proto/device_management_constants.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/common/guid.h"
17 #include "chrome/common/net/gaia/gaia_constants.h"
18 #include "content/common/notification_service.h"
19 #include "content/common/notification_type.h"
20
21 // MachineInfo key names.
22 static const char kMachineInfoSystemHwqual[] = "hardware_class";
23 static const char kMachineInfoSerialNumber[] = "serial_number";
24
25 namespace policy {
26
27 DevicePolicyIdentityStrategy::DevicePolicyIdentityStrategy() {
28 chromeos::SystemAccess* sys_lib = chromeos::SystemAccess::GetInstance();
29
30 if (!sys_lib->GetMachineStatistic(kMachineInfoSystemHwqual,
31 &machine_model_)) {
32 LOG(ERROR) << "Failed to get machine model.";
33 }
34 if (!sys_lib->GetMachineStatistic(kMachineInfoSerialNumber,
35 &machine_id_)) {
36 LOG(ERROR) << "Failed to get machine serial number.";
37 }
38 }
39
40 DevicePolicyIdentityStrategy::~DevicePolicyIdentityStrategy() {
41 }
42
43 std::string DevicePolicyIdentityStrategy::GetDeviceToken() {
44 return device_token_;
45 }
46
47 std::string DevicePolicyIdentityStrategy::GetDeviceID() {
48 return device_id_;
49 }
50
51 std::string DevicePolicyIdentityStrategy::GetMachineID() {
52 return machine_id_;
53 }
54
55 std::string DevicePolicyIdentityStrategy::GetMachineModel() {
56 return machine_model_;
57 }
58
59 em::DeviceRegisterRequest_Type
60 DevicePolicyIdentityStrategy::GetPolicyRegisterType() {
61 return em::DeviceRegisterRequest::DEVICE;
62 }
63
64 std::string DevicePolicyIdentityStrategy::GetPolicyType() {
65 return kChromeDevicePolicyType;
66 }
67
68 void DevicePolicyIdentityStrategy::SetAuthCredentials(
69 const std::string& username,
70 const std::string& auth_token) {
71 username_ = username;
72 auth_token_ = auth_token;
73 device_id_ = guid::GenerateGUID();
74 NotifyAuthChanged();
75 }
76
77 void DevicePolicyIdentityStrategy::SetDeviceManagementCredentials(
78 const std::string& owner_email,
79 const std::string& device_id,
80 const std::string& device_token) {
81 username_ = owner_email;
82 device_id_ = device_id;
83 device_token_ = device_token;
84 NotifyDeviceTokenChanged();
85 }
86
87 void DevicePolicyIdentityStrategy::FetchPolicy() {
88 DCHECK(!device_token_.empty());
89 NotifyDeviceTokenChanged();
90 }
91
92 bool DevicePolicyIdentityStrategy::GetCredentials(std::string* username,
93 std::string* auth_token) {
94 *username = username_;
95 *auth_token = auth_token_;
96
97 return !username->empty() && !auth_token->empty();
98 }
99
100 void DevicePolicyIdentityStrategy::OnDeviceTokenAvailable(
101 const std::string& token) {
102 device_token_ = token;
103 }
104
105 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_policy_identity_strategy.h ('k') | chrome/browser/policy/device_token_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698