OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/device_token_fetcher.h" | 5 #include "chrome/browser/policy/device_token_fetcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "chrome/browser/policy/cloud_policy_cache.h" | 10 #include "chrome/browser/policy/cloud_policy_cache.h" |
11 #include "chrome/browser/policy/device_management_service.h" | 11 #include "chrome/browser/policy/device_management_service.h" |
| 12 #include "chrome/browser/policy/proto/device_management_constants.h" |
12 #include "chrome/browser/policy/proto/device_management_local.pb.h" | 13 #include "chrome/browser/policy/proto/device_management_local.pb.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // Retry after 3 seconds (with exponential backoff) after token fetch errors. | 17 // Retry after 3 seconds (with exponential backoff) after token fetch errors. |
17 const int64 kTokenFetchErrorDelayMilliseconds = 3 * 1000; | 18 const int64 kTokenFetchErrorDelayMilliseconds = 3 * 1000; |
18 // For unmanaged devices, check once per day whether they're still unmanaged. | 19 // For unmanaged devices, check once per day whether they're still unmanaged. |
19 const int64 kUnmanagedDeviceRefreshRateMilliseconds = 24 * 60 * 60 * 1000; | 20 const int64 kUnmanagedDeviceRefreshRateMilliseconds = 24 * 60 * 60 * 1000; |
20 | 21 |
21 } // namespace | 22 } // namespace |
(...skipping 21 matching lines...) Expand all Loading... |
43 Initialize(service, | 44 Initialize(service, |
44 cache, | 45 cache, |
45 token_fetch_error_delay_ms, | 46 token_fetch_error_delay_ms, |
46 unmanaged_device_refresh_rate_ms); | 47 unmanaged_device_refresh_rate_ms); |
47 } | 48 } |
48 | 49 |
49 DeviceTokenFetcher::~DeviceTokenFetcher() { | 50 DeviceTokenFetcher::~DeviceTokenFetcher() { |
50 CancelRetryTask(); | 51 CancelRetryTask(); |
51 } | 52 } |
52 | 53 |
53 void DeviceTokenFetcher::FetchToken(const std::string& auth_token, | 54 void DeviceTokenFetcher::FetchToken( |
54 const std::string& device_id) { | 55 const std::string& auth_token, |
| 56 const std::string& device_id, |
| 57 em::DeviceRegisterRequest_Type policy_type, |
| 58 const std::string& machine_id) { |
55 SetState(STATE_INACTIVE); | 59 SetState(STATE_INACTIVE); |
56 auth_token_ = auth_token; | 60 auth_token_ = auth_token; |
57 device_id_ = device_id; | 61 device_id_ = device_id; |
| 62 policy_type_ = policy_type; |
| 63 machine_id_ = machine_id; |
58 FetchTokenInternal(); | 64 FetchTokenInternal(); |
59 } | 65 } |
60 | 66 |
61 void DeviceTokenFetcher::FetchTokenInternal() { | 67 void DeviceTokenFetcher::FetchTokenInternal() { |
62 DCHECK(state_ != STATE_TOKEN_AVAILABLE); | 68 DCHECK(state_ != STATE_TOKEN_AVAILABLE); |
63 DCHECK(!auth_token_.empty() && !device_id_.empty()); | 69 DCHECK(!auth_token_.empty() && !device_id_.empty()); |
64 // Construct a new backend, which will discard any previous requests. | 70 // Construct a new backend, which will discard any previous requests. |
65 backend_.reset(service_->CreateBackend()); | 71 backend_.reset(service_->CreateBackend()); |
66 em::DeviceRegisterRequest request; | 72 em::DeviceRegisterRequest request; |
| 73 request.set_type(policy_type_); |
| 74 if (!machine_id_.empty()) |
| 75 request.set_machine_id(machine_id_); |
| 76 request.set_machine_model(kRegisterRequestMachineModel); |
67 backend_->ProcessRegisterRequest(auth_token_, device_id_, request, this); | 77 backend_->ProcessRegisterRequest(auth_token_, device_id_, request, this); |
68 } | 78 } |
69 | 79 |
70 const std::string& DeviceTokenFetcher::GetDeviceToken() { | 80 const std::string& DeviceTokenFetcher::GetDeviceToken() { |
71 return device_token_; | 81 return device_token_; |
72 } | 82 } |
73 | 83 |
74 void DeviceTokenFetcher::AddObserver(DeviceTokenFetcher::Observer* observer) { | 84 void DeviceTokenFetcher::AddObserver(DeviceTokenFetcher::Observer* observer) { |
75 observer_list_.AddObserver(observer); | 85 observer_list_.AddObserver(observer); |
76 } | 86 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 179 } |
170 | 180 |
171 void DeviceTokenFetcher::CancelRetryTask() { | 181 void DeviceTokenFetcher::CancelRetryTask() { |
172 if (retry_task_) { | 182 if (retry_task_) { |
173 retry_task_->Cancel(); | 183 retry_task_->Cancel(); |
174 retry_task_ = NULL; | 184 retry_task_ = NULL; |
175 } | 185 } |
176 } | 186 } |
177 | 187 |
178 } // namespace policy | 188 } // namespace policy |
OLD | NEW |