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

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

Issue 399613003: SignAndStore method is moved out from DeviceSettingsService to OwnerSettingsService. It's still cal… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/settings/device_settings_service.h ('k') | no next file » | 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/device_settings_service.h" 5 #include "chrome/browser/chromeos/settings/device_settings_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 return public_key_; 106 return public_key_;
107 } 107 }
108 108
109 void DeviceSettingsService::Load() { 109 void DeviceSettingsService::Load() {
110 EnqueueLoad(false); 110 EnqueueLoad(false);
111 } 111 }
112 112
113 void DeviceSettingsService::SignAndStore( 113 void DeviceSettingsService::SignAndStore(
114 scoped_ptr<em::ChromeDeviceSettingsProto> new_settings, 114 scoped_ptr<em::ChromeDeviceSettingsProto> new_settings,
115 const base::Closure& callback) { 115 const base::Closure& callback) {
116 scoped_ptr<em::PolicyData> new_policy = AssemblePolicy(*new_settings); 116 if (!delegate_)
117 if (!new_policy) { 117 HandleError(STORE_KEY_UNAVAILABLE, callback);
118 HandleError(STORE_POLICY_ERROR, callback); 118 else
119 return; 119 delegate_->SignAndStoreAsync(new_settings.Pass(), callback);
120 }
121
122 EnqueueSignAndStore(new_policy.Pass(), callback);
123 } 120 }
124 121
125 void DeviceSettingsService::SetManagementSettings( 122 void DeviceSettingsService::SetManagementSettings(
126 em::PolicyData::ManagementMode management_mode, 123 em::PolicyData::ManagementMode management_mode,
127 const std::string& request_token, 124 const std::string& request_token,
128 const std::string& device_id, 125 const std::string& device_id,
129 const base::Closure& callback) { 126 const base::Closure& callback) {
130 if (!CheckManagementModeTransition(management_mode)) { 127 if (!delegate_) {
131 LOG(ERROR) << "Invalid management mode transition: current mode = " 128 HandleError(STORE_KEY_UNAVAILABLE, callback);
132 << GetManagementMode() << ", new mode = " << management_mode; 129 } else {
133 HandleError(STORE_POLICY_ERROR, callback); 130 delegate_->SetManagementSettingsAsync(
134 return; 131 management_mode, request_token, device_id, callback);
135 } 132 }
136
137 scoped_ptr<em::PolicyData> policy = AssemblePolicy(*device_settings_);
138 if (!policy) {
139 HandleError(STORE_POLICY_ERROR, callback);
140 return;
141 }
142
143 policy->set_management_mode(management_mode);
144 policy->set_request_token(request_token);
145 policy->set_device_id(device_id);
146
147 EnqueueSignAndStore(policy.Pass(), callback);
148 } 133 }
149 134
150 void DeviceSettingsService::Store(scoped_ptr<em::PolicyFetchResponse> policy, 135 void DeviceSettingsService::Store(scoped_ptr<em::PolicyFetchResponse> policy,
151 const base::Closure& callback) { 136 const base::Closure& callback) {
152 Enqueue( 137 Enqueue(
153 new StoreSettingsOperation( 138 new StoreSettingsOperation(
154 base::Bind(&DeviceSettingsService::HandleCompletedOperation, 139 base::Bind(&DeviceSettingsService::HandleCompletedOperation,
155 weak_factory_.GetWeakPtr(), 140 weak_factory_.GetWeakPtr(),
156 callback), 141 callback),
157 policy.Pass())); 142 policy.Pass()));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 new LoadSettingsOperation( 222 new LoadSettingsOperation(
238 base::Bind(&DeviceSettingsService::HandleCompletedOperation, 223 base::Bind(&DeviceSettingsService::HandleCompletedOperation,
239 weak_factory_.GetWeakPtr(), 224 weak_factory_.GetWeakPtr(),
240 base::Closure())); 225 base::Closure()));
241 operation->set_force_key_load(force_key_load); 226 operation->set_force_key_load(force_key_load);
242 operation->set_username(username_); 227 operation->set_username(username_);
243 operation->set_delegate(delegate_); 228 operation->set_delegate(delegate_);
244 Enqueue(operation); 229 Enqueue(operation);
245 } 230 }
246 231
247 void DeviceSettingsService::EnqueueSignAndStore(
248 scoped_ptr<em::PolicyData> policy,
249 const base::Closure& callback) {
250 SignAndStoreSettingsOperation* operation = new SignAndStoreSettingsOperation(
251 base::Bind(&DeviceSettingsService::HandleCompletedOperation,
252 weak_factory_.GetWeakPtr(),
253 callback),
254 policy.Pass());
255 operation->set_delegate(delegate_);
256 Enqueue(operation);
257 }
258
259 void DeviceSettingsService::EnsureReload(bool force_key_load) { 232 void DeviceSettingsService::EnsureReload(bool force_key_load) {
260 if (!pending_operations_.empty()) { 233 if (!pending_operations_.empty()) {
261 pending_operations_.front()->set_username(username_); 234 pending_operations_.front()->set_username(username_);
262 pending_operations_.front()->set_delegate(delegate_); 235 pending_operations_.front()->set_delegate(delegate_);
263 pending_operations_.front()->RestartLoad(force_key_load); 236 pending_operations_.front()->RestartLoad(force_key_load);
264 } else { 237 } else {
265 EnqueueLoad(force_key_load); 238 EnqueueLoad(force_key_load);
266 } 239 }
267 } 240 }
268 241
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 LOG(ERROR) << "Session manager operation failed: " << status; 331 LOG(ERROR) << "Session manager operation failed: " << status;
359 332
360 FOR_EACH_OBSERVER(Observer, observers_, DeviceSettingsUpdated()); 333 FOR_EACH_OBSERVER(Observer, observers_, DeviceSettingsUpdated());
361 334
362 // The completion callback happens after the notification so clients can 335 // The completion callback happens after the notification so clients can
363 // filter self-triggered updates. 336 // filter self-triggered updates.
364 if (!callback.is_null()) 337 if (!callback.is_null())
365 callback.Run(); 338 callback.Run();
366 } 339 }
367 340
368 scoped_ptr<em::PolicyData> DeviceSettingsService::AssemblePolicy( 341 void DeviceSettingsService::OnSignAndStoreOperationCompleted(Status status) {
369 const em::ChromeDeviceSettingsProto& settings) const { 342 store_status_ = status;
370 scoped_ptr<em::PolicyData> policy(new em::PolicyData()); 343 FOR_EACH_OBSERVER(Observer, observers_, DeviceSettingsUpdated());
371 if (policy_data_) {
372 // Preserve management settings.
373 if (policy_data_->has_management_mode())
374 policy->set_management_mode(policy_data_->management_mode());
375 if (policy_data_->has_request_token())
376 policy->set_request_token(policy_data_->request_token());
377 if (policy_data_->has_device_id())
378 policy->set_device_id(policy_data_->device_id());
379 } else {
380 // If there's no previous policy data, this is the first time the device
381 // setting is set. We set the management mode to NOT_MANAGED initially.
382 policy->set_management_mode(em::PolicyData::NOT_MANAGED);
383 }
384 policy->set_policy_type(policy::dm_protocol::kChromeDevicePolicyType);
385 policy->set_timestamp((base::Time::Now() - base::Time::UnixEpoch()).
386 InMilliseconds());
387 policy->set_username(username_);
388 if (!settings.SerializeToString(policy->mutable_policy_value()))
389 return scoped_ptr<em::PolicyData>();
390
391 return policy.Pass();
392 }
393
394 em::PolicyData::ManagementMode DeviceSettingsService::GetManagementMode()
395 const {
396 if (policy_data_ && policy_data_->has_management_mode())
397 return policy_data_->management_mode();
398 return em::PolicyData::NOT_MANAGED;
399 }
400
401 bool DeviceSettingsService::CheckManagementModeTransition(
402 em::PolicyData::ManagementMode new_mode) const {
403 em::PolicyData::ManagementMode current_mode = GetManagementMode();
404
405 // Mode is not changed.
406 if (current_mode == new_mode)
407 return true;
408
409 switch (current_mode) {
410 case em::PolicyData::NOT_MANAGED:
411 // For consumer management enrollment.
412 return new_mode == em::PolicyData::CONSUMER_MANAGED;
413
414 case em::PolicyData::ENTERPRISE_MANAGED:
415 // Management mode cannot be set when it is currently ENTERPRISE_MANAGED.
416 return false;
417
418 case em::PolicyData::CONSUMER_MANAGED:
419 // For consumer management unenrollment.
420 return new_mode == em::PolicyData::NOT_MANAGED;
421 }
422
423 NOTREACHED();
424 return false;
425 } 344 }
426 345
427 ScopedTestDeviceSettingsService::ScopedTestDeviceSettingsService() { 346 ScopedTestDeviceSettingsService::ScopedTestDeviceSettingsService() {
428 DeviceSettingsService::Initialize(); 347 DeviceSettingsService::Initialize();
429 } 348 }
430 349
431 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() { 350 ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() {
432 // Clean pending operations. 351 // Clean pending operations.
433 DeviceSettingsService::Get()->UnsetSessionManager(); 352 DeviceSettingsService::Get()->UnsetSessionManager();
434 DeviceSettingsService::Shutdown(); 353 DeviceSettingsService::Shutdown();
435 } 354 }
436 355
437 } // namespace chromeos 356 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/settings/device_settings_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698