Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(492)

Side by Side Diff: chrome/browser/ui/webui/chromeos/set_time_ui.cc

Issue 247663003: Date and Time dialog for when the clock isn't synced. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moar edits Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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/ui/webui/chromeos/set_time_ui.h"
6
7 #include "ash/shell.h"
8 #include "ash/system/tray/system_tray_delegate.h"
9 #include "ash/system/user/login_status.h"
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/build_time.h"
13 #include "base/values.h"
14 #include "chrome/browser/chromeos/settings/cros_settings.h"
15 #include "chrome/browser/chromeos/system/timezone_util.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/url_constants.h"
18 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/dbus/system_clock_client.h"
20 #include "chromeos/settings/timezone_settings.h"
21 #include "content/public/browser/web_ui.h"
22 #include "content/public/browser/web_ui_data_source.h"
23 #include "content/public/browser/web_ui_message_handler.h"
24 #include "grit/browser_resources.h"
25 #include "grit/generated_resources.h"
26
27 namespace chromeos {
28
29 namespace {
30
31 class SetTimeMessageHandler : public content::WebUIMessageHandler,
32 public chromeos::SystemClockClient::Observer,
33 public system::TimezoneSettings::Observer {
34 public:
35 SetTimeMessageHandler() {
36 system::TimezoneSettings::GetInstance()->AddObserver(this);
37 };
38
39 virtual ~SetTimeMessageHandler() {
40 system::TimezoneSettings::GetInstance()->RemoveObserver(this);
41 }
42
43 // WebUIMessageHandler:
44 virtual void RegisterMessages() OVERRIDE {
45 web_ui()->RegisterMessageCallback(
46 "setTimeInSeconds",
47 base::Bind(&SetTimeMessageHandler::OnSetTime, base::Unretained(this)));
48 web_ui()->RegisterMessageCallback(
49 "setTimezone",
50 base::Bind(&SetTimeMessageHandler::OnSetTimezone,
51 base::Unretained(this)));
52 }
53
54 private:
55 // system::SystemClockClient::Observer:
56 virtual void SystemClockUpdated() OVERRIDE {
57 web_ui()->CallJavascriptFunction("settime.TimeSetter.updateTime");
58 }
59
60 // system::TimezoneSettings::Observer:
61 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE {
62 base::StringValue timezone_id(
63 system::TimezoneSettings::GetTimezoneID(timezone));
64 web_ui()->CallJavascriptFunction("settime.TimeSetter.setTimezone",
65 timezone_id);
66 }
67
68 // Handler for Javascript call to set the system clock when the user sets a
69 // new time. Expects the time as an integer number of seconds since the
70 // Unix epoch.
71 void OnSetTime(const base::ListValue* args) {
72 int seconds;
73 if (!args->GetInteger(0, &seconds))
74 NOTREACHED();
Dan Beam 2014/04/25 00:05:49 this only fires in debug builds, so either: CHE
stevenjb 2014/04/25 01:41:11 This is a programming error, so we shouldn't handl
Dan Beam 2014/04/25 02:15:53 |seconds| is currently an uninitialized int that c
michaelpg 2014/04/25 02:40:24 Agreed. Worst case scenario is if |seconds| is uni
Dan Beam 2014/04/25 02:44:54 yes
michaelpg 2014/04/25 20:05:14 Done.
75
76 chromeos::DBusThreadManager::Get()->GetSystemClockClient()->SetTime(
77 seconds);
78 }
79
80 // Handler for Javascript call to change the system time zone when the user
81 // selects a new time zone. Expects the time zone ID as a string, as it
82 // appears in the time zone option values.
83 void OnSetTimezone(const base::ListValue* args) {
84 std::string timezone_id;
85 if (!args->GetString(0, &timezone_id))
86 NOTREACHED();
Dan Beam 2014/04/25 00:05:49 same
michaelpg 2014/04/25 20:05:14 Done.
87
88 CrosSettings::Get()->SetString(kSystemTimezone, timezone_id);
89 }
90
91 DISALLOW_COPY_AND_ASSIGN(SetTimeMessageHandler);
92 };
93
94 } // namespace
95
96 SetTimeUI::SetTimeUI(content::WebUI* web_ui) : WebDialogUI(web_ui) {
97 web_ui->AddMessageHandler(new SetTimeMessageHandler());
98
99 // Set up the chrome://set-time source.
100 content::WebUIDataSource* source =
101 content::WebUIDataSource::Create(chrome::kChromeUISetTimeHost);
102 source->SetUseJsonJSFormatV2();
103
104 source->AddLocalizedString("setTimeTitle", IDS_SET_TIME_TITLE);
105 source->AddLocalizedString("prompt", IDS_SET_TIME_PROMPT);
106 source->AddLocalizedString("doneButton", IDS_SET_TIME_BUTTON_CLOSE);
107 source->AddLocalizedString("timezone",
108 IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION);
109
110 base::DictionaryValue values;
111 values.Set("timezoneList", chromeos::system::GetTimezoneList().release());
112
113 // If we are logged in, the dialog was launched from the settings page.
114 // Don't show the timezone dropdown in that case.
115 std::string current_timezone_id;
116 ash::user::LoginStatus login_status =
117 ash::Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus();
118 if (login_status == ash::user::LOGGED_IN_LOCKED ||
119 login_status == ash::user::LOGGED_IN_NONE) {
120 CrosSettings::Get()->GetString(kSystemTimezone, &current_timezone_id);
121 }
122 values.SetString("currentTimezoneId", current_timezone_id);
123 values.SetDouble("buildTime", base::GetBuildTime().ToJsTime());
124
125 source->AddLocalizedStrings(values);
126 source->SetJsonPath("strings.js");
127
128 source->AddResourcePath("set_time.css", IDR_SET_TIME_CSS);
129 source->AddResourcePath("set_time.js", IDR_SET_TIME_JS);
130 source->SetDefaultResource(IDR_SET_TIME_HTML);
131
132 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
133 }
134
135 SetTimeUI::~SetTimeUI() {
136 }
137
138 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698