OLD | NEW |
| (Empty) |
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/system_settings_provider.h" | |
6 | |
7 #include "base/string16.h" | |
8 #include "base/time.h" | |
9 #include "base/values.h" | |
10 #include "chrome/browser/chromeos/cros_settings.h" | |
11 #include "chrome/browser/chromeos/cros_settings_names.h" | |
12 #include "chrome/browser/chromeos/login/user_manager.h" | |
13 #include "grit/generated_resources.h" | |
14 #include "ui/base/l10n/l10n_util.h" | |
15 | |
16 namespace chromeos { | |
17 | |
18 SystemSettingsProvider::SystemSettingsProvider( | |
19 const NotifyObserversCallback& notify_cb) | |
20 : CrosSettingsProvider(notify_cb) { | |
21 system::TimezoneSettings *timezone_settings = | |
22 system::TimezoneSettings::GetInstance(); | |
23 timezone_settings->AddObserver(this); | |
24 timezone_value_.reset(base::Value::CreateStringValue( | |
25 timezone_settings->GetCurrentTimezoneID())); | |
26 } | |
27 | |
28 SystemSettingsProvider::~SystemSettingsProvider() { | |
29 system::TimezoneSettings::GetInstance()->RemoveObserver(this); | |
30 } | |
31 | |
32 void SystemSettingsProvider::DoSet(const std::string& path, | |
33 const base::Value& in_value) { | |
34 // Non-guest users can change the time zone. | |
35 if (UserManager::Get()->IsLoggedInAsGuest()) | |
36 return; | |
37 | |
38 if (path == kSystemTimezone) { | |
39 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 | |
47 const 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 | |
55 SystemSettingsProvider::PrepareTrustedValues(const base::Closure& cb) { | |
56 return TRUSTED; | |
57 } | |
58 | |
59 bool SystemSettingsProvider::HandlesSetting(const std::string& path) const { | |
60 return path == kSystemTimezone; | |
61 } | |
62 | |
63 void SystemSettingsProvider::Reload() { | |
64 // TODO(pastarmovj): We can actually cache the timezone here to make returning | |
65 // it faster. | |
66 } | |
67 | |
68 void SystemSettingsProvider::TimezoneChanged(const icu::TimeZone& timezone) { | |
69 // Fires system setting change notification. | |
70 timezone_value_.reset(base::Value::CreateStringValue( | |
71 system::TimezoneSettings::GetTimezoneID(timezone))); | |
72 NotifyObservers(kSystemTimezone); | |
73 } | |
74 | |
75 } // namespace chromeos | |
OLD | NEW |