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

Side by Side Diff: chrome/browser/chromeos/device_settings_provider.cc

Issue 9703115: Add DeviceSettingProvider unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed documentation. Created 8 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 | Annotate | Revision Log
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/device_settings_provider.h" 5 #include "chrome/browser/chromeos/device_settings_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // If the value is not set we should try to migrate legacy consent file. 74 // If the value is not set we should try to migrate legacy consent file.
75 // Loading consent file state causes us to do blocking IO on UI thread. 75 // Loading consent file state causes us to do blocking IO on UI thread.
76 // Temporarily allow it until we fix http://crbug.com/62626 76 // Temporarily allow it until we fix http://crbug.com/62626
77 base::ThreadRestrictions::ScopedAllowIO allow_io; 77 base::ThreadRestrictions::ScopedAllowIO allow_io;
78 return GoogleUpdateSettings::GetCollectStatsConsent(); 78 return GoogleUpdateSettings::GetCollectStatsConsent();
79 } 79 }
80 80
81 } // namespace 81 } // namespace
82 82
83 DeviceSettingsProvider::DeviceSettingsProvider( 83 DeviceSettingsProvider::DeviceSettingsProvider(
84 const NotifyObserversCallback& notify_cb,
85 SignedSettingsHelper* signed_settings_helper,
86 OwnershipService::Status ownership_status)
87 : CrosSettingsProvider(notify_cb),
88 signed_settings_helper_(signed_settings_helper),
89 ownership_status_(ownership_status),
90 migration_helper_(new SignedSettingsMigrationHelper()),
91 retries_left_(kNumRetriesLimit),
92 trusted_(false) {
93 Initialize();
94 }
95
96 DeviceSettingsProvider::DeviceSettingsProvider(
84 const NotifyObserversCallback& notify_cb) 97 const NotifyObserversCallback& notify_cb)
85 : CrosSettingsProvider(notify_cb), 98 : CrosSettingsProvider(notify_cb),
99 signed_settings_helper_(SignedSettingsHelper::Get()),
86 ownership_status_(OwnershipService::GetSharedInstance()->GetStatus(true)), 100 ownership_status_(OwnershipService::GetSharedInstance()->GetStatus(true)),
87 migration_helper_(new SignedSettingsMigrationHelper()), 101 migration_helper_(new SignedSettingsMigrationHelper()),
88 retries_left_(kNumRetriesLimit), 102 retries_left_(kNumRetriesLimit),
89 trusted_(false) { 103 trusted_(false) {
104 Initialize();
105 }
106
107 DeviceSettingsProvider::~DeviceSettingsProvider() {
108 }
109
110 void DeviceSettingsProvider::Initialize() {
90 // Register for notification when ownership is taken so that we can update 111 // Register for notification when ownership is taken so that we can update
91 // the |ownership_status_| and reload if needed. 112 // the |ownership_status_| and reload if needed.
92 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, 113 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED,
93 content::NotificationService::AllSources()); 114 content::NotificationService::AllSources());
94 // Make sure we have at least the cache data immediately. 115 // Make sure we have at least the cache data immediately.
95 RetrieveCachedData(); 116 RetrieveCachedData();
96 // Start prefetching preferences. 117 // Start prefetching preferences.
97 Reload(); 118 Reload();
98 } 119 }
99 120
100 DeviceSettingsProvider::~DeviceSettingsProvider() {
101 }
102
103 void DeviceSettingsProvider::Reload() { 121 void DeviceSettingsProvider::Reload() {
104 // While fetching we can't trust the cache anymore. 122 // While fetching we can't trust the cache anymore.
105 trusted_ = false; 123 trusted_ = false;
106 if (ownership_status_ == OwnershipService::OWNERSHIP_NONE) { 124 if (ownership_status_ == OwnershipService::OWNERSHIP_NONE) {
107 RetrieveCachedData(); 125 RetrieveCachedData();
108 } else { 126 } else {
109 // Retrieve the real data. 127 // Retrieve the real data.
110 SignedSettingsHelper::Get()->StartRetrievePolicyOp( 128 signed_settings_helper_->StartRetrievePolicyOp(
111 base::Bind(&DeviceSettingsProvider::OnRetrievePolicyCompleted, 129 base::Bind(&DeviceSettingsProvider::OnRetrievePolicyCompleted,
112 base::Unretained(this))); 130 base::Unretained(this)));
113 } 131 }
114 } 132 }
115 133
116 void DeviceSettingsProvider::DoSet(const std::string& path, 134 void DeviceSettingsProvider::DoSet(const std::string& path,
117 const base::Value& in_value) { 135 const base::Value& in_value) {
118 if (!UserManager::Get()->IsCurrentUserOwner() && 136 if (!UserManager::Get()->IsCurrentUserOwner() &&
119 ownership_status_ != OwnershipService::OWNERSHIP_NONE) { 137 ownership_status_ != OwnershipService::OWNERSHIP_NONE) {
120 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; 138 LOG(WARNING) << "Changing settings from non-owner, setting=" << path;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 if (!pending_changes_.empty()) 205 if (!pending_changes_.empty())
188 SetInPolicy(); 206 SetInPolicy();
189 } else { 207 } else {
190 NOTREACHED(); 208 NOTREACHED();
191 } 209 }
192 return; 210 return;
193 } 211 }
194 212
195 if (!RequestTrustedEntity()) { 213 if (!RequestTrustedEntity()) {
196 // Otherwise we should first reload and apply on top of that. 214 // Otherwise we should first reload and apply on top of that.
197 SignedSettingsHelper::Get()->StartRetrievePolicyOp( 215 signed_settings_helper_->StartRetrievePolicyOp(
198 base::Bind(&DeviceSettingsProvider::FinishSetInPolicy, 216 base::Bind(&DeviceSettingsProvider::FinishSetInPolicy,
199 base::Unretained(this))); 217 base::Unretained(this)));
200 return; 218 return;
201 } 219 }
202 220
203 trusted_ = false; 221 trusted_ = false;
204 em::PolicyData data = policy(); 222 em::PolicyData data = policy();
205 em::ChromeDeviceSettingsProto pol; 223 em::ChromeDeviceSettingsProto pol;
206 pol.ParseFromString(data.policy_value()); 224 pol.ParseFromString(data.policy_value());
207 if (prop == kAccountsPrefAllowNewUser) { 225 if (prop == kAccountsPrefAllowNewUser) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // Set the cache to the updated value. 314 // Set the cache to the updated value.
297 policy_ = data; 315 policy_ = data;
298 UpdateValuesCache(); 316 UpdateValuesCache();
299 317
300 if (!signed_settings_cache::Store(data, g_browser_process->local_state())) 318 if (!signed_settings_cache::Store(data, g_browser_process->local_state()))
301 LOG(ERROR) << "Couldn't store to the temp storage."; 319 LOG(ERROR) << "Couldn't store to the temp storage.";
302 320
303 if (ownership_status_ == OwnershipService::OWNERSHIP_TAKEN) { 321 if (ownership_status_ == OwnershipService::OWNERSHIP_TAKEN) {
304 em::PolicyFetchResponse policy_envelope; 322 em::PolicyFetchResponse policy_envelope;
305 policy_envelope.set_policy_data(policy_.SerializeAsString()); 323 policy_envelope.set_policy_data(policy_.SerializeAsString());
306 SignedSettingsHelper::Get()->StartStorePolicyOp( 324 signed_settings_helper_->StartStorePolicyOp(
307 policy_envelope, 325 policy_envelope,
308 base::Bind(&DeviceSettingsProvider::OnStorePolicyCompleted, 326 base::Bind(&DeviceSettingsProvider::OnStorePolicyCompleted,
309 base::Unretained(this))); 327 base::Unretained(this)));
310 } else { 328 } else {
311 // OnStorePolicyCompleted won't get called in this case so proceed with any 329 // OnStorePolicyCompleted won't get called in this case so proceed with any
312 // pending operations immediately. 330 // pending operations immediately.
313 delete pending_changes_[0].second; 331 delete pending_changes_[0].second;
314 pending_changes_.erase(pending_changes_.begin()); 332 pending_changes_.erase(pending_changes_.begin());
315 if (!pending_changes_.empty()) 333 if (!pending_changes_.empty())
316 SetInPolicy(); 334 SetInPolicy();
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 Reload(); 740 Reload();
723 return; 741 return;
724 } 742 }
725 LOG(ERROR) << "No retries left"; 743 LOG(ERROR) << "No retries left";
726 break; 744 break;
727 } 745 }
728 } 746 }
729 } 747 }
730 748
731 } // namespace chromeos 749 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698