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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/chromeos/set_time_ui.cc
diff --git a/chrome/browser/ui/webui/chromeos/set_time_ui.cc b/chrome/browser/ui/webui/chromeos/set_time_ui.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fac4b05f023e5ece15ddd32161733c85d20a9eb8
--- /dev/null
+++ b/chrome/browser/ui/webui/chromeos/set_time_ui.cc
@@ -0,0 +1,138 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/chromeos/set_time_ui.h"
+
+#include "ash/shell.h"
+#include "ash/system/tray/system_tray_delegate.h"
+#include "ash/system/user/login_status.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/build_time.h"
+#include "base/values.h"
+#include "chrome/browser/chromeos/settings/cros_settings.h"
+#include "chrome/browser/chromeos/system/timezone_util.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/url_constants.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/system_clock_client.h"
+#include "chromeos/settings/timezone_settings.h"
+#include "content/public/browser/web_ui.h"
+#include "content/public/browser/web_ui_data_source.h"
+#include "content/public/browser/web_ui_message_handler.h"
+#include "grit/browser_resources.h"
+#include "grit/generated_resources.h"
+
+namespace chromeos {
+
+namespace {
+
+class SetTimeMessageHandler : public content::WebUIMessageHandler,
+ public chromeos::SystemClockClient::Observer,
+ public system::TimezoneSettings::Observer {
+ public:
+ SetTimeMessageHandler() {
+ system::TimezoneSettings::GetInstance()->AddObserver(this);
+ };
+
+ virtual ~SetTimeMessageHandler() {
+ system::TimezoneSettings::GetInstance()->RemoveObserver(this);
+ }
+
+ // WebUIMessageHandler:
+ virtual void RegisterMessages() OVERRIDE {
+ web_ui()->RegisterMessageCallback(
+ "setTimeInSeconds",
+ base::Bind(&SetTimeMessageHandler::OnSetTime, base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "setTimezone",
+ base::Bind(&SetTimeMessageHandler::OnSetTimezone,
+ base::Unretained(this)));
+ }
+
+ private:
+ // system::SystemClockClient::Observer:
+ virtual void SystemClockUpdated() OVERRIDE {
+ web_ui()->CallJavascriptFunction("settime.TimeSetter.updateTime");
+ }
+
+ // system::TimezoneSettings::Observer:
+ virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE {
+ base::StringValue timezone_id(
+ system::TimezoneSettings::GetTimezoneID(timezone));
+ web_ui()->CallJavascriptFunction("settime.TimeSetter.setTimezone",
+ timezone_id);
+ }
+
+ // Handler for Javascript call to set the system clock when the user sets a
+ // new time. Expects the time as an integer number of seconds since the
+ // Unix epoch.
+ void OnSetTime(const base::ListValue* args) {
+ int seconds;
+ if (!args->GetInteger(0, &seconds))
+ 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.
+
+ chromeos::DBusThreadManager::Get()->GetSystemClockClient()->SetTime(
+ seconds);
+ }
+
+ // Handler for Javascript call to change the system time zone when the user
+ // selects a new time zone. Expects the time zone ID as a string, as it
+ // appears in the time zone option values.
+ void OnSetTimezone(const base::ListValue* args) {
+ std::string timezone_id;
+ if (!args->GetString(0, &timezone_id))
+ NOTREACHED();
Dan Beam 2014/04/25 00:05:49 same
michaelpg 2014/04/25 20:05:14 Done.
+
+ CrosSettings::Get()->SetString(kSystemTimezone, timezone_id);
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(SetTimeMessageHandler);
+};
+
+} // namespace
+
+SetTimeUI::SetTimeUI(content::WebUI* web_ui) : WebDialogUI(web_ui) {
+ web_ui->AddMessageHandler(new SetTimeMessageHandler());
+
+ // Set up the chrome://set-time source.
+ content::WebUIDataSource* source =
+ content::WebUIDataSource::Create(chrome::kChromeUISetTimeHost);
+ source->SetUseJsonJSFormatV2();
+
+ source->AddLocalizedString("setTimeTitle", IDS_SET_TIME_TITLE);
+ source->AddLocalizedString("prompt", IDS_SET_TIME_PROMPT);
+ source->AddLocalizedString("doneButton", IDS_SET_TIME_BUTTON_CLOSE);
+ source->AddLocalizedString("timezone",
+ IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION);
+
+ base::DictionaryValue values;
+ values.Set("timezoneList", chromeos::system::GetTimezoneList().release());
+
+ // If we are logged in, the dialog was launched from the settings page.
+ // Don't show the timezone dropdown in that case.
+ std::string current_timezone_id;
+ ash::user::LoginStatus login_status =
+ ash::Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus();
+ if (login_status == ash::user::LOGGED_IN_LOCKED ||
+ login_status == ash::user::LOGGED_IN_NONE) {
+ CrosSettings::Get()->GetString(kSystemTimezone, &current_timezone_id);
+ }
+ values.SetString("currentTimezoneId", current_timezone_id);
+ values.SetDouble("buildTime", base::GetBuildTime().ToJsTime());
+
+ source->AddLocalizedStrings(values);
+ source->SetJsonPath("strings.js");
+
+ source->AddResourcePath("set_time.css", IDR_SET_TIME_CSS);
+ source->AddResourcePath("set_time.js", IDR_SET_TIME_JS);
+ source->SetDefaultResource(IDR_SET_TIME_HTML);
+
+ content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
+}
+
+SetTimeUI::~SetTimeUI() {
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698