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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/settings/system_settings_provider.h"
7 #include "base/strings/string16.h"
8 #include "base/time/time.h"
9 #include "base/values.h"
10 #include "chromeos/login/login_state.h"
11 #include "chromeos/settings/cros_settings_names.h"
12 #include "content/public/browser/render_process_host.h"
16 SystemSettingsProvider::SystemSettingsProvider(
17 const NotifyObserversCallback& notify_cb)
18 : CrosSettingsProvider(notify_cb) {
19 system::TimezoneSettings *timezone_settings =
20 system::TimezoneSettings::GetInstance();
21 timezone_settings->AddObserver(this);
22 timezone_value_.reset(new base::StringValue(
23 timezone_settings->GetCurrentTimezoneID()));
26 SystemSettingsProvider::~SystemSettingsProvider() {
27 system::TimezoneSettings::GetInstance()->RemoveObserver(this);
30 void SystemSettingsProvider::DoSet(const std::string& path,
31 const base::Value& in_value) {
32 // Non-guest users can change the time zone.
33 if (LoginState::Get()->IsGuestUser())
36 if (path == kSystemTimezone) {
37 base::string16 timezone_id;
38 if (!in_value.GetAsString(&timezone_id))
40 // This will call TimezoneChanged.
41 system::TimezoneSettings::GetInstance()->SetTimezoneFromID(timezone_id);
45 const base::Value* SystemSettingsProvider::Get(const std::string& path) const {
46 if (path == kSystemTimezone)
47 return timezone_value_.get();
51 // The timezone is always trusted.
52 CrosSettingsProvider::TrustedStatus
53 SystemSettingsProvider::PrepareTrustedValues(const base::Closure& cb) {
57 bool SystemSettingsProvider::HandlesSetting(const std::string& path) const {
58 return path == kSystemTimezone;
61 void SystemSettingsProvider::TimezoneChanged(const icu::TimeZone& timezone) {
62 // Fires system setting change notification.
63 timezone_value_.reset(new base::StringValue(
64 system::TimezoneSettings::GetTimezoneID(timezone)));
65 NotifyObservers(kSystemTimezone);
68 for (content::RenderProcessHost::iterator it(
69 content::RenderProcessHost::AllHostsIterator());
72 it.GetCurrentValue()->NotifyTimezoneChange();
76 } // namespace chromeos