| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/chromeos/login/network_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/network_screen_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/strings/string_number_conversions.h" | |
| 17 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
| 20 #include "base/values.h" | 19 #include "base/values.h" |
| 21 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 21 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 23 #include "chrome/browser/chromeos/base/locale_util.h" | 22 #include "chrome/browser/chromeos/base/locale_util.h" |
| 23 #include "chrome/browser/chromeos/customization_document.h" |
| 24 #include "chrome/browser/chromeos/idle_detector.h" | 24 #include "chrome/browser/chromeos/idle_detector.h" |
| 25 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 25 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 26 #include "chrome/browser/chromeos/login/screens/core_oobe_actor.h" | 26 #include "chrome/browser/chromeos/login/screens/core_oobe_actor.h" |
| 27 #include "chrome/browser/chromeos/login/ui/input_events_blocker.h" | 27 #include "chrome/browser/chromeos/login/ui/input_events_blocker.h" |
| 28 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | |
| 29 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | |
| 30 #include "chrome/browser/chromeos/system/input_device_settings.h" | 28 #include "chrome/browser/chromeos/system/input_device_settings.h" |
| 31 #include "chrome/browser/chromeos/system/timezone_util.h" | 29 #include "chrome/browser/chromeos/system/timezone_util.h" |
| 32 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 30 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
| 33 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler
.h" | 31 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler
.h" |
| 34 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 35 #include "chromeos/chromeos_switches.h" | 33 #include "chromeos/chromeos_switches.h" |
| 36 #include "chromeos/ime/extension_ime_util.h" | 34 #include "chromeos/ime/extension_ime_util.h" |
| 37 #include "chromeos/network/network_handler.h" | 35 #include "chromeos/network/network_handler.h" |
| 38 #include "chromeos/network/network_state_handler.h" | 36 #include "chromeos/network/network_state_handler.h" |
| 39 #include "grit/chromium_strings.h" | 37 #include "grit/chromium_strings.h" |
| 40 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
| 41 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 42 #include "ui/gfx/rect.h" | 40 #include "ui/gfx/rect.h" |
| 43 #include "ui/views/layout/fill_layout.h" | 41 #include "ui/views/layout/fill_layout.h" |
| 44 #include "ui/views/widget/widget.h" | 42 #include "ui/views/widget/widget.h" |
| 45 | 43 |
| 46 namespace { | 44 namespace { |
| 47 | 45 |
| 48 const char kJsScreenPath[] = "login.NetworkScreen"; | 46 const char kJsScreenPath[] = "login.NetworkScreen"; |
| 49 | 47 |
| 50 // JS API callbacks names. | 48 // JS API callbacks names. |
| 51 const char kJsApiNetworkOnExit[] = "networkOnExit"; | 49 const char kJsApiNetworkOnExit[] = "networkOnExit"; |
| 52 const char kJsApiNetworkOnLanguageChanged[] = "networkOnLanguageChanged"; | 50 const char kJsApiNetworkOnLanguageChanged[] = "networkOnLanguageChanged"; |
| 53 const char kJsApiNetworkOnInputMethodChanged[] = "networkOnInputMethodChanged"; | 51 const char kJsApiNetworkOnInputMethodChanged[] = "networkOnInputMethodChanged"; |
| 54 const char kJsApiNetworkOnTimezoneChanged[] = "networkOnTimezoneChanged"; | 52 const char kJsApiNetworkOnTimezoneChanged[] = "networkOnTimezoneChanged"; |
| 55 | 53 |
| 56 const int kDerelectDetectionTimeoutSeconds = 8 * 60 * 60; // 8 hours. | |
| 57 const int kDerelectIdleTimeoutSeconds = 5 * 60; // 5 minutes. | |
| 58 const int kOobeTimerUpdateIntervalSeconds = 5 * 60; // 5 minutes. | |
| 59 | |
| 60 // Returns true if element was inserted. | 54 // Returns true if element was inserted. |
| 61 bool InsertString(const std::string& str, std::set<std::string>& to) { | 55 bool InsertString(const std::string& str, std::set<std::string>& to) { |
| 62 const std::pair<std::set<std::string>::iterator, bool> result = | 56 const std::pair<std::set<std::string>::iterator, bool> result = |
| 63 to.insert(str); | 57 to.insert(str); |
| 64 return result.second; | 58 return result.second; |
| 65 } | 59 } |
| 66 | 60 |
| 67 void AddOptgroupOtherLayouts(base::ListValue* input_methods_list) { | 61 void AddOptgroupOtherLayouts(base::ListValue* input_methods_list) { |
| 68 base::DictionaryValue* optgroup = new base::DictionaryValue; | 62 base::DictionaryValue* optgroup = new base::DictionaryValue; |
| 69 optgroup->SetString( | 63 optgroup->SetString( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 97 | 91 |
| 98 NetworkScreenHandler::NetworkScreenHandler(CoreOobeActor* core_oobe_actor) | 92 NetworkScreenHandler::NetworkScreenHandler(CoreOobeActor* core_oobe_actor) |
| 99 : BaseScreenHandler(kJsScreenPath), | 93 : BaseScreenHandler(kJsScreenPath), |
| 100 screen_(NULL), | 94 screen_(NULL), |
| 101 core_oobe_actor_(core_oobe_actor), | 95 core_oobe_actor_(core_oobe_actor), |
| 102 is_continue_enabled_(false), | 96 is_continue_enabled_(false), |
| 103 show_on_init_(false), | 97 show_on_init_(false), |
| 104 should_reinitialize_language_keyboard_list_(false), | 98 should_reinitialize_language_keyboard_list_(false), |
| 105 weak_ptr_factory_(this) { | 99 weak_ptr_factory_(this) { |
| 106 DCHECK(core_oobe_actor_); | 100 DCHECK(core_oobe_actor_); |
| 107 SetupTimeouts(); | |
| 108 | 101 |
| 109 input_method::InputMethodManager* manager = | 102 input_method::InputMethodManager* manager = |
| 110 input_method::InputMethodManager::Get(); | 103 input_method::InputMethodManager::Get(); |
| 111 manager->AddObserver(this); | 104 manager->AddObserver(this); |
| 112 manager->GetComponentExtensionIMEManager()->AddObserver(this); | 105 manager->GetComponentExtensionIMEManager()->AddObserver(this); |
| 113 } | 106 } |
| 114 | 107 |
| 115 NetworkScreenHandler::~NetworkScreenHandler() { | 108 NetworkScreenHandler::~NetworkScreenHandler() { |
| 116 if (screen_) | 109 if (screen_) |
| 117 screen_->OnActorDestroyed(this); | 110 screen_->OnActorDestroyed(this); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableDemoMode)) | 157 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableDemoMode)) |
| 165 return; | 158 return; |
| 166 if (base::SysInfo::IsRunningOnChromeOS()) { | 159 if (base::SysInfo::IsRunningOnChromeOS()) { |
| 167 std::string track; | 160 std::string track; |
| 168 // We're running on an actual device; if we cannot find our release track | 161 // We're running on an actual device; if we cannot find our release track |
| 169 // value or if the track contains "testimage", don't start demo mode. | 162 // value or if the track contains "testimage", don't start demo mode. |
| 170 if (!base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_TRACK", &track) || | 163 if (!base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_TRACK", &track) || |
| 171 track.find("testimage") != std::string::npos) | 164 track.find("testimage") != std::string::npos) |
| 172 return; | 165 return; |
| 173 } | 166 } |
| 174 | 167 core_oobe_actor_->InitDemoModeDetection(); |
| 175 if (IsDerelict()) | |
| 176 StartIdleDetection(); | |
| 177 else | |
| 178 StartOobeTimer(); | |
| 179 } | 168 } |
| 180 | 169 |
| 181 void NetworkScreenHandler::Hide() { | 170 void NetworkScreenHandler::Hide() { |
| 182 } | 171 } |
| 183 | 172 |
| 184 void NetworkScreenHandler::ShowError(const base::string16& message) { | 173 void NetworkScreenHandler::ShowError(const base::string16& message) { |
| 185 CallJS("showError", message); | 174 CallJS("showError", message); |
| 186 } | 175 } |
| 187 | 176 |
| 188 void NetworkScreenHandler::ClearErrors() { | 177 void NetworkScreenHandler::ClearErrors() { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 250 |
| 262 | 251 |
| 263 // static | 252 // static |
| 264 void NetworkScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { | 253 void NetworkScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { |
| 265 registry->RegisterInt64Pref(prefs::kTimeOnOobe, 0); | 254 registry->RegisterInt64Pref(prefs::kTimeOnOobe, 0); |
| 266 } | 255 } |
| 267 | 256 |
| 268 // NetworkScreenHandler, private: ---------------------------------------------- | 257 // NetworkScreenHandler, private: ---------------------------------------------- |
| 269 | 258 |
| 270 void NetworkScreenHandler::HandleOnExit() { | 259 void NetworkScreenHandler::HandleOnExit() { |
| 271 idle_detector_.reset(); | 260 core_oobe_actor_->StopDemoModeDetection(); |
| 272 ClearErrors(); | 261 ClearErrors(); |
| 273 if (screen_) | 262 if (screen_) |
| 274 screen_->OnContinuePressed(); | 263 screen_->OnContinuePressed(); |
| 275 } | 264 } |
| 276 | 265 |
| 277 struct NetworkScreenHandlerOnLanguageChangedCallbackData { | 266 struct NetworkScreenHandlerOnLanguageChangedCallbackData { |
| 278 explicit NetworkScreenHandlerOnLanguageChangedCallbackData( | 267 explicit NetworkScreenHandlerOnLanguageChangedCallbackData( |
| 279 base::WeakPtr<NetworkScreenHandler>& handler) | 268 base::WeakPtr<NetworkScreenHandler>& handler) |
| 280 : handler_(handler) {} | 269 : handler_(handler) {} |
| 281 | 270 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 339 |
| 351 CrosSettings::Get()->SetString(kSystemTimezone, timezone_id); | 340 CrosSettings::Get()->SetString(kSystemTimezone, timezone_id); |
| 352 } | 341 } |
| 353 | 342 |
| 354 void NetworkScreenHandler::OnSystemTimezoneChanged() { | 343 void NetworkScreenHandler::OnSystemTimezoneChanged() { |
| 355 std::string current_timezone_id; | 344 std::string current_timezone_id; |
| 356 CrosSettings::Get()->GetString(kSystemTimezone, ¤t_timezone_id); | 345 CrosSettings::Get()->GetString(kSystemTimezone, ¤t_timezone_id); |
| 357 CallJS("setTimezone", current_timezone_id); | 346 CallJS("setTimezone", current_timezone_id); |
| 358 } | 347 } |
| 359 | 348 |
| 360 void NetworkScreenHandler::StartIdleDetection() { | |
| 361 if (!idle_detector_.get()) { | |
| 362 idle_detector_.reset( | |
| 363 new IdleDetector(base::Closure(), | |
| 364 base::Bind(&NetworkScreenHandler::OnIdle, | |
| 365 weak_ptr_factory_.GetWeakPtr()))); | |
| 366 } | |
| 367 idle_detector_->Start(derelict_idle_timeout_); | |
| 368 } | |
| 369 | |
| 370 void NetworkScreenHandler::StartOobeTimer() { | |
| 371 oobe_timer_.Start(FROM_HERE, | |
| 372 oobe_timer_update_interval_, | |
| 373 this, | |
| 374 &NetworkScreenHandler::OnOobeTimerUpdate); | |
| 375 } | |
| 376 | |
| 377 void NetworkScreenHandler::OnIdle() { | |
| 378 LoginDisplayHost* host = LoginDisplayHostImpl::default_host(); | |
| 379 host->StartDemoAppLaunch(); | |
| 380 } | |
| 381 | |
| 382 void NetworkScreenHandler::OnOobeTimerUpdate() { | |
| 383 time_on_oobe_ += oobe_timer_update_interval_; | |
| 384 | |
| 385 PrefService* prefs = g_browser_process->local_state(); | |
| 386 prefs->SetInt64(prefs::kTimeOnOobe, time_on_oobe_.InSeconds()); | |
| 387 | |
| 388 if (IsDerelict()) { | |
| 389 oobe_timer_.Stop(); | |
| 390 StartIdleDetection(); | |
| 391 } | |
| 392 } | |
| 393 | |
| 394 void NetworkScreenHandler::SetupTimeouts() { | |
| 395 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | |
| 396 DCHECK(cmdline); | |
| 397 | |
| 398 PrefService* prefs = g_browser_process->local_state(); | |
| 399 time_on_oobe_ = | |
| 400 base::TimeDelta::FromSeconds(prefs->GetInt64(prefs::kTimeOnOobe)); | |
| 401 | |
| 402 int derelict_detection_timeout; | |
| 403 if (!cmdline->HasSwitch(switches::kDerelictDetectionTimeout) || | |
| 404 !base::StringToInt( | |
| 405 cmdline->GetSwitchValueASCII(switches::kDerelictDetectionTimeout), | |
| 406 &derelict_detection_timeout)) { | |
| 407 derelict_detection_timeout = kDerelectDetectionTimeoutSeconds; | |
| 408 } | |
| 409 derelict_detection_timeout_ = | |
| 410 base::TimeDelta::FromSeconds(derelict_detection_timeout); | |
| 411 | |
| 412 int derelict_idle_timeout; | |
| 413 if (!cmdline->HasSwitch(switches::kDerelictIdleTimeout) || | |
| 414 !base::StringToInt( | |
| 415 cmdline->GetSwitchValueASCII(switches::kDerelictIdleTimeout), | |
| 416 &derelict_idle_timeout)) { | |
| 417 derelict_idle_timeout = kDerelectIdleTimeoutSeconds; | |
| 418 } | |
| 419 derelict_idle_timeout_ = base::TimeDelta::FromSeconds(derelict_idle_timeout); | |
| 420 | |
| 421 | |
| 422 int oobe_timer_update_interval; | |
| 423 if (!cmdline->HasSwitch(switches::kOobeTimerInterval) || | |
| 424 !base::StringToInt( | |
| 425 cmdline->GetSwitchValueASCII(switches::kOobeTimerInterval), | |
| 426 &oobe_timer_update_interval)) { | |
| 427 oobe_timer_update_interval = kOobeTimerUpdateIntervalSeconds; | |
| 428 } | |
| 429 oobe_timer_update_interval_ = | |
| 430 base::TimeDelta::FromSeconds(oobe_timer_update_interval); | |
| 431 | |
| 432 // In case we'd be derelict before our timer is set to trigger, reduce | |
| 433 // the interval so we check again when we're scheduled to go derelict. | |
| 434 oobe_timer_update_interval_ = | |
| 435 std::max(std::min(oobe_timer_update_interval_, | |
| 436 derelict_detection_timeout_ - time_on_oobe_), | |
| 437 base::TimeDelta::FromSeconds(0)); | |
| 438 } | |
| 439 | |
| 440 bool NetworkScreenHandler::IsDerelict() { | |
| 441 return time_on_oobe_ >= derelict_detection_timeout_; | |
| 442 } | |
| 443 | |
| 444 base::ListValue* NetworkScreenHandler::GetLanguageList() { | 349 base::ListValue* NetworkScreenHandler::GetLanguageList() { |
| 445 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 350 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 446 input_method::InputMethodManager* manager = | 351 input_method::InputMethodManager* manager = |
| 447 input_method::InputMethodManager::Get(); | 352 input_method::InputMethodManager::Get(); |
| 448 ComponentExtensionIMEManager* comp_manager = | 353 ComponentExtensionIMEManager* comp_manager = |
| 449 manager->GetComponentExtensionIMEManager(); | 354 manager->GetComponentExtensionIMEManager(); |
| 450 input_method::InputMethodDescriptors descriptors; | 355 input_method::InputMethodDescriptors descriptors; |
| 451 if (comp_manager->IsInitialized()) | 356 if (comp_manager->IsInitialized()) |
| 452 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor(); | 357 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor(); |
| 453 base::ListValue* languages_list = | 358 base::ListValue* languages_list = |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 timezone_option->SetString("value", timezone_id); | 525 timezone_option->SetString("value", timezone_id); |
| 621 timezone_option->SetString("title", timezone_name); | 526 timezone_option->SetString("title", timezone_name); |
| 622 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); | 527 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); |
| 623 timezone_list->Append(timezone_option.release()); | 528 timezone_list->Append(timezone_option.release()); |
| 624 } | 529 } |
| 625 | 530 |
| 626 return timezone_list.release(); | 531 return timezone_list.release(); |
| 627 } | 532 } |
| 628 | 533 |
| 629 } // namespace chromeos | 534 } // namespace chromeos |
| OLD | NEW |