OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/policy/cloud_policy_client.h" | 5 #include "chrome/browser/policy/cloud_policy_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/guid.h" | 8 #include "base/guid.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/browser/policy/device_management_service.h" | 10 #include "chrome/browser/policy/device_management_service.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 PolicyScope scope, | 24 PolicyScope scope, |
25 StatusProvider* status_provider, | 25 StatusProvider* status_provider, |
26 DeviceManagementService* service) | 26 DeviceManagementService* service) |
27 : machine_id_(machine_id), | 27 : machine_id_(machine_id), |
28 machine_model_(machine_model), | 28 machine_model_(machine_model), |
29 user_affiliation_(user_affiliation), | 29 user_affiliation_(user_affiliation), |
30 scope_(scope), | 30 scope_(scope), |
31 submit_machine_id_(false), | 31 submit_machine_id_(false), |
32 public_key_version_(-1), | 32 public_key_version_(-1), |
33 public_key_version_valid_(false), | 33 public_key_version_valid_(false), |
34 service_(service), // Can be NULL for unit tests. | 34 service_(service), |
35 status_provider_(status_provider), // Can be NULL for unit tests. | 35 status_provider_(status_provider), |
36 status_(DM_STATUS_SUCCESS) { | 36 status_(DM_STATUS_SUCCESS) {} |
37 } | |
38 | 37 |
39 CloudPolicyClient::~CloudPolicyClient() {} | 38 CloudPolicyClient::~CloudPolicyClient() {} |
40 | 39 |
41 void CloudPolicyClient::SetupRegistration(const std::string& dm_token, | 40 void CloudPolicyClient::SetupRegistration(const std::string& dm_token, |
42 const std::string& client_id) { | 41 const std::string& client_id) { |
43 DCHECK(!dm_token.empty()); | 42 DCHECK(!dm_token.empty()); |
44 DCHECK(!client_id.empty()); | 43 DCHECK(!client_id.empty()); |
45 DCHECK(!is_registered()); | 44 DCHECK(!is_registered()); |
46 | 45 |
47 dm_token_ = dm_token; | 46 dm_token_ = dm_token; |
48 client_id_ = client_id; | 47 client_id_ = client_id; |
49 request_job_.reset(); | 48 request_job_.reset(); |
50 policy_.reset(); | 49 policy_.reset(); |
51 | 50 |
52 NotifyRegistrationStateChanged(); | 51 NotifyRegistrationStateChanged(); |
53 } | 52 } |
54 | 53 |
55 void CloudPolicyClient::Register(const std::string& auth_token) { | 54 void CloudPolicyClient::Register(const std::string& auth_token) { |
56 DCHECK(service_); | |
57 DCHECK(!auth_token.empty()); | 55 DCHECK(!auth_token.empty()); |
58 DCHECK(!is_registered()); | 56 DCHECK(!is_registered()); |
59 | 57 |
60 // Generate a new client ID. This is intentionally done on each new | 58 // Generate a new client ID. This is intentionally done on each new |
61 // registration request in order to preserve privacy. Reusing IDs would mean | 59 // registration request in order to preserve privacy. Reusing IDs would mean |
62 // the server could track clients by their registration attempts. | 60 // the server could track clients by their registration attempts. |
63 client_id_ = base::GenerateGUID(); | 61 client_id_ = base::GenerateGUID(); |
64 | 62 |
65 request_job_.reset( | 63 request_job_.reset( |
66 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)); | 64 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 request->clear_session_status_report_request(); | 113 request->clear_session_status_report_request(); |
116 } | 114 } |
117 } | 115 } |
118 | 116 |
119 // Fire the job. | 117 // Fire the job. |
120 request_job_->Start(base::Bind(&CloudPolicyClient::OnPolicyFetchCompleted, | 118 request_job_->Start(base::Bind(&CloudPolicyClient::OnPolicyFetchCompleted, |
121 base::Unretained(this))); | 119 base::Unretained(this))); |
122 } | 120 } |
123 | 121 |
124 void CloudPolicyClient::Unregister() { | 122 void CloudPolicyClient::Unregister() { |
125 DCHECK(service_); | |
126 request_job_.reset( | 123 request_job_.reset( |
127 service_->CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION)); | 124 service_->CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION)); |
128 request_job_->SetDMToken(dm_token_); | 125 request_job_->SetDMToken(dm_token_); |
129 request_job_->SetClientID(client_id_); | 126 request_job_->SetClientID(client_id_); |
130 request_job_->GetRequest()->mutable_unregister_request(); | 127 request_job_->GetRequest()->mutable_unregister_request(); |
131 request_job_->Start(base::Bind(&CloudPolicyClient::OnUnregisterCompleted, | 128 request_job_->Start(base::Bind(&CloudPolicyClient::OnUnregisterCompleted, |
132 base::Unretained(this))); | 129 base::Unretained(this))); |
133 } | 130 } |
134 | 131 |
135 void CloudPolicyClient::AddObserver(Observer* observer) { | 132 void CloudPolicyClient::AddObserver(Observer* observer) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 229 |
233 void CloudPolicyClient::NotifyRegistrationStateChanged() { | 230 void CloudPolicyClient::NotifyRegistrationStateChanged() { |
234 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); | 231 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); |
235 } | 232 } |
236 | 233 |
237 void CloudPolicyClient::NotifyClientError() { | 234 void CloudPolicyClient::NotifyClientError() { |
238 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); | 235 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); |
239 } | 236 } |
240 | 237 |
241 } // namespace policy | 238 } // namespace policy |
OLD | NEW |