Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: chrome/browser/chromeos/settings/session_manager_operation.cc

Issue 2737483006: Reland Fix handling of device cloud signing policy key rotation (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/policy/device_cloud_policy_browsertest.cc ('k') | chromeos/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 29 matching lines...) Expand all
40 scoped_refptr<OwnerKeyUtil> owner_key_util, 40 scoped_refptr<OwnerKeyUtil> owner_key_util,
41 scoped_refptr<PublicKey> public_key) { 41 scoped_refptr<PublicKey> public_key) {
42 session_manager_client_ = session_manager_client; 42 session_manager_client_ = session_manager_client;
43 owner_key_util_ = owner_key_util; 43 owner_key_util_ = owner_key_util;
44 public_key_ = public_key; 44 public_key_ = public_key;
45 Run(); 45 Run();
46 } 46 }
47 47
48 void SessionManagerOperation::RestartLoad(bool key_changed) { 48 void SessionManagerOperation::RestartLoad(bool key_changed) {
49 if (key_changed) 49 if (key_changed)
50 public_key_ = NULL; 50 public_key_ = nullptr;
51 51
52 if (!is_loading_) 52 if (!is_loading_)
53 return; 53 return;
54 54
55 // Abort previous load operations. 55 // Abort previous load operations.
56 weak_factory_.InvalidateWeakPtrs(); 56 weak_factory_.InvalidateWeakPtrs();
57 // Mark as not loading to start loading again. 57 // Mark as not loading to start loading again.
58 is_loading_ = false; 58 is_loading_ = false;
59 StartLoading(); 59 StartLoading();
60 } 60 }
(...skipping 16 matching lines...) Expand all
77 weak_factory_.GetWeakPtr()), 77 weak_factory_.GetWeakPtr()),
78 LoadPublicKey(owner_key_util_, public_key_)); 78 LoadPublicKey(owner_key_util_, public_key_));
79 } 79 }
80 80
81 void SessionManagerOperation::ReportResult( 81 void SessionManagerOperation::ReportResult(
82 DeviceSettingsService::Status status) { 82 DeviceSettingsService::Status status) {
83 callback_.Run(this, status); 83 callback_.Run(this, status);
84 } 84 }
85 85
86 void SessionManagerOperation::EnsurePublicKey(const base::Closure& callback) { 86 void SessionManagerOperation::EnsurePublicKey(const base::Closure& callback) {
87 if (force_key_load_ || !public_key_.get() || !public_key_->is_loaded()) { 87 if (force_key_load_ || !public_key_ || !public_key_->is_loaded()) {
88 scoped_refptr<base::TaskRunner> task_runner = 88 scoped_refptr<base::TaskRunner> task_runner =
89 content::BrowserThread::GetBlockingPool() 89 content::BrowserThread::GetBlockingPool()
90 ->GetTaskRunnerWithShutdownBehavior( 90 ->GetTaskRunnerWithShutdownBehavior(
91 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 91 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
92 base::PostTaskAndReplyWithResult( 92 base::PostTaskAndReplyWithResult(
93 task_runner.get(), 93 task_runner.get(), FROM_HERE,
94 FROM_HERE, 94 base::Bind(&SessionManagerOperation::LoadPublicKey, owner_key_util_,
95 base::Bind(&SessionManagerOperation::LoadPublicKey, 95 force_key_load_ ? nullptr : public_key_),
96 owner_key_util_,
97 public_key_),
98 base::Bind(&SessionManagerOperation::StorePublicKey, 96 base::Bind(&SessionManagerOperation::StorePublicKey,
99 weak_factory_.GetWeakPtr(), 97 weak_factory_.GetWeakPtr(), callback));
100 callback));
101 } else { 98 } else {
102 callback.Run(); 99 callback.Run();
103 } 100 }
104 } 101 }
105 102
106 // static 103 // static
107 scoped_refptr<PublicKey> SessionManagerOperation::LoadPublicKey( 104 scoped_refptr<PublicKey> SessionManagerOperation::LoadPublicKey(
108 scoped_refptr<OwnerKeyUtil> util, 105 scoped_refptr<OwnerKeyUtil> util,
109 scoped_refptr<PublicKey> current_key) { 106 scoped_refptr<PublicKey> current_key) {
110 scoped_refptr<PublicKey> public_key(new PublicKey()); 107 scoped_refptr<PublicKey> public_key(new PublicKey());
111 108
112 // Keep already-existing public key. 109 // Keep already-existing public key.
113 if (current_key.get() && current_key->is_loaded()) { 110 if (current_key && current_key->is_loaded()) {
114 public_key->data() = current_key->data(); 111 public_key->data() = current_key->data();
115 } 112 }
116 if (!public_key->is_loaded() && util->IsPublicKeyPresent()) { 113 if (!public_key->is_loaded() && util->IsPublicKeyPresent()) {
117 if (!util->ImportPublicKey(&public_key->data())) 114 if (!util->ImportPublicKey(&public_key->data()))
118 LOG(ERROR) << "Failed to load public owner key."; 115 LOG(ERROR) << "Failed to load public owner key.";
119 } 116 }
120 117
121 return public_key; 118 return public_key;
122 } 119 }
123 120
124 void SessionManagerOperation::StorePublicKey(const base::Closure& callback, 121 void SessionManagerOperation::StorePublicKey(const base::Closure& callback,
125 scoped_refptr<PublicKey> new_key) { 122 scoped_refptr<PublicKey> new_key) {
126 force_key_load_ = false; 123 force_key_load_ = false;
127 public_key_ = new_key; 124 public_key_ = new_key;
128 125
129 if (!public_key_.get() || !public_key_->is_loaded()) { 126 if (!public_key_ || !public_key_->is_loaded()) {
130 ReportResult(DeviceSettingsService::STORE_KEY_UNAVAILABLE); 127 ReportResult(DeviceSettingsService::STORE_KEY_UNAVAILABLE);
131 return; 128 return;
132 } 129 }
133 130
134 callback.Run(); 131 callback.Run();
135 } 132 }
136 133
137 void SessionManagerOperation::RetrieveDeviceSettings() { 134 void SessionManagerOperation::RetrieveDeviceSettings() {
138 session_manager_client()->RetrieveDevicePolicy( 135 session_manager_client()->RetrieveDevicePolicy(
139 base::Bind(&SessionManagerOperation::ValidateDeviceSettings, 136 base::Bind(&SessionManagerOperation::ValidateDeviceSettings,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 LoadImmediately(); 251 LoadImmediately();
255 else 252 else
256 StartLoading(); 253 StartLoading();
257 } 254 }
258 255
259 StoreSettingsOperation::StoreSettingsOperation( 256 StoreSettingsOperation::StoreSettingsOperation(
260 const Callback& callback, 257 const Callback& callback,
261 std::unique_ptr<em::PolicyFetchResponse> policy) 258 std::unique_ptr<em::PolicyFetchResponse> policy)
262 : SessionManagerOperation(callback), 259 : SessionManagerOperation(callback),
263 policy_(std::move(policy)), 260 policy_(std::move(policy)),
264 weak_factory_(this) {} 261 weak_factory_(this) {
262 if (policy_->has_new_public_key())
263 force_key_load_ = true;
264 }
265 265
266 StoreSettingsOperation::~StoreSettingsOperation() {} 266 StoreSettingsOperation::~StoreSettingsOperation() {}
267 267
268 void StoreSettingsOperation::Run() { 268 void StoreSettingsOperation::Run() {
269 session_manager_client()->StoreDevicePolicy( 269 session_manager_client()->StoreDevicePolicy(
270 policy_->SerializeAsString(), 270 policy_->SerializeAsString(),
271 base::Bind(&StoreSettingsOperation::HandleStoreResult, 271 base::Bind(&StoreSettingsOperation::HandleStoreResult,
272 weak_factory_.GetWeakPtr())); 272 weak_factory_.GetWeakPtr()));
273 } 273 }
274 274
275 void StoreSettingsOperation::HandleStoreResult(bool success) { 275 void StoreSettingsOperation::HandleStoreResult(bool success) {
276 if (!success) 276 if (!success)
277 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); 277 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED);
278 else 278 else
279 StartLoading(); 279 StartLoading();
280 } 280 }
281 281
282 } // namespace chromeos 282 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/device_cloud_policy_browsertest.cc ('k') | chromeos/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698