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

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

Issue 8899002: [cros] Add --stub-cros-settings option for testing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CrosSettingsProvider instances use a callback for notifying observers. Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // TODO(pastarmovj): Remove this once migration is not needed anymore. 85 // TODO(pastarmovj): Remove this once migration is not needed anymore.
86 // If the value is not set we should try to migrate legacy consent file. 86 // If the value is not set we should try to migrate legacy consent file.
87 // Loading consent file state causes us to do blocking IO on UI thread. 87 // Loading consent file state causes us to do blocking IO on UI thread.
88 // Temporarily allow it until we fix http://crbug.com/62626 88 // Temporarily allow it until we fix http://crbug.com/62626
89 base::ThreadRestrictions::ScopedAllowIO allow_io; 89 base::ThreadRestrictions::ScopedAllowIO allow_io;
90 return GoogleUpdateSettings::GetCollectStatsConsent(); 90 return GoogleUpdateSettings::GetCollectStatsConsent();
91 } 91 }
92 92
93 } // namespace 93 } // namespace
94 94
95 DeviceSettingsProvider::DeviceSettingsProvider() 95 DeviceSettingsProvider::DeviceSettingsProvider(
96 : ownership_status_(OwnershipService::GetSharedInstance()->GetStatus(true)), 96 const NotifyObserversCallback& notify_cb)
97 : CrosSettingsProvider(notify_cb),
98 ownership_status_(OwnershipService::GetSharedInstance()->GetStatus(true)),
97 migration_helper_(new SignedSettingsMigrationHelper()), 99 migration_helper_(new SignedSettingsMigrationHelper()),
98 retries_left_(kNumRetriesLimit), 100 retries_left_(kNumRetriesLimit),
99 trusted_(false) { 101 trusted_(false) {
100 // Register for notification when ownership is taken so that we can update 102 // Register for notification when ownership is taken so that we can update
101 // the |ownership_status_| and reload if needed. 103 // the |ownership_status_| and reload if needed.
102 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, 104 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED,
103 content::NotificationService::AllSources()); 105 content::NotificationService::AllSources());
104 // Make sure we have at least the cache data immediately. 106 // Make sure we have at least the cache data immediately.
105 RetrieveCachedData(); 107 RetrieveCachedData();
106 // Start prefetching preferences. 108 // Start prefetching preferences.
(...skipping 16 matching lines...) Expand all
123 } 125 }
124 } 126 }
125 127
126 void DeviceSettingsProvider::DoSet(const std::string& path, 128 void DeviceSettingsProvider::DoSet(const std::string& path,
127 const base::Value& in_value) { 129 const base::Value& in_value) {
128 if (!UserManager::Get()->current_user_is_owner() && 130 if (!UserManager::Get()->current_user_is_owner() &&
129 ownership_status_ != OwnershipService::OWNERSHIP_NONE) { 131 ownership_status_ != OwnershipService::OWNERSHIP_NONE) {
130 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; 132 LOG(WARNING) << "Changing settings from non-owner, setting=" << path;
131 133
132 // Revert UI change. 134 // Revert UI change.
133 CrosSettings::Get()->FireObservers(path.c_str()); 135 NotifyObservers(path);
134 return; 136 return;
135 } 137 }
136 138
137 if (IsControlledSetting(path)) 139 if (IsControlledSetting(path))
138 SetInPolicy(path, in_value); 140 SetInPolicy(path, in_value);
139 else 141 else
140 NOTREACHED() << "Try to set unhandled cros setting " << path; 142 NOTREACHED() << "Try to set unhandled cros setting " << path;
141 } 143 }
142 144
143 void DeviceSettingsProvider::Observe( 145 void DeviceSettingsProvider::Observe(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 177 }
176 178
177 void DeviceSettingsProvider::SetInPolicy(const std::string& prop, 179 void DeviceSettingsProvider::SetInPolicy(const std::string& prop,
178 const base::Value& value) { 180 const base::Value& value) {
179 if (prop == kDeviceOwner) { 181 if (prop == kDeviceOwner) {
180 // Just store it in the memory cache without trusted checks or persisting. 182 // Just store it in the memory cache without trusted checks or persisting.
181 std::string owner; 183 std::string owner;
182 if (value.GetAsString(&owner)) { 184 if (value.GetAsString(&owner)) {
183 policy_.set_username(owner); 185 policy_.set_username(owner);
184 values_cache_.SetValue(prop, value.DeepCopy()); 186 values_cache_.SetValue(prop, value.DeepCopy());
185 CrosSettings::Get()->FireObservers(prop.c_str()); 187 NotifyObservers(prop);
186 // We can't trust this value anymore until we reload the real username. 188 // We can't trust this value anymore until we reload the real username.
187 trusted_ = false; 189 trusted_ = false;
188 } else { 190 } else {
189 NOTREACHED(); 191 NOTREACHED();
190 } 192 }
191 return; 193 return;
192 } 194 }
193 195
194 if (!RequestTrustedEntity()) { 196 if (!RequestTrustedEntity()) {
195 // Otherwise we should first reload and apply on top of that. 197 // Otherwise we should first reload and apply on top of that.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 if ((*i)->GetAsString(&email)) 270 if ((*i)->GetAsString(&email))
269 whitelist_proto->add_user_whitelist(email.c_str()); 271 whitelist_proto->add_user_whitelist(email.c_str());
270 } 272 }
271 } else { 273 } else {
272 NOTREACHED(); 274 NOTREACHED();
273 } 275 }
274 data.set_policy_value(pol.SerializeAsString()); 276 data.set_policy_value(pol.SerializeAsString());
275 // Set the cache to the updated value. 277 // Set the cache to the updated value.
276 policy_ = data; 278 policy_ = data;
277 UpdateValuesCache(); 279 UpdateValuesCache();
278 CrosSettings::Get()->FireObservers(prop.c_str()); 280 NotifyObservers(prop);
279 281
280 if (!signed_settings_cache::Store(data, g_browser_process->local_state())) 282 if (!signed_settings_cache::Store(data, g_browser_process->local_state()))
281 LOG(ERROR) << "Couldn't store to the temp storage."; 283 LOG(ERROR) << "Couldn't store to the temp storage.";
282 284
283 if (ownership_status_ == OwnershipService::OWNERSHIP_TAKEN) { 285 if (ownership_status_ == OwnershipService::OWNERSHIP_TAKEN) {
284 em::PolicyFetchResponse policy_envelope; 286 em::PolicyFetchResponse policy_envelope;
285 policy_envelope.set_policy_data(policy_.SerializeAsString()); 287 policy_envelope.set_policy_data(policy_.SerializeAsString());
286 SignedSettingsHelper::Get()->StartStorePolicyOp( 288 SignedSettingsHelper::Get()->StartStorePolicyOp(
287 policy_envelope, 289 policy_envelope,
288 base::Bind(&DeviceSettingsProvider::OnStorePolicyCompleted, 290 base::Bind(&DeviceSettingsProvider::OnStorePolicyCompleted,
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 Reload(); 520 Reload();
519 return; 521 return;
520 } 522 }
521 LOG(ERROR) << "No retries left"; 523 LOG(ERROR) << "No retries left";
522 break; 524 break;
523 } 525 }
524 } 526 }
525 } 527 }
526 528
527 } // namespace chromeos 529 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698