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

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 copyright header. Created 8 years, 8 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // If the value is not set we should try to migrate legacy consent file. 75 // If the value is not set we should try to migrate legacy consent file.
76 // Loading consent file state causes us to do blocking IO on UI thread. 76 // Loading consent file state causes us to do blocking IO on UI thread.
77 // Temporarily allow it until we fix http://crbug.com/62626 77 // Temporarily allow it until we fix http://crbug.com/62626
78 base::ThreadRestrictions::ScopedAllowIO allow_io; 78 base::ThreadRestrictions::ScopedAllowIO allow_io;
79 return GoogleUpdateSettings::GetCollectStatsConsent(); 79 return GoogleUpdateSettings::GetCollectStatsConsent();
80 } 80 }
81 81
82 } // namespace 82 } // namespace
83 83
84 DeviceSettingsProvider::DeviceSettingsProvider( 84 DeviceSettingsProvider::DeviceSettingsProvider(
85 const NotifyObserversCallback& notify_cb) 85 const NotifyObserversCallback& notify_cb,
86 SignedSettingsHelper* signed_settings_helper)
86 : CrosSettingsProvider(notify_cb), 87 : CrosSettingsProvider(notify_cb),
88 signed_settings_helper_(signed_settings_helper),
87 ownership_status_(OwnershipService::GetSharedInstance()->GetStatus(true)), 89 ownership_status_(OwnershipService::GetSharedInstance()->GetStatus(true)),
88 migration_helper_(new SignedSettingsMigrationHelper()), 90 migration_helper_(new SignedSettingsMigrationHelper()),
89 retries_left_(kNumRetriesLimit), 91 retries_left_(kNumRetriesLimit),
90 trusted_(false) { 92 trusted_(false) {
91 // Register for notification when ownership is taken so that we can update 93 // Register for notification when ownership is taken so that we can update
92 // the |ownership_status_| and reload if needed. 94 // the |ownership_status_| and reload if needed.
93 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, 95 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED,
94 content::NotificationService::AllSources()); 96 content::NotificationService::AllSources());
95 // Make sure we have at least the cache data immediately. 97 // Make sure we have at least the cache data immediately.
96 RetrieveCachedData(); 98 RetrieveCachedData();
97 // Start prefetching preferences. 99 // Start prefetching preferences.
98 Reload(); 100 Reload();
99 } 101 }
100 102
101 DeviceSettingsProvider::~DeviceSettingsProvider() { 103 DeviceSettingsProvider::~DeviceSettingsProvider() {
102 } 104 }
103 105
104 void DeviceSettingsProvider::Reload() { 106 void DeviceSettingsProvider::Reload() {
105 // While fetching we can't trust the cache anymore. 107 // While fetching we can't trust the cache anymore.
106 trusted_ = false; 108 trusted_ = false;
107 if (ownership_status_ == OwnershipService::OWNERSHIP_NONE) { 109 if (ownership_status_ == OwnershipService::OWNERSHIP_NONE) {
108 RetrieveCachedData(); 110 RetrieveCachedData();
109 } else { 111 } else {
110 // Retrieve the real data. 112 // Retrieve the real data.
111 SignedSettingsHelper::Get()->StartRetrievePolicyOp( 113 signed_settings_helper_->StartRetrievePolicyOp(
112 base::Bind(&DeviceSettingsProvider::OnRetrievePolicyCompleted, 114 base::Bind(&DeviceSettingsProvider::OnRetrievePolicyCompleted,
113 base::Unretained(this))); 115 base::Unretained(this)));
114 } 116 }
115 } 117 }
116 118
117 void DeviceSettingsProvider::DoSet(const std::string& path, 119 void DeviceSettingsProvider::DoSet(const std::string& path,
118 const base::Value& in_value) { 120 const base::Value& in_value) {
119 if (!UserManager::Get()->IsCurrentUserOwner() && 121 if (!UserManager::Get()->IsCurrentUserOwner() &&
120 ownership_status_ != OwnershipService::OWNERSHIP_NONE) { 122 ownership_status_ != OwnershipService::OWNERSHIP_NONE) {
121 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; 123 LOG(WARNING) << "Changing settings from non-owner, setting=" << path;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if (!pending_changes_.empty()) 190 if (!pending_changes_.empty())
189 SetInPolicy(); 191 SetInPolicy();
190 } else { 192 } else {
191 NOTREACHED(); 193 NOTREACHED();
192 } 194 }
193 return; 195 return;
194 } 196 }
195 197
196 if (!RequestTrustedEntity()) { 198 if (!RequestTrustedEntity()) {
197 // Otherwise we should first reload and apply on top of that. 199 // Otherwise we should first reload and apply on top of that.
198 SignedSettingsHelper::Get()->StartRetrievePolicyOp( 200 signed_settings_helper_->StartRetrievePolicyOp(
199 base::Bind(&DeviceSettingsProvider::FinishSetInPolicy, 201 base::Bind(&DeviceSettingsProvider::FinishSetInPolicy,
200 base::Unretained(this))); 202 base::Unretained(this)));
201 return; 203 return;
202 } 204 }
203 205
204 trusted_ = false; 206 trusted_ = false;
205 em::PolicyData data = policy(); 207 em::PolicyData data = policy();
206 em::ChromeDeviceSettingsProto pol; 208 em::ChromeDeviceSettingsProto pol;
207 pol.ParseFromString(data.policy_value()); 209 pol.ParseFromString(data.policy_value());
208 if (prop == kAccountsPrefAllowNewUser) { 210 if (prop == kAccountsPrefAllowNewUser) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // Set the cache to the updated value. 300 // Set the cache to the updated value.
299 policy_ = data; 301 policy_ = data;
300 UpdateValuesCache(); 302 UpdateValuesCache();
301 303
302 if (!signed_settings_cache::Store(data, g_browser_process->local_state())) 304 if (!signed_settings_cache::Store(data, g_browser_process->local_state()))
303 LOG(ERROR) << "Couldn't store to the temp storage."; 305 LOG(ERROR) << "Couldn't store to the temp storage.";
304 306
305 if (ownership_status_ == OwnershipService::OWNERSHIP_TAKEN) { 307 if (ownership_status_ == OwnershipService::OWNERSHIP_TAKEN) {
306 em::PolicyFetchResponse policy_envelope; 308 em::PolicyFetchResponse policy_envelope;
307 policy_envelope.set_policy_data(policy_.SerializeAsString()); 309 policy_envelope.set_policy_data(policy_.SerializeAsString());
308 SignedSettingsHelper::Get()->StartStorePolicyOp( 310 signed_settings_helper_->StartStorePolicyOp(
309 policy_envelope, 311 policy_envelope,
310 base::Bind(&DeviceSettingsProvider::OnStorePolicyCompleted, 312 base::Bind(&DeviceSettingsProvider::OnStorePolicyCompleted,
311 base::Unretained(this))); 313 base::Unretained(this)));
312 } else { 314 } else {
313 // OnStorePolicyCompleted won't get called in this case so proceed with any 315 // OnStorePolicyCompleted won't get called in this case so proceed with any
314 // pending operations immediately. 316 // pending operations immediately.
315 delete pending_changes_[0].second; 317 delete pending_changes_[0].second;
316 pending_changes_.erase(pending_changes_.begin()); 318 pending_changes_.erase(pending_changes_.begin());
317 if (!pending_changes_.empty()) 319 if (!pending_changes_.empty())
318 SetInPolicy(); 320 SetInPolicy();
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 Reload(); 725 Reload();
724 return; 726 return;
725 } 727 }
726 LOG(ERROR) << "No retries left"; 728 LOG(ERROR) << "No retries left";
727 break; 729 break;
728 } 730 }
729 } 731 }
730 } 732 }
731 733
732 } // namespace chromeos 734 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/device_settings_provider.h ('k') | chrome/browser/chromeos/device_settings_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698