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 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())); 24 } 25 26 SystemSettingsProvider::~SystemSettingsProvider() { 27 system::TimezoneSettings::GetInstance()->RemoveObserver(this); 28 } 29 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()) 34 return; 35 36 if (path == kSystemTimezone) { 37 base::string16 timezone_id; 38 if (!in_value.GetAsString(&timezone_id)) 39 return; 40 // This will call TimezoneChanged. 41 system::TimezoneSettings::GetInstance()->SetTimezoneFromID(timezone_id); 42 } 43 } 44 45 const base::Value* SystemSettingsProvider::Get(const std::string& path) const { 46 if (path == kSystemTimezone) 47 return timezone_value_.get(); 48 return NULL; 49 } 50 51 // The timezone is always trusted. 52 CrosSettingsProvider::TrustedStatus 53 SystemSettingsProvider::PrepareTrustedValues(const base::Closure& cb) { 54 return TRUSTED; 55 } 56 57 bool SystemSettingsProvider::HandlesSetting(const std::string& path) const { 58 return path == kSystemTimezone; 59 } 60 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); 66 } 67 68 } // namespace chromeos 69