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), | 34 service_(service), // Can be NULL for unit tests. |
35 status_provider_(status_provider), | 35 status_provider_(status_provider), // Can be NULL for unit tests. |
36 status_(DM_STATUS_SUCCESS) {} | 36 status_(DM_STATUS_SUCCESS) { |
| 37 } |
37 | 38 |
38 CloudPolicyClient::~CloudPolicyClient() {} | 39 CloudPolicyClient::~CloudPolicyClient() {} |
39 | 40 |
40 void CloudPolicyClient::SetupRegistration(const std::string& dm_token, | 41 void CloudPolicyClient::SetupRegistration(const std::string& dm_token, |
41 const std::string& client_id) { | 42 const std::string& client_id) { |
42 DCHECK(!dm_token.empty()); | 43 DCHECK(!dm_token.empty()); |
43 DCHECK(!client_id.empty()); | 44 DCHECK(!client_id.empty()); |
44 DCHECK(!is_registered()); | 45 DCHECK(!is_registered()); |
45 | 46 |
46 dm_token_ = dm_token; | 47 dm_token_ = dm_token; |
47 client_id_ = client_id; | 48 client_id_ = client_id; |
48 request_job_.reset(); | 49 request_job_.reset(); |
49 policy_.reset(); | 50 policy_.reset(); |
50 | 51 |
51 NotifyRegistrationStateChanged(); | 52 NotifyRegistrationStateChanged(); |
52 } | 53 } |
53 | 54 |
54 void CloudPolicyClient::Register(const std::string& auth_token) { | 55 void CloudPolicyClient::Register(const std::string& auth_token) { |
| 56 DCHECK(service_); |
55 DCHECK(!auth_token.empty()); | 57 DCHECK(!auth_token.empty()); |
56 DCHECK(!is_registered()); | 58 DCHECK(!is_registered()); |
57 | 59 |
58 // Generate a new client ID. This is intentionally done on each new | 60 // Generate a new client ID. This is intentionally done on each new |
59 // registration request in order to preserve privacy. Reusing IDs would mean | 61 // registration request in order to preserve privacy. Reusing IDs would mean |
60 // the server could track clients by their registration attempts. | 62 // the server could track clients by their registration attempts. |
61 client_id_ = base::GenerateGUID(); | 63 client_id_ = base::GenerateGUID(); |
62 | 64 |
63 request_job_.reset( | 65 request_job_.reset( |
64 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)); | 66 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 request->clear_session_status_report_request(); | 115 request->clear_session_status_report_request(); |
114 } | 116 } |
115 } | 117 } |
116 | 118 |
117 // Fire the job. | 119 // Fire the job. |
118 request_job_->Start(base::Bind(&CloudPolicyClient::OnPolicyFetchCompleted, | 120 request_job_->Start(base::Bind(&CloudPolicyClient::OnPolicyFetchCompleted, |
119 base::Unretained(this))); | 121 base::Unretained(this))); |
120 } | 122 } |
121 | 123 |
122 void CloudPolicyClient::Unregister() { | 124 void CloudPolicyClient::Unregister() { |
| 125 DCHECK(service_); |
123 request_job_.reset( | 126 request_job_.reset( |
124 service_->CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION)); | 127 service_->CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION)); |
125 request_job_->SetDMToken(dm_token_); | 128 request_job_->SetDMToken(dm_token_); |
126 request_job_->SetClientID(client_id_); | 129 request_job_->SetClientID(client_id_); |
127 request_job_->GetRequest()->mutable_unregister_request(); | 130 request_job_->GetRequest()->mutable_unregister_request(); |
128 request_job_->Start(base::Bind(&CloudPolicyClient::OnUnregisterCompleted, | 131 request_job_->Start(base::Bind(&CloudPolicyClient::OnUnregisterCompleted, |
129 base::Unretained(this))); | 132 base::Unretained(this))); |
130 } | 133 } |
131 | 134 |
132 void CloudPolicyClient::AddObserver(Observer* observer) { | 135 void CloudPolicyClient::AddObserver(Observer* observer) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 232 |
230 void CloudPolicyClient::NotifyRegistrationStateChanged() { | 233 void CloudPolicyClient::NotifyRegistrationStateChanged() { |
231 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); | 234 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); |
232 } | 235 } |
233 | 236 |
234 void CloudPolicyClient::NotifyClientError() { | 237 void CloudPolicyClient::NotifyClientError() { |
235 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); | 238 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); |
236 } | 239 } |
237 | 240 |
238 } // namespace policy | 241 } // namespace policy |
OLD | NEW |