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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/system_settings_provider.cc

Issue 8727037: Signed settings refactoring: Proper caching and more tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Fixed small bugs. Rebased to ToT. 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/ui/webui/options/chromeos/system_settings_provider.h" 5 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } // namespace anonymous 182 } // namespace anonymous
183 183
184 namespace chromeos { 184 namespace chromeos {
185 185
186 SystemSettingsProvider::SystemSettingsProvider() { 186 SystemSettingsProvider::SystemSettingsProvider() {
187 for (size_t i = 0; i < arraysize(kTimeZones); i++) { 187 for (size_t i = 0; i < arraysize(kTimeZones); i++) {
188 timezones_.push_back(icu::TimeZone::createTimeZone( 188 timezones_.push_back(icu::TimeZone::createTimeZone(
189 icu::UnicodeString(kTimeZones[i], -1, US_INV))); 189 icu::UnicodeString(kTimeZones[i], -1, US_INV)));
190 } 190 }
191 system::TimezoneSettings::GetInstance()->AddObserver(this); 191 system::TimezoneSettings::GetInstance()->AddObserver(this);
192 192 timezone_value_.reset(base::Value::CreateStringValue(GetKnownTimezoneID(
193 system::TimezoneSettings::GetInstance()->GetTimezone())));
193 } 194 }
194 195
195 SystemSettingsProvider::~SystemSettingsProvider() { 196 SystemSettingsProvider::~SystemSettingsProvider() {
196 system::TimezoneSettings::GetInstance()->RemoveObserver(this); 197 system::TimezoneSettings::GetInstance()->RemoveObserver(this);
197 STLDeleteElements(&timezones_); 198 STLDeleteElements(&timezones_);
198 } 199 }
199 200
200 void SystemSettingsProvider::DoSet(const std::string& path, 201 void SystemSettingsProvider::DoSet(const std::string& path,
201 const base::Value& in_value) { 202 const base::Value& in_value) {
202 // Non-guest users can change the time zone. 203 // Non-guest users can change the time zone.
203 if (UserManager::Get()->IsLoggedInAsGuest()) 204 if (UserManager::Get()->IsLoggedInAsGuest())
204 return; 205 return;
205 206
206 if (path == kSystemTimezone) { 207 if (path == kSystemTimezone) {
207 string16 value; 208 string16 value;
208 if (!in_value.IsType(Value::TYPE_STRING) || !in_value.GetAsString(&value)) 209 if (!in_value.IsType(Value::TYPE_STRING) || !in_value.GetAsString(&value))
209 return; 210 return;
210 const icu::TimeZone* timezone = GetTimezone(value); 211 const icu::TimeZone* timezone = GetTimezone(value);
211 if (!timezone) 212 if (!timezone)
212 return; 213 return;
213 system::TimezoneSettings::GetInstance()->SetTimezone(*timezone); 214 system::TimezoneSettings::GetInstance()->SetTimezone(*timezone);
215 timezone_value_.reset(
216 base::Value::CreateStringValue(GetKnownTimezoneID(*timezone)));
214 } 217 }
215 } 218 }
216 219
217 const base::Value* SystemSettingsProvider::Get(const std::string& path) const { 220 const base::Value* SystemSettingsProvider::Get(const std::string& path) const {
218 if (path == kSystemTimezone) { 221 if (path == kSystemTimezone)
219 // TODO(pastarmovj): Cache this in the local_state instead of locally. 222 return timezone_value_.get();
220 system_timezone_.reset(base::Value::CreateStringValue(GetKnownTimezoneID(
221 system::TimezoneSettings::GetInstance()->GetTimezone())));
222 return system_timezone_.get();
223 }
224 return NULL; 223 return NULL;
225 } 224 }
226 225
227 // The timezone is always trusted. 226 // The timezone is always trusted.
228 bool SystemSettingsProvider::GetTrusted(const std::string& path, 227 bool SystemSettingsProvider::GetTrusted(const std::string& path,
229 const base::Closure& callback) const { 228 const base::Closure& callback) {
230 return true; 229 return true;
231 } 230 }
232 231
233 bool SystemSettingsProvider::HandlesSetting(const std::string& path) const { 232 bool SystemSettingsProvider::HandlesSetting(const std::string& path) const {
234 return path == kSystemTimezone; 233 return path == kSystemTimezone;
235 } 234 }
236 235
236 void SystemSettingsProvider::Reload() {
237 // TODO(pastarmovj): We can actually cache the timezone here to make returning
238 // it faster.
239 }
240
237 void SystemSettingsProvider::TimezoneChanged(const icu::TimeZone& timezone) { 241 void SystemSettingsProvider::TimezoneChanged(const icu::TimeZone& timezone) {
238 // Fires system setting change notification. 242 // Fires system setting change notification.
243 timezone_value_.reset(
244 base::Value::CreateStringValue(GetKnownTimezoneID(timezone)));
239 CrosSettings::Get()->FireObservers(kSystemTimezone); 245 CrosSettings::Get()->FireObservers(kSystemTimezone);
240 } 246 }
241 247
242 ListValue* SystemSettingsProvider::GetTimezoneList() { 248 ListValue* SystemSettingsProvider::GetTimezoneList() {
243 ListValue* timezoneList = new ListValue(); 249 ListValue* timezoneList = new ListValue();
244 for (std::vector<icu::TimeZone*>::iterator iter = timezones_.begin(); 250 for (std::vector<icu::TimeZone*>::iterator iter = timezones_.begin();
245 iter != timezones_.end(); ++iter) { 251 iter != timezones_.end(); ++iter) {
246 const icu::TimeZone* timezone = *iter; 252 const icu::TimeZone* timezone = *iter;
247 ListValue* option = new ListValue(); 253 ListValue* option = new ListValue();
248 option->Append(Value::CreateStringValue(GetTimezoneID(*timezone))); 254 option->Append(Value::CreateStringValue(GetTimezoneID(*timezone)));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 const icu::TimeZone* known_timezone = *iter; 322 const icu::TimeZone* known_timezone = *iter;
317 if (known_timezone->hasSameRules(timezone)) 323 if (known_timezone->hasSameRules(timezone))
318 return GetTimezoneID(*known_timezone); 324 return GetTimezoneID(*known_timezone);
319 } 325 }
320 326
321 // Not able to find a matching timezone in our list. 327 // Not able to find a matching timezone in our list.
322 return string16(); 328 return string16();
323 } 329 }
324 330
325 } // namespace chromeos 331 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/system_settings_provider.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698