 Chromium Code Reviews
 Chromium Code Reviews Issue 247663003:
  Date and Time dialog for when the clock isn't synced.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 247663003:
  Date and Time dialog for when the clock isn't synced.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| (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 "content/public/browser/web_ui.h" | |
| 21 #include "content/public/browser/web_ui_data_source.h" | |
| 22 #include "content/public/browser/web_ui_message_handler.h" | |
| 23 #include "grit/browser_resources.h" | |
| 24 #include "grit/generated_resources.h" | |
| 25 | |
| 26 namespace chromeos { | |
| 27 | |
| 28 namespace { | |
| 29 | |
| 30 const char kStringsJsFile[] = "strings.js"; | |
| 31 const char kSetTimeCallback[] = "setTimeInSeconds"; | |
| 32 const char kSetTimezoneCallback[] = "setTimezone"; | |
| 
Dan Beam
2014/04/23 17:51:45
just inline these in RegisterMessageCallback()
 
michaelpg
2014/04/24 01:32:23
Done.
 | |
| 33 | |
| 34 class SetTimeMessageHandler : public content::WebUIMessageHandler, | |
| 35 public system::TimezoneSettings::Observer { | |
| 36 public: | |
| 37 SetTimeMessageHandler(); | |
| 38 virtual ~SetTimeMessageHandler(); | |
| 39 | |
| 40 // WebUIMessageHandler: | |
| 41 virtual void RegisterMessages() OVERRIDE; | |
| 42 | |
| 43 private: | |
| 
stevenjb
2014/04/23 21:32:04
// system::TimezoneSettings::Observer
 
michaelpg
2014/04/24 01:32:23
Done.
 | |
| 44 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE; | |
| 45 void OnSetTime(const base::ListValue* args); | |
| 46 void OnSetTimezone(const base::ListValue* args); | |
| 
Dan Beam
2014/04/23 17:51:45
DISALLOW_COPY_AND_ASSIGN(SetTimeMessageHandler); (
 
michaelpg
2014/04/24 01:32:23
Done.
 | |
| 47 }; | |
| 48 | |
| 49 SetTimeMessageHandler::SetTimeMessageHandler() { | |
| 
Dan Beam
2014/04/23 17:51:45
just put the implementations right after the metho
 
michaelpg
2014/04/24 01:32:23
We try to avoid inlining most functions.
 
stevenjb
2014/04/24 17:06:23
Actually, that is something of a judgement call. W
 
michaelpg
2014/04/24 18:52:31
The C++ Do's & Dont's file has a few arguments for
 
Dan Beam
2014/04/24 21:32:23
i think it'll result in shorter, simpler code (whi
 
michaelpg
2014/04/24 22:42:47
Done.
 | |
| 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 kSetTimeCallback, | |
| 60 base::Bind(&SetTimeMessageHandler::OnSetTime, | |
| 61 base::Unretained(this))); | |
| 62 web_ui()->RegisterMessageCallback( | |
| 63 kSetTimezoneCallback, | |
| 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)) | |
| 
Dan Beam
2014/04/23 17:51:45
DCHECK() or CHECK() or NOTREACHED() (as this is pr
 
michaelpg
2014/04/24 01:32:23
Done.
 | |
| 71 return; | |
| 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 return; | |
| 
stevenjb
2014/04/23 21:32:04
NOTREACHED() instead of return
 
michaelpg
2014/04/24 01:32:23
Done.
 | |
| 80 | |
| 81 CrosSettings::Get()->SetString(kSystemTimezone, timezone_id); | |
| 82 } | |
| 83 | |
| 84 | |
| 85 void SetTimeMessageHandler::TimezoneChanged(const icu::TimeZone& timezone) { | |
| 86 base::StringValue timezone_id( | |
| 87 system::TimezoneSettings::GetTimezoneID(timezone)); | |
| 88 web_ui()->CallJavascriptFunction( | |
| 89 "setTime.TimeSetter.setTimezone", timezone_id); | |
| 90 } | |
| 91 | |
| 92 } // namespace | |
| 93 | |
| 94 SetTimeUI::SetTimeUI(content::WebUI* web_ui) : WebDialogUI(web_ui) { | |
| 95 web_ui->AddMessageHandler(new SetTimeMessageHandler()); | |
| 
Dan Beam
2014/04/23 17:51:45
indent off
 
michaelpg
2014/04/24 01:32:23
Done.
 | |
| 96 | |
| 97 // Set up the chrome://set-time source. | |
| 98 content::WebUIDataSource* source = | |
| 99 content::WebUIDataSource::Create(chrome::kChromeUISetTimeHost); | |
| 100 source->SetUseJsonJSFormatV2(); | |
| 101 | |
| 102 source->AddLocalizedString("setTimeTitle", IDS_SET_TIME_TITLE); | |
| 103 source->AddLocalizedString("prompt", IDS_SET_TIME_PROMPT); | |
| 104 source->AddLocalizedString("doneButton", IDS_SET_TIME_BUTTON_CLOSE); | |
| 105 source->AddLocalizedString("timezone", | |
| 106 IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION); | |
| 107 | |
| 108 base::DictionaryValue values; | |
| 109 values.Set("timezoneList", chromeos::system::GetTimezoneList().release()); | |
| 110 | |
| 111 // If we are logged in, the dialog launched from the settings page. | |
| 
stevenjb
2014/04/23 21:32:04
dialog was launched
 
michaelpg
2014/04/24 01:32:23
Done.
 | |
| 112 // Don't show the timezone dropdown in that case. | |
| 113 std::string current_timezone_id; | |
| 114 ash::user::LoginStatus login_status = | |
| 115 ash::Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus(); | |
| 116 if (login_status == ash::user::LOGGED_IN_LOCKED || | |
| 117 login_status == ash::user::LOGGED_IN_NONE) { | |
| 
stevenjb
2014/04/23 21:32:04
An easier way to do this is LoginState::Get()->IsU
 
michaelpg
2014/04/24 01:32:23
I'm intentionally using the Ash status. Specifical
 
michaelpg
2014/04/24 18:52:31
OK - so we won't show the dialog at all if the scr
 | |
| 118 CrosSettings::Get()->GetString(kSystemTimezone, ¤t_timezone_id); | |
| 119 } | |
| 120 values.SetString("currentTimezoneId", current_timezone_id); | |
| 121 | |
| 122 base::Time build_time = base::GetBuildTime(); | |
| 123 values.SetDouble("buildTime", build_time.ToJsTime()); | |
| 124 | |
| 125 source->AddLocalizedStrings(values); | |
| 126 source->SetJsonPath(kStringsJsFile); | |
| 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 Profile* profile = Profile::FromWebUI(web_ui); | |
| 133 content::WebUIDataSource::Add(profile, source); | |
| 
Dan Beam
2014/04/23 17:51:45
nit: just inline |profile|, e.g.
  content::WebUI
 
michaelpg
2014/04/24 01:32:23
Done.
 | |
| 134 } | |
| 135 | |
| 136 SetTimeUI::~SetTimeUI() { | |
| 137 } | |
| 138 | |
| 139 } // namespace chromeos | |
| OLD | NEW |