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 // Only non-guest users can change the time zone.
33 if (LoginState::Get()->IsGuestSessionUser() ||
34 LoginState::Get()->IsPublicSessionUser()) {
38 if (path
== kSystemTimezone
) {
39 base::string16 timezone_id
;
40 if (!in_value
.GetAsString(&timezone_id
))
42 // This will call TimezoneChanged.
43 system::TimezoneSettings::GetInstance()->SetTimezoneFromID(timezone_id
);
47 const base::Value
* SystemSettingsProvider::Get(const std::string
& path
) const {
48 if (path
== kSystemTimezone
)
49 return timezone_value_
.get();
53 // The timezone is always trusted.
54 CrosSettingsProvider::TrustedStatus
55 SystemSettingsProvider::PrepareTrustedValues(const base::Closure
& cb
) {
59 bool SystemSettingsProvider::HandlesSetting(const std::string
& path
) const {
60 return path
== kSystemTimezone
;
63 void SystemSettingsProvider::TimezoneChanged(const icu::TimeZone
& timezone
) {
64 // Fires system setting change notification.
65 timezone_value_
.reset(new base::StringValue(
66 system::TimezoneSettings::GetTimezoneID(timezone
)));
67 NotifyObservers(kSystemTimezone
);
70 } // namespace chromeos