| 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; |
| 26 using ownership::OwnerKeyUtil; | 28 using ownership::OwnerKeyUtil; |
| 27 using ownership::PublicKey; | 29 using ownership::PublicKey; |
| 28 | 30 |
| 29 namespace em = enterprise_management; | 31 namespace em = enterprise_management; |
| 30 | 32 |
| 31 namespace chromeos { | 33 namespace chromeos { |
| 32 | 34 |
| 33 SessionManagerOperation::SessionManagerOperation(const Callback& callback) | 35 SessionManagerOperation::SessionManagerOperation(const Callback& callback) |
| 34 : callback_(callback), weak_factory_(this) {} | 36 : callback_(callback), weak_factory_(this) {} |
| 35 | 37 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 callback.Run(); | 133 callback.Run(); |
| 132 } | 134 } |
| 133 | 135 |
| 134 void SessionManagerOperation::RetrieveDeviceSettings() { | 136 void SessionManagerOperation::RetrieveDeviceSettings() { |
| 135 session_manager_client()->RetrieveDevicePolicy( | 137 session_manager_client()->RetrieveDevicePolicy( |
| 136 base::Bind(&SessionManagerOperation::ValidateDeviceSettings, | 138 base::Bind(&SessionManagerOperation::ValidateDeviceSettings, |
| 137 weak_factory_.GetWeakPtr())); | 139 weak_factory_.GetWeakPtr())); |
| 138 } | 140 } |
| 139 | 141 |
| 140 void SessionManagerOperation::BlockingRetrieveDeviceSettings() { | 142 void SessionManagerOperation::BlockingRetrieveDeviceSettings() { |
| 141 ValidateDeviceSettings( | 143 std::string policy_blob; |
| 142 session_manager_client()->BlockingRetrieveDevicePolicy()); | 144 RetrievePolicyResponseType response = |
| 145 session_manager_client()->BlockingRetrieveDevicePolicy(&policy_blob); |
| 146 ValidateDeviceSettings(policy_blob, response); |
| 143 } | 147 } |
| 144 | 148 |
| 145 void SessionManagerOperation::ValidateDeviceSettings( | 149 void SessionManagerOperation::ValidateDeviceSettings( |
| 146 const std::string& policy_blob) { | 150 const std::string& policy_blob, |
| 151 RetrievePolicyResponseType response_type) { |
| 147 std::unique_ptr<em::PolicyFetchResponse> policy( | 152 std::unique_ptr<em::PolicyFetchResponse> policy( |
| 148 new em::PolicyFetchResponse()); | 153 new em::PolicyFetchResponse()); |
| 149 if (policy_blob.empty()) { | 154 if (policy_blob.empty()) { |
| 150 ReportResult(DeviceSettingsService::STORE_NO_POLICY); | 155 ReportResult(DeviceSettingsService::STORE_NO_POLICY); |
| 151 return; | 156 return; |
| 152 } | 157 } |
| 153 | 158 |
| 154 if (!policy->ParseFromString(policy_blob) || | 159 if (!policy->ParseFromString(policy_blob) || !policy->IsInitialized()) { |
| 155 !policy->IsInitialized()) { | |
| 156 ReportResult(DeviceSettingsService::STORE_INVALID_POLICY); | 160 ReportResult(DeviceSettingsService::STORE_INVALID_POLICY); |
| 157 return; | 161 return; |
| 158 } | 162 } |
| 159 | 163 |
| 160 base::SequencedWorkerPool* pool = | 164 base::SequencedWorkerPool* pool = |
| 161 content::BrowserThread::GetBlockingPool(); | 165 content::BrowserThread::GetBlockingPool(); |
| 162 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 166 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
| 163 pool->GetSequencedTaskRunnerWithShutdownBehavior( | 167 pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 164 pool->GetSequenceToken(), | 168 pool->GetSequenceToken(), |
| 165 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 169 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 266 } |
| 263 | 267 |
| 264 void StoreSettingsOperation::HandleStoreResult(bool success) { | 268 void StoreSettingsOperation::HandleStoreResult(bool success) { |
| 265 if (!success) | 269 if (!success) |
| 266 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); | 270 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); |
| 267 else | 271 else |
| 268 StartLoading(); | 272 StartLoading(); |
| 269 } | 273 } |
| 270 | 274 |
| 271 } // namespace chromeos | 275 } // namespace chromeos |
| OLD | NEW |