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/chromeos/settings/session_manager_operation.h" | 5 #include "chrome/browser/chromeos/settings/session_manager_operation.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/task_runner_util.h" | 15 #include "base/task_runner_util.h" |
16 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
17 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 17 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
18 #include "chrome/browser/net/nss_context.h" | 18 #include "chrome/browser/net/nss_context.h" |
19 #include "components/ownership/owner_key_util.h" | 19 #include "components/ownership/owner_key_util.h" |
20 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 20 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
21 #include "components/policy/proto/device_management_backend.pb.h" | 21 #include "components/policy/proto/device_management_backend.pb.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "crypto/rsa_private_key.h" | 23 #include "crypto/rsa_private_key.h" |
24 #include "crypto/signature_creator.h" | 24 #include "crypto/signature_creator.h" |
25 | 25 |
26 using RetrievePolicyResponseType = | |
27 chromeos::SessionManagerClient::RetrievePolicyResponseType; | |
28 using ownership::OwnerKeyUtil; | 26 using ownership::OwnerKeyUtil; |
29 using ownership::PublicKey; | 27 using ownership::PublicKey; |
30 | 28 |
31 namespace em = enterprise_management; | 29 namespace em = enterprise_management; |
32 | 30 |
33 namespace chromeos { | 31 namespace chromeos { |
34 | 32 |
35 SessionManagerOperation::SessionManagerOperation(const Callback& callback) | 33 SessionManagerOperation::SessionManagerOperation(const Callback& callback) |
36 : callback_(callback), weak_factory_(this) {} | 34 : callback_(callback), weak_factory_(this) {} |
37 | 35 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 callback.Run(); | 131 callback.Run(); |
134 } | 132 } |
135 | 133 |
136 void SessionManagerOperation::RetrieveDeviceSettings() { | 134 void SessionManagerOperation::RetrieveDeviceSettings() { |
137 session_manager_client()->RetrieveDevicePolicy( | 135 session_manager_client()->RetrieveDevicePolicy( |
138 base::Bind(&SessionManagerOperation::ValidateDeviceSettings, | 136 base::Bind(&SessionManagerOperation::ValidateDeviceSettings, |
139 weak_factory_.GetWeakPtr())); | 137 weak_factory_.GetWeakPtr())); |
140 } | 138 } |
141 | 139 |
142 void SessionManagerOperation::BlockingRetrieveDeviceSettings() { | 140 void SessionManagerOperation::BlockingRetrieveDeviceSettings() { |
143 std::string policy_blob; | 141 ValidateDeviceSettings( |
144 RetrievePolicyResponseType response = | 142 session_manager_client()->BlockingRetrieveDevicePolicy()); |
145 session_manager_client()->BlockingRetrieveDevicePolicy(&policy_blob); | |
146 ValidateDeviceSettings(policy_blob, response); | |
147 } | 143 } |
148 | 144 |
149 void SessionManagerOperation::ValidateDeviceSettings( | 145 void SessionManagerOperation::ValidateDeviceSettings( |
150 const std::string& policy_blob, | 146 const std::string& policy_blob) { |
151 RetrievePolicyResponseType response_type) { | |
152 std::unique_ptr<em::PolicyFetchResponse> policy( | 147 std::unique_ptr<em::PolicyFetchResponse> policy( |
153 new em::PolicyFetchResponse()); | 148 new em::PolicyFetchResponse()); |
154 if (policy_blob.empty()) { | 149 if (policy_blob.empty()) { |
155 ReportResult(DeviceSettingsService::STORE_NO_POLICY); | 150 ReportResult(DeviceSettingsService::STORE_NO_POLICY); |
156 return; | 151 return; |
157 } | 152 } |
158 | 153 |
159 if (!policy->ParseFromString(policy_blob) || !policy->IsInitialized()) { | 154 if (!policy->ParseFromString(policy_blob) || |
| 155 !policy->IsInitialized()) { |
160 ReportResult(DeviceSettingsService::STORE_INVALID_POLICY); | 156 ReportResult(DeviceSettingsService::STORE_INVALID_POLICY); |
161 return; | 157 return; |
162 } | 158 } |
163 | 159 |
164 base::SequencedWorkerPool* pool = | 160 base::SequencedWorkerPool* pool = |
165 content::BrowserThread::GetBlockingPool(); | 161 content::BrowserThread::GetBlockingPool(); |
166 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 162 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
167 pool->GetSequencedTaskRunnerWithShutdownBehavior( | 163 pool->GetSequencedTaskRunnerWithShutdownBehavior( |
168 pool->GetSequenceToken(), | 164 pool->GetSequenceToken(), |
169 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 165 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 273 } |
278 | 274 |
279 void StoreSettingsOperation::HandleStoreResult(bool success) { | 275 void StoreSettingsOperation::HandleStoreResult(bool success) { |
280 if (!success) | 276 if (!success) |
281 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); | 277 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); |
282 else | 278 else |
283 StartLoading(); | 279 StartLoading(); |
284 } | 280 } |
285 | 281 |
286 } // namespace chromeos | 282 } // namespace chromeos |
OLD | NEW |