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

Side by Side Diff: chrome/browser/policy/user_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/user_policy_identity_strategy.h"
6
7 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
8 #include "chrome/browser/policy/proto/device_management_constants.h"
9 #include "chrome/common/guid.h"
10
11 namespace policy {
12
13 namespace em = enterprise_management;
14
15 UserPolicyIdentityStrategy::UserPolicyIdentityStrategy(
16 const std::string& user_name,
17 const FilePath& cache_file)
18 : cache_loaded_(false),
19 user_name_(user_name),
20 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
21 cache_ = new UserPolicyTokenCache(weak_ptr_factory_.GetWeakPtr(), cache_file);
22 }
23
24 UserPolicyIdentityStrategy::~UserPolicyIdentityStrategy() {}
25
26 void UserPolicyIdentityStrategy::LoadTokenCache() {
27 cache_->Load();
28 }
29
30 std::string UserPolicyIdentityStrategy::GetDeviceToken() {
31 return device_token_;
32 }
33
34 std::string UserPolicyIdentityStrategy::GetDeviceID() {
35 return device_id_;
36 }
37
38 std::string UserPolicyIdentityStrategy::GetMachineID() {
39 return std::string();
40 }
41
42 std::string UserPolicyIdentityStrategy::GetMachineModel() {
43 return std::string();
44 }
45
46 em::DeviceRegisterRequest_Type
47 UserPolicyIdentityStrategy::GetPolicyRegisterType() {
48 return em::DeviceRegisterRequest::USER;
49 }
50
51 std::string UserPolicyIdentityStrategy::GetPolicyType() {
52 return kChromeUserPolicyType;
53 }
54
55 bool UserPolicyIdentityStrategy::GetCredentials(std::string* username,
56 std::string* auth_token) {
57 *username = user_name_;
58 *auth_token = auth_token_;
59
60 return !username->empty() && !auth_token->empty() && !device_id_.empty();
61 }
62
63 void UserPolicyIdentityStrategy::OnDeviceTokenAvailable(
64 const std::string& token) {
65 DCHECK(!device_id_.empty());
66 device_token_ = token;
67 cache_->Store(device_token_, device_id_);
68 NotifyDeviceTokenChanged();
69 }
70
71 void UserPolicyIdentityStrategy::CheckAndTriggerFetch() {
72 if (!user_name_.empty() && !auth_token_.empty() && cache_loaded_) {
73 // For user tokens, there is no actual identifier. We generate a random
74 // identifier instead each time we ask for the token.
75 // This shouldn't be done before the cache is loaded, because there may
76 // already be a device id and matching device token stored there.
77 device_id_ = guid::GenerateGUID();
78 NotifyAuthChanged();
79 }
80 }
81
82 void UserPolicyIdentityStrategy::SetAuthToken(const std::string& auth_token) {
83 auth_token_ = auth_token;
84
85 // Request a new device management server token, but only in case we
86 // don't already have it.
87 if (device_token_.empty())
88 CheckAndTriggerFetch();
89 }
90
91 void UserPolicyIdentityStrategy::OnTokenCacheLoaded(
92 const std::string& token,
93 const std::string& device_id) {
94 if (cache_loaded_)
95 return;
96 cache_loaded_ = true;
97 if (!token.empty() && !device_id.empty()) {
98 device_token_ = token;
99 device_id_ = device_id;
100 NotifyDeviceTokenChanged();
101 } else {
102 CheckAndTriggerFetch();
103 }
104 }
105
106
107 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/user_policy_identity_strategy.h ('k') | chrome/browser/policy/user_policy_token_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698