| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/settings/system_settings_provider.h" | 5 #include "chrome/browser/chromeos/settings/system_settings_provider.h" |
| 6 | 6 |
| 7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/system/timezone_util.h" |
| 10 #include "chromeos/login/login_state.h" | 11 #include "chromeos/login/login_state.h" |
| 11 #include "chromeos/settings/cros_settings_names.h" | 12 #include "chromeos/settings/cros_settings_names.h" |
| 12 | 13 |
| 13 namespace chromeos { | 14 namespace chromeos { |
| 14 | 15 |
| 15 SystemSettingsProvider::SystemSettingsProvider( | 16 SystemSettingsProvider::SystemSettingsProvider( |
| 16 const NotifyObserversCallback& notify_cb) | 17 const NotifyObserversCallback& notify_cb) |
| 17 : CrosSettingsProvider(notify_cb) { | 18 : CrosSettingsProvider(notify_cb) { |
| 18 system::TimezoneSettings *timezone_settings = | 19 system::TimezoneSettings *timezone_settings = |
| 19 system::TimezoneSettings::GetInstance(); | 20 system::TimezoneSettings::GetInstance(); |
| 20 timezone_settings->AddObserver(this); | 21 timezone_settings->AddObserver(this); |
| 21 timezone_value_.reset( | 22 timezone_value_.reset( |
| 22 new base::Value(timezone_settings->GetCurrentTimezoneID())); | 23 new base::Value(timezone_settings->GetCurrentTimezoneID())); |
| 24 per_user_timezone_enabled_value_.reset( |
| 25 new base::Value(system::PerUserTimezoneEnabled())); |
| 23 } | 26 } |
| 24 | 27 |
| 25 SystemSettingsProvider::~SystemSettingsProvider() { | 28 SystemSettingsProvider::~SystemSettingsProvider() { |
| 26 system::TimezoneSettings::GetInstance()->RemoveObserver(this); | 29 system::TimezoneSettings::GetInstance()->RemoveObserver(this); |
| 27 } | 30 } |
| 28 | 31 |
| 29 void SystemSettingsProvider::DoSet(const std::string& path, | 32 void SystemSettingsProvider::DoSet(const std::string& path, |
| 30 const base::Value& in_value) { | 33 const base::Value& in_value) { |
| 31 // Only non-guest users can change the time zone. | 34 // Only non-guest users can change the time zone. |
| 32 if (LoginState::Get()->IsGuestSessionUser() || | 35 if (LoginState::Get()->IsGuestSessionUser() || |
| 33 LoginState::Get()->IsPublicSessionUser()) { | 36 LoginState::Get()->IsPublicSessionUser()) { |
| 34 return; | 37 return; |
| 35 } | 38 } |
| 36 | 39 |
| 37 if (path == kSystemTimezone) { | 40 if (path == kSystemTimezone) { |
| 38 base::string16 timezone_id; | 41 base::string16 timezone_id; |
| 39 if (!in_value.GetAsString(&timezone_id)) | 42 if (!in_value.GetAsString(&timezone_id)) |
| 40 return; | 43 return; |
| 41 // This will call TimezoneChanged. | 44 // This will call TimezoneChanged. |
| 42 system::TimezoneSettings::GetInstance()->SetTimezoneFromID(timezone_id); | 45 system::TimezoneSettings::GetInstance()->SetTimezoneFromID(timezone_id); |
| 43 } | 46 } |
| 47 // kPerUserTimezoneEnabled is read-only. |
| 44 } | 48 } |
| 45 | 49 |
| 46 const base::Value* SystemSettingsProvider::Get(const std::string& path) const { | 50 const base::Value* SystemSettingsProvider::Get(const std::string& path) const { |
| 47 if (path == kSystemTimezone) | 51 if (path == kSystemTimezone) |
| 48 return timezone_value_.get(); | 52 return timezone_value_.get(); |
| 53 |
| 54 if (path == kPerUserTimezoneEnabled) |
| 55 return per_user_timezone_enabled_value_.get(); |
| 56 |
| 49 return NULL; | 57 return NULL; |
| 50 } | 58 } |
| 51 | 59 |
| 52 // The timezone is always trusted. | 60 // The timezone is always trusted. |
| 53 CrosSettingsProvider::TrustedStatus | 61 CrosSettingsProvider::TrustedStatus |
| 54 SystemSettingsProvider::PrepareTrustedValues(const base::Closure& cb) { | 62 SystemSettingsProvider::PrepareTrustedValues(const base::Closure& cb) { |
| 55 return TRUSTED; | 63 return TRUSTED; |
| 56 } | 64 } |
| 57 | 65 |
| 58 bool SystemSettingsProvider::HandlesSetting(const std::string& path) const { | 66 bool SystemSettingsProvider::HandlesSetting(const std::string& path) const { |
| 59 return path == kSystemTimezone; | 67 return path == kSystemTimezone || path == kPerUserTimezoneEnabled; |
| 60 } | 68 } |
| 61 | 69 |
| 62 void SystemSettingsProvider::TimezoneChanged(const icu::TimeZone& timezone) { | 70 void SystemSettingsProvider::TimezoneChanged(const icu::TimeZone& timezone) { |
| 63 // Fires system setting change notification. | 71 // Fires system setting change notification. |
| 64 timezone_value_.reset( | 72 timezone_value_.reset( |
| 65 new base::Value(system::TimezoneSettings::GetTimezoneID(timezone))); | 73 new base::Value(system::TimezoneSettings::GetTimezoneID(timezone))); |
| 66 NotifyObservers(kSystemTimezone); | 74 NotifyObservers(kSystemTimezone); |
| 67 } | 75 } |
| 68 | 76 |
| 69 } // namespace chromeos | 77 } // namespace chromeos |
| OLD | NEW |