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"
13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/render_widget_host.h"
15 #include "content/public/browser/render_widget_host_iterator.h"
19 SystemSettingsProvider::SystemSettingsProvider(
20 const NotifyObserversCallback
& notify_cb
)
21 : CrosSettingsProvider(notify_cb
) {
22 system::TimezoneSettings
*timezone_settings
=
23 system::TimezoneSettings::GetInstance();
24 timezone_settings
->AddObserver(this);
25 timezone_value_
.reset(new base::StringValue(
26 timezone_settings
->GetCurrentTimezoneID()));
29 SystemSettingsProvider::~SystemSettingsProvider() {
30 system::TimezoneSettings::GetInstance()->RemoveObserver(this);
33 void SystemSettingsProvider::DoSet(const std::string
& path
,
34 const base::Value
& in_value
) {
35 // Non-guest users can change the time zone.
36 if (!LoginState::Get()->IsUserAuthenticated())
39 if (path
== kSystemTimezone
) {
40 base::string16 timezone_id
;
41 if (!in_value
.GetAsString(&timezone_id
))
43 // This will call TimezoneChanged.
44 system::TimezoneSettings::GetInstance()->SetTimezoneFromID(timezone_id
);
48 const base::Value
* SystemSettingsProvider::Get(const std::string
& path
) const {
49 if (path
== kSystemTimezone
)
50 return timezone_value_
.get();
54 // The timezone is always trusted.
55 CrosSettingsProvider::TrustedStatus
56 SystemSettingsProvider::PrepareTrustedValues(const base::Closure
& cb
) {
60 bool SystemSettingsProvider::HandlesSetting(const std::string
& path
) const {
61 return path
== kSystemTimezone
;
64 void SystemSettingsProvider::TimezoneChanged(const icu::TimeZone
& timezone
) {
65 // Fires system setting change notification.
66 timezone_value_
.reset(new base::StringValue(
67 system::TimezoneSettings::GetTimezoneID(timezone
)));
68 NotifyObservers(kSystemTimezone
);
71 scoped_ptr
<content::RenderWidgetHostIterator
> widgets(
72 content::RenderWidgetHost::GetRenderWidgetHosts());
73 while (content::RenderWidgetHost
* widget
= widgets
->GetNextHost()) {
74 if (widget
->IsRenderView()) {
75 content::RenderViewHost
* view
= content::RenderViewHost::From(widget
);
76 view
->NotifyTimezoneChange();
81 } // namespace chromeos