Index: chrome/browser/chromeos/settings/device_settings_service.cc |
diff --git a/chrome/browser/chromeos/settings/device_settings_service.cc b/chrome/browser/chromeos/settings/device_settings_service.cc |
index 9c2669ae583ef9752bf06337c7e7251de806006d..53b2a561ef37ed801968059f856c29a60fa6d1cf 100644 |
--- a/chrome/browser/chromeos/settings/device_settings_service.cc |
+++ b/chrome/browser/chromeos/settings/device_settings_service.cc |
@@ -10,7 +10,6 @@ |
#include "base/stl_util.h" |
#include "base/time/time.h" |
#include "chrome/browser/chrome_notification_types.h" |
-#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
#include "chrome/browser/chromeos/settings/session_manager_operation.h" |
#include "components/ownership/owner_key_util.h" |
@@ -36,6 +35,36 @@ |
// of retry time. |
int kMaxLoadRetries = (1000 * 60 * 10) / kLoadRetryDelayMs; |
+// Assembles PolicyData based on |settings|, |policy_data| and |
+// |user_id|. |
+scoped_ptr<em::PolicyData> AssemblePolicy( |
+ const std::string& user_id, |
+ const em::PolicyData* policy_data, |
+ const em::ChromeDeviceSettingsProto* settings) { |
+ scoped_ptr<em::PolicyData> policy(new em::PolicyData()); |
+ if (policy_data) { |
+ // Preserve management settings. |
+ if (policy_data->has_management_mode()) |
+ policy->set_management_mode(policy_data->management_mode()); |
+ if (policy_data->has_request_token()) |
+ policy->set_request_token(policy_data->request_token()); |
+ if (policy_data->has_device_id()) |
+ policy->set_device_id(policy_data->device_id()); |
+ } else { |
+ // If there's no previous policy data, this is the first time the device |
+ // setting is set. We set the management mode to NOT_MANAGED initially. |
+ policy->set_management_mode(em::PolicyData::NOT_MANAGED); |
+ } |
+ policy->set_policy_type(policy::dm_protocol::kChromeDevicePolicyType); |
+ policy->set_timestamp( |
+ (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); |
+ policy->set_username(user_id); |
+ if (!settings->SerializeToString(policy->mutable_policy_value())) |
+ return scoped_ptr<em::PolicyData>(); |
+ |
+ return policy.Pass(); |
+} |
+ |
// Returns true if it is okay to transfer from the current mode to the new |
// mode. This function should be called in SetManagementMode(). |
bool CheckManagementModeTransition(em::PolicyData::ManagementMode current_mode, |
@@ -122,6 +151,8 @@ |
} |
void DeviceSettingsService::UnsetSessionManager() { |
+ STLDeleteContainerPointers(pending_operations_.begin(), |
+ pending_operations_.end()); |
pending_operations_.clear(); |
if (session_manager_client_) |
@@ -141,10 +172,18 @@ |
void DeviceSettingsService::SignAndStore( |
scoped_ptr<em::ChromeDeviceSettingsProto> new_settings, |
const base::Closure& callback) { |
+ if (!owner_settings_service_) { |
+ HandleError(STORE_KEY_UNAVAILABLE, callback); |
+ return; |
+ } |
scoped_ptr<em::PolicyData> policy = |
- OwnerSettingsServiceChromeOS::AssemblePolicy( |
- GetUsername(), policy_data(), new_settings.get()); |
- EnqueueSignAndStore(policy.Pass(), callback); |
+ AssemblePolicy(GetUsername(), policy_data(), new_settings.get()); |
+ if (!policy) { |
+ HandleError(STORE_POLICY_ERROR, callback); |
+ return; |
+ } |
+ |
+ owner_settings_service_->SignAndStorePolicyAsync(policy.Pass(), callback); |
} |
void DeviceSettingsService::SetManagementSettings( |
@@ -169,8 +208,7 @@ |
} |
scoped_ptr<em::PolicyData> policy = |
- OwnerSettingsServiceChromeOS::AssemblePolicy( |
- GetUsername(), policy_data(), device_settings()); |
+ AssemblePolicy(GetUsername(), policy_data(), device_settings()); |
if (!policy) { |
HandleError(DeviceSettingsService::STORE_POLICY_ERROR, callback); |
return; |
@@ -180,16 +218,17 @@ |
policy->set_request_token(request_token); |
policy->set_device_id(device_id); |
- EnqueueSignAndStore(policy.Pass(), callback); |
+ owner_settings_service_->SignAndStorePolicyAsync(policy.Pass(), callback); |
} |
void DeviceSettingsService::Store(scoped_ptr<em::PolicyFetchResponse> policy, |
const base::Closure& callback) { |
- Enqueue(linked_ptr<SessionManagerOperation>(new StoreSettingsOperation( |
- base::Bind(&DeviceSettingsService::HandleCompletedOperation, |
- weak_factory_.GetWeakPtr(), |
- callback), |
- policy.Pass()))); |
+ Enqueue( |
+ new StoreSettingsOperation( |
+ base::Bind(&DeviceSettingsService::HandleCompletedOperation, |
+ weak_factory_.GetWeakPtr(), |
+ callback), |
+ policy.Pass())); |
} |
DeviceSettingsService::OwnershipStatus |
@@ -237,11 +276,6 @@ |
return username_; |
} |
-ownership::OwnerSettingsService* |
-DeviceSettingsService::GetOwnerSettingsService() const { |
- return owner_settings_service_.get(); |
-} |
- |
void DeviceSettingsService::AddObserver(Observer* observer) { |
observers_.AddObserver(observer); |
} |
@@ -269,33 +303,20 @@ |
EnsureReload(false); |
} |
-void DeviceSettingsService::Enqueue( |
- const linked_ptr<SessionManagerOperation>& operation) { |
+void DeviceSettingsService::Enqueue(SessionManagerOperation* operation) { |
pending_operations_.push_back(operation); |
- if (pending_operations_.front().get() == operation.get()) |
+ if (pending_operations_.front() == operation) |
StartNextOperation(); |
} |
void DeviceSettingsService::EnqueueLoad(bool force_key_load) { |
- linked_ptr<SessionManagerOperation> operation(new LoadSettingsOperation( |
- base::Bind(&DeviceSettingsService::HandleCompletedOperation, |
- weak_factory_.GetWeakPtr(), |
- base::Closure()))); |
+ SessionManagerOperation* operation = |
+ new LoadSettingsOperation( |
+ base::Bind(&DeviceSettingsService::HandleCompletedOperation, |
+ weak_factory_.GetWeakPtr(), |
+ base::Closure())); |
operation->set_force_key_load(force_key_load); |
operation->set_username(username_); |
- operation->set_owner_settings_service(owner_settings_service_); |
- Enqueue(operation); |
-} |
- |
-void DeviceSettingsService::EnqueueSignAndStore( |
- scoped_ptr<enterprise_management::PolicyData> policy, |
- const base::Closure& callback) { |
- linked_ptr<SessionManagerOperation> operation( |
- new SignAndStoreSettingsOperation( |
- base::Bind(&DeviceSettingsService::HandleCompletedOperation, |
- weak_factory_.GetWeakPtr(), |
- callback), |
- policy.Pass())); |
operation->set_owner_settings_service(owner_settings_service_); |
Enqueue(operation); |
} |
@@ -312,7 +333,8 @@ |
} |
void DeviceSettingsService::StartNextOperation() { |
- if (!pending_operations_.empty() && session_manager_client_ && |
+ if (!pending_operations_.empty() && |
+ session_manager_client_ && |
owner_key_util_.get()) { |
pending_operations_.front()->Start( |
session_manager_client_, owner_key_util_, public_key_); |
@@ -323,7 +345,7 @@ |
const base::Closure& callback, |
SessionManagerOperation* operation, |
Status status) { |
- DCHECK_EQ(operation, pending_operations_.front().get()); |
+ DCHECK_EQ(operation, pending_operations_.front()); |
store_status_ = status; |
OwnershipStatus ownership_status = OWNERSHIP_UNKNOWN; |
@@ -390,6 +412,7 @@ |
// Only remove the pending operation here, so new operations triggered by any |
// of the callbacks above are queued up properly. |
pending_operations_.pop_front(); |
+ delete operation; |
StartNextOperation(); |
} |
@@ -408,6 +431,11 @@ |
callback.Run(); |
} |
+void DeviceSettingsService::OnSignAndStoreOperationCompleted(Status status) { |
+ store_status_ = status; |
+ FOR_EACH_OBSERVER(Observer, observers_, DeviceSettingsUpdated()); |
+} |
+ |
ScopedTestDeviceSettingsService::ScopedTestDeviceSettingsService() { |
DeviceSettingsService::Initialize(); |
} |