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

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: Next round of comments. All bots meanwhile good and manual testing seems fine as well. 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) {
Mattias Nissler (ping if slow) 2011/12/02 12:13:37 no need for curlies.
pastarmovj 2011/12/02 14:43:38 Done.
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 } 223 }
224 return NULL; 224 return NULL;
225 } 225 }
226 226
227 // The timezone is always trusted. 227 // The timezone is always trusted.
228 bool SystemSettingsProvider::GetTrusted(const std::string& path, 228 bool SystemSettingsProvider::GetTrusted(const std::string& path,
229 const base::Closure& callback) const { 229 const base::Closure& callback) {
230 return true; 230 return true;
231 } 231 }
232 232
233 bool SystemSettingsProvider::HandlesSetting(const std::string& path) const { 233 bool SystemSettingsProvider::HandlesSetting(const std::string& path) const {
234 return path == kSystemTimezone; 234 return path == kSystemTimezone;
235 } 235 }
236 236
237 void SystemSettingsProvider::Reload() {
238 // TODO(pastarmovj): We can actually cache the timezone here to make returning
239 // it faster.
240 }
241
237 void SystemSettingsProvider::TimezoneChanged(const icu::TimeZone& timezone) { 242 void SystemSettingsProvider::TimezoneChanged(const icu::TimeZone& timezone) {
238 // Fires system setting change notification. 243 // Fires system setting change notification.
244 timezone_value_.reset(
245 base::Value::CreateStringValue(GetKnownTimezoneID(timezone)));
239 CrosSettings::Get()->FireObservers(kSystemTimezone); 246 CrosSettings::Get()->FireObservers(kSystemTimezone);
240 } 247 }
241 248
242 ListValue* SystemSettingsProvider::GetTimezoneList() { 249 ListValue* SystemSettingsProvider::GetTimezoneList() {
243 ListValue* timezoneList = new ListValue(); 250 ListValue* timezoneList = new ListValue();
244 for (std::vector<icu::TimeZone*>::iterator iter = timezones_.begin(); 251 for (std::vector<icu::TimeZone*>::iterator iter = timezones_.begin();
245 iter != timezones_.end(); ++iter) { 252 iter != timezones_.end(); ++iter) {
246 const icu::TimeZone* timezone = *iter; 253 const icu::TimeZone* timezone = *iter;
247 ListValue* option = new ListValue(); 254 ListValue* option = new ListValue();
248 option->Append(Value::CreateStringValue(GetTimezoneID(*timezone))); 255 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; 323 const icu::TimeZone* known_timezone = *iter;
317 if (known_timezone->hasSameRules(timezone)) 324 if (known_timezone->hasSameRules(timezone))
318 return GetTimezoneID(*known_timezone); 325 return GetTimezoneID(*known_timezone);
319 } 326 }
320 327
321 // Not able to find a matching timezone in our list. 328 // Not able to find a matching timezone in our list.
322 return string16(); 329 return string16();
323 } 330 }
324 331
325 } // namespace chromeos 332 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698