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

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: 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 virtual ~SetTimeMessageHandler();
37
38 // WebUIMessageHandler:
39 virtual void RegisterMessages() OVERRIDE;
40
41 private:
42 // system::SystemClockClient::Observer:
43 virtual void SystemClockUpdated() OVERRIDE;
44
45 // system::TimezoneSettings::Observer:
46 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE;
47
Dan Beam 2014/04/24 21:54:33 document these (why/how are they called, what are
michaelpg 2014/04/24 22:42:48 Done.
48 void OnSetTime(const base::ListValue* args);
49 void OnSetTimezone(const base::ListValue* args);
50
51 DISALLOW_COPY_AND_ASSIGN(SetTimeMessageHandler);
52 };
53
54 SetTimeMessageHandler::SetTimeMessageHandler() {
55 system::TimezoneSettings::GetInstance()->AddObserver(this);
56 }
57
58 SetTimeMessageHandler::~SetTimeMessageHandler() {
59 system::TimezoneSettings::GetInstance()->RemoveObserver(this);
60 }
61
62 void SetTimeMessageHandler::RegisterMessages() {
63 web_ui()->RegisterMessageCallback(
64 "setTimeInSeconds",
65 base::Bind(&SetTimeMessageHandler::OnSetTime, base::Unretained(this)));
66 web_ui()->RegisterMessageCallback(
67 "setTimezone",
68 base::Bind(&SetTimeMessageHandler::OnSetTimezone,
69 base::Unretained(this)));
70 }
71
72 void SetTimeMessageHandler::OnSetTime(const base::ListValue* args) {
73 int seconds;
74 if (!args->GetInteger(0, &seconds))
75 NOTREACHED();
76
77 chromeos::DBusThreadManager::Get()->GetSystemClockClient()->SetTime(seconds);
78 }
79
80 void SetTimeMessageHandler::OnSetTimezone(const base::ListValue* args) {
81 std::string timezone_id;
82 if (!args->GetString(0, &timezone_id))
83 NOTREACHED();
84
85 CrosSettings::Get()->SetString(kSystemTimezone, timezone_id);
86 }
87
88 void SetTimeMessageHandler::SystemClockUpdated() {
89 web_ui()->CallJavascriptFunction("settime.TimeSetter.updateTime");
90 }
91
92 void SetTimeMessageHandler::TimezoneChanged(const icu::TimeZone& timezone) {
93 base::StringValue timezone_id(
94 system::TimezoneSettings::GetTimezoneID(timezone));
95 web_ui()->CallJavascriptFunction("settime.TimeSetter.setTimezone",
96 timezone_id);
97 }
Dan Beam 2014/04/24 21:54:33 combine private classes in .cc so I don't have to
michaelpg 2014/04/24 22:42:48 Done.
98
99 } // namespace
100
101 SetTimeUI::SetTimeUI(content::WebUI* web_ui) : WebDialogUI(web_ui) {
102 web_ui->AddMessageHandler(new SetTimeMessageHandler());
103
104 // Set up the chrome://set-time source.
105 content::WebUIDataSource* source =
106 content::WebUIDataSource::Create(chrome::kChromeUISetTimeHost);
107 source->SetUseJsonJSFormatV2();
108
109 source->AddLocalizedString("setTimeTitle", IDS_SET_TIME_TITLE);
110 source->AddLocalizedString("prompt", IDS_SET_TIME_PROMPT);
111 source->AddLocalizedString("doneButton", IDS_SET_TIME_BUTTON_CLOSE);
112 source->AddLocalizedString("timezone",
113 IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION);
114
115 base::DictionaryValue values;
116 values.Set("timezoneList", chromeos::system::GetTimezoneList().release());
117
118 // If we are logged in, the dialog was launched from the settings page.
119 // Don't show the timezone dropdown in that case.
120 std::string current_timezone_id;
121 ash::user::LoginStatus login_status =
122 ash::Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus();
123 if (login_status == ash::user::LOGGED_IN_LOCKED ||
124 login_status == ash::user::LOGGED_IN_NONE) {
125 CrosSettings::Get()->GetString(kSystemTimezone, &current_timezone_id);
126 }
127 values.SetString("currentTimezoneId", current_timezone_id);
128
129 base::Time build_time = base::GetBuildTime();
130 values.SetDouble("buildTime", build_time.ToJsTime());
Dan Beam 2014/04/24 21:54:33 nit: values.SetDouble("buildTime", base::GetBui
michaelpg 2014/04/24 22:42:48 Done.
131
132 source->AddLocalizedStrings(values);
133 source->SetJsonPath("strings.js");
134
135 source->AddResourcePath("set_time.css", IDR_SET_TIME_CSS);
136 source->AddResourcePath("set_time.js", IDR_SET_TIME_JS);
137 source->SetDefaultResource(IDR_SET_TIME_HTML);
138
139 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
140 }
141
142 SetTimeUI::~SetTimeUI() {
143 }
144
145 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698