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

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: Addressed feedback 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 system::TimezoneSettings::Observer {
33 public:
34 SetTimeMessageHandler();
35 virtual ~SetTimeMessageHandler();
36
37 // WebUIMessageHandler:
38 virtual void RegisterMessages() OVERRIDE;
39
40 private:
41 // system::TimezoneSettings::Observer:
42 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE;
43 void OnSetTime(const base::ListValue* args);
44 void OnSetTimezone(const base::ListValue* args);
45
46 DISALLOW_COPY_AND_ASSIGN(SetTimeMessageHandler);
47 };
48
49 SetTimeMessageHandler::SetTimeMessageHandler() {
50 system::TimezoneSettings::GetInstance()->AddObserver(this);
51 }
52
53 SetTimeMessageHandler::~SetTimeMessageHandler() {
54 system::TimezoneSettings::GetInstance()->RemoveObserver(this);
55 }
56
57 void SetTimeMessageHandler::RegisterMessages() {
58 web_ui()->RegisterMessageCallback(
59 "setTimeInSeconds",
60 base::Bind(&SetTimeMessageHandler::OnSetTime,
61 base::Unretained(this)));
62 web_ui()->RegisterMessageCallback(
63 "setTimezone",
64 base::Bind(&SetTimeMessageHandler::OnSetTimezone,
65 base::Unretained(this)));
66 }
67
68 void SetTimeMessageHandler::OnSetTime(const base::ListValue* args) {
69 int seconds;
70 if (!args->GetInteger(0, &seconds))
71 NOTREACHED();
72
73 chromeos::DBusThreadManager::Get()->GetSystemClockClient()->SetTime(seconds);
74 }
75
76 void SetTimeMessageHandler::OnSetTimezone(const base::ListValue* args) {
77 std::string timezone_id;
78 if (!args->GetString(0, &timezone_id))
79 NOTREACHED();
80
81 CrosSettings::Get()->SetString(kSystemTimezone, timezone_id);
82 }
83
84 void SetTimeMessageHandler::TimezoneChanged(const icu::TimeZone& timezone) {
Nikita (slow) 2014/04/24 14:31:53 Do you need the same one OnTimeChanged()?
michaelpg 2014/04/24 18:52:32 Hmm, sure. It's a bit weird because if the time ch
85 base::StringValue timezone_id(
86 system::TimezoneSettings::GetTimezoneID(timezone));
87 web_ui()->CallJavascriptFunction(
88 "settime.TimeSetter.setTimezone", timezone_id);
89 }
90
91 } // namespace
92
93 SetTimeUI::SetTimeUI(content::WebUI* web_ui) : WebDialogUI(web_ui) {
94 web_ui->AddMessageHandler(new SetTimeMessageHandler());
95
96 // Set up the chrome://set-time source.
97 content::WebUIDataSource* source =
98 content::WebUIDataSource::Create(chrome::kChromeUISetTimeHost);
99 source->SetUseJsonJSFormatV2();
100
101 source->AddLocalizedString("setTimeTitle", IDS_SET_TIME_TITLE);
102 source->AddLocalizedString("prompt", IDS_SET_TIME_PROMPT);
103 source->AddLocalizedString("doneButton", IDS_SET_TIME_BUTTON_CLOSE);
104 source->AddLocalizedString("timezone",
105 IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION);
106
107 base::DictionaryValue values;
108 values.Set("timezoneList", chromeos::system::GetTimezoneList().release());
109
110 // If we are logged in, the dialog was launched from the settings page.
111 // Don't show the timezone dropdown in that case.
112 std::string current_timezone_id;
113 ash::user::LoginStatus login_status =
114 ash::Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus();
115 if (login_status == ash::user::LOGGED_IN_LOCKED ||
Nikita (slow) 2014/04/24 14:31:53 Will this dialog be available from lock screen? I
stevenjb 2014/04/24 17:06:23 The logic and the comment above are inverted which
michaelpg 2014/04/24 18:52:32 I didn't realize the Settings button isn't availab
Nikita (slow) 2014/04/25 17:06:18 Do you still need LOGGED_IN_LOCKED here?
michaelpg 2014/04/25 20:05:14 No, it is being removed.
116 login_status == ash::user::LOGGED_IN_NONE) {
117 CrosSettings::Get()->GetString(kSystemTimezone, &current_timezone_id);
118 }
119 values.SetString("currentTimezoneId", current_timezone_id);
120
121 base::Time build_time = base::GetBuildTime();
122 values.SetDouble("buildTime", build_time.ToJsTime());
123
124 source->AddLocalizedStrings(values);
125 source->SetJsonPath("strings.js");
126
127 source->AddResourcePath("set_time.css", IDR_SET_TIME_CSS);
128 source->AddResourcePath("set_time.js", IDR_SET_TIME_JS);
129 source->SetDefaultResource(IDR_SET_TIME_HTML);
130
131 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
132 }
133
134 SetTimeUI::~SetTimeUI() {
135 }
136
137 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698