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. 4 5 #include "chrome/browser/chromeos/settings/system_settings_provider.h" 6 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 14 namespace chromeos { 15 SystemSettingsProvider(const NotifyObserversCallback & notify_cb)16SystemSettingsProvider::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())); 24 } 25 ~SystemSettingsProvider()26SystemSettingsProvider::~SystemSettingsProvider() { 27 system::TimezoneSettings::GetInstance()->RemoveObserver(this); 28 } 29 DoSet(const std::string & path,const base::Value & in_value)30void 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()) { 35 return; 36 } 37 38 if (path == kSystemTimezone) { 39 base::string16 timezone_id; 40 if (!in_value.GetAsString(&timezone_id)) 41 return; 42 // This will call TimezoneChanged. 43 system::TimezoneSettings::GetInstance()->SetTimezoneFromID(timezone_id); 44 } 45 } 46 Get(const std::string & path) const47const base::Value* SystemSettingsProvider::Get(const std::string& path) const { 48 if (path == kSystemTimezone) 49 return timezone_value_.get(); 50 return NULL; 51 } 52 53 // The timezone is always trusted. 54 CrosSettingsProvider::TrustedStatus PrepareTrustedValues(const base::Closure & cb)55 SystemSettingsProvider::PrepareTrustedValues(const base::Closure& cb) { 56 return TRUSTED; 57 } 58 HandlesSetting(const std::string & path) const59bool SystemSettingsProvider::HandlesSetting(const std::string& path) const { 60 return path == kSystemTimezone; 61 } 62 TimezoneChanged(const icu::TimeZone & timezone)63void 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); 68 } 69 70 } // namespace chromeos 71