| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/login/background_view.h" | 5 #include "chrome/browser/chromeos/login/background_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 : status_area_(NULL), | 78 : status_area_(NULL), |
| 79 os_version_label_(NULL), | 79 os_version_label_(NULL), |
| 80 boot_times_label_(NULL), | 80 boot_times_label_(NULL), |
| 81 progress_bar_(NULL), | 81 progress_bar_(NULL), |
| 82 shutdown_button_(NULL), | 82 shutdown_button_(NULL), |
| 83 #if defined(OFFICIAL_BUILD) | 83 #if defined(OFFICIAL_BUILD) |
| 84 is_official_build_(true), | 84 is_official_build_(true), |
| 85 #else | 85 #else |
| 86 is_official_build_(false), | 86 is_official_build_(false), |
| 87 #endif | 87 #endif |
| 88 background_area_(NULL) { | 88 background_area_(NULL), |
| 89 version_info_updater_(this) { |
| 89 } | 90 } |
| 90 | 91 |
| 91 BackgroundView::~BackgroundView() {} | 92 BackgroundView::~BackgroundView() { |
| 93 version_info_updater_.set_delegate(NULL); |
| 94 } |
| 92 | 95 |
| 93 void BackgroundView::Init(const GURL& background_url) { | 96 void BackgroundView::Init(const GURL& background_url) { |
| 94 views::Painter* painter = CreateBackgroundPainter(); | 97 views::Painter* painter = CreateBackgroundPainter(); |
| 95 set_background(views::Background::CreateBackgroundPainter(true, painter)); | 98 set_background(views::Background::CreateBackgroundPainter(true, painter)); |
| 96 InitStatusArea(); | 99 InitStatusArea(); |
| 97 InitInfoLabels(); | 100 InitInfoLabels(); |
| 98 if (!background_url.is_empty()) { | 101 if (!background_url.is_empty()) { |
| 99 Profile* profile = ProfileManager::GetDefaultProfile(); | 102 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 100 background_area_ = new DOMView(); | 103 background_area_ = new DOMView(); |
| 101 AddChildView(background_area_); | 104 AddChildView(background_area_); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 } | 300 } |
| 298 | 301 |
| 299 // Overridden from LoginHtmlDialog::Delegate: | 302 // Overridden from LoginHtmlDialog::Delegate: |
| 300 void BackgroundView::OnLocaleChanged() { | 303 void BackgroundView::OnLocaleChanged() { |
| 301 // Proxy settings dialog contains localized strings. | 304 // Proxy settings dialog contains localized strings. |
| 302 proxy_settings_dialog_.reset(); | 305 proxy_settings_dialog_.reset(); |
| 303 InitInfoLabels(); | 306 InitInfoLabels(); |
| 304 SchedulePaint(); | 307 SchedulePaint(); |
| 305 } | 308 } |
| 306 | 309 |
| 310 void BackgroundView::OnOSVersionLabelTextUpdated( |
| 311 const std::string& os_version_label_text) { |
| 312 os_version_label_->SetText(ASCIIToWide(os_version_label_text)); |
| 313 } |
| 314 |
| 315 void BackgroundView::OnBootTimesLabelTextUpdated( |
| 316 const std::string& boot_times_label_text) { |
| 317 boot_times_label_->SetText(ASCIIToWide(boot_times_label_text)); |
| 318 } |
| 319 |
| 307 /////////////////////////////////////////////////////////////////////////////// | 320 /////////////////////////////////////////////////////////////////////////////// |
| 308 // BackgroundView private: | 321 // BackgroundView private: |
| 309 | 322 |
| 310 void BackgroundView::InitStatusArea() { | 323 void BackgroundView::InitStatusArea() { |
| 311 DCHECK(status_area_ == NULL); | 324 DCHECK(status_area_ == NULL); |
| 312 status_area_ = new StatusAreaView(this); | 325 status_area_ = new StatusAreaView(this); |
| 313 status_area_->Init(); | 326 status_area_->Init(); |
| 314 AddChildView(status_area_); | 327 AddChildView(status_area_); |
| 315 } | 328 } |
| 316 | 329 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 335 boot_times_label_ = new views::Label(); | 348 boot_times_label_ = new views::Label(); |
| 336 boot_times_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 349 boot_times_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 337 boot_times_label_->SetColor(kVersionColor); | 350 boot_times_label_->SetColor(kVersionColor); |
| 338 boot_times_label_->SetFont(rb.GetFont(ResourceBundle::SmallFont)); | 351 boot_times_label_->SetFont(rb.GetFont(ResourceBundle::SmallFont)); |
| 339 if (idx < 0) | 352 if (idx < 0) |
| 340 AddChildView(boot_times_label_); | 353 AddChildView(boot_times_label_); |
| 341 else | 354 else |
| 342 AddChildViewAt(boot_times_label_, idx); | 355 AddChildViewAt(boot_times_label_, idx); |
| 343 } | 356 } |
| 344 | 357 |
| 345 if (CrosLibrary::Get()->EnsureLoaded()) { | 358 version_info_updater_.StartUpdate(is_official_build_); |
| 346 version_loader_.EnablePlatformVersions(true); | |
| 347 version_loader_.GetVersion( | |
| 348 &version_consumer_, | |
| 349 NewCallback(this, &BackgroundView::OnVersion), | |
| 350 is_official_build_ ? | |
| 351 VersionLoader::VERSION_SHORT_WITH_DATE : | |
| 352 VersionLoader::VERSION_FULL); | |
| 353 if (!is_official_build_) { | |
| 354 boot_times_loader_.GetBootTimes( | |
| 355 &boot_times_consumer_, | |
| 356 NewCallback(this, &BackgroundView::OnBootTimes)); | |
| 357 } | |
| 358 } else { | |
| 359 UpdateVersionLabel(); | |
| 360 } | |
| 361 | |
| 362 policy::CloudPolicySubsystem* cloud_policy = | |
| 363 g_browser_process->browser_policy_connector()-> | |
| 364 device_cloud_policy_subsystem(); | |
| 365 if (cloud_policy) { | |
| 366 // Two-step reset because we want to construct new ObserverRegistrar after | |
| 367 // destruction of old ObserverRegistrar to avoid DCHECK violation because | |
| 368 // of adding existing observer. | |
| 369 cloud_policy_registrar_.reset(); | |
| 370 cloud_policy_registrar_.reset( | |
| 371 new policy::CloudPolicySubsystem::ObserverRegistrar( | |
| 372 cloud_policy, this)); | |
| 373 | |
| 374 // Ensure that we have up-to-date enterprise info in case enterprise policy | |
| 375 // is already fetched and has finished initialization. | |
| 376 UpdateEnterpriseInfo(); | |
| 377 } | |
| 378 } | 359 } |
| 379 | 360 |
| 380 void BackgroundView::InitProgressBar() { | 361 void BackgroundView::InitProgressBar() { |
| 381 std::vector<int> steps; | 362 std::vector<int> steps; |
| 382 steps.push_back(GetStepId(SELECT_NETWORK)); | 363 steps.push_back(GetStepId(SELECT_NETWORK)); |
| 383 #if defined(OFFICIAL_BUILD) | 364 #if defined(OFFICIAL_BUILD) |
| 384 steps.push_back(GetStepId(EULA)); | 365 steps.push_back(GetStepId(EULA)); |
| 385 #endif | 366 #endif |
| 386 steps.push_back(GetStepId(SIGNIN)); | 367 steps.push_back(GetStepId(SIGNIN)); |
| 387 #if defined(OFFICIAL_BUILD) | 368 #if defined(OFFICIAL_BUILD) |
| 388 if (WizardController::IsRegisterScreenDefined()) | 369 if (WizardController::IsRegisterScreenDefined()) |
| 389 steps.push_back(GetStepId(REGISTRATION)); | 370 steps.push_back(GetStepId(REGISTRATION)); |
| 390 #endif | 371 #endif |
| 391 steps.push_back(GetStepId(PICTURE)); | 372 steps.push_back(GetStepId(PICTURE)); |
| 392 progress_bar_ = new OobeProgressBar(steps); | 373 progress_bar_ = new OobeProgressBar(steps); |
| 393 AddChildView(progress_bar_); | 374 AddChildView(progress_bar_); |
| 394 } | 375 } |
| 395 | 376 |
| 396 void BackgroundView::UpdateWindowType() { | 377 void BackgroundView::UpdateWindowType() { |
| 397 std::vector<int> params; | 378 std::vector<int> params; |
| 398 WmIpc::instance()->SetWindowType( | 379 WmIpc::instance()->SetWindowType( |
| 399 GTK_WIDGET(GetNativeWindow()), | 380 GTK_WIDGET(GetNativeWindow()), |
| 400 WM_IPC_WINDOW_LOGIN_BACKGROUND, | 381 WM_IPC_WINDOW_LOGIN_BACKGROUND, |
| 401 ¶ms); | 382 ¶ms); |
| 402 } | 383 } |
| 403 | 384 |
| 404 void BackgroundView::UpdateVersionLabel() { | |
| 405 if (!CrosLibrary::Get()->EnsureLoaded()) { | |
| 406 os_version_label_->SetText( | |
| 407 ASCIIToWide(CrosLibrary::Get()->load_error_string())); | |
| 408 return; | |
| 409 } | |
| 410 | |
| 411 if (version_text_.empty()) | |
| 412 return; | |
| 413 | |
| 414 chrome::VersionInfo version_info; | |
| 415 std::string label_text = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME); | |
| 416 label_text += ' '; | |
| 417 label_text += version_info.Version(); | |
| 418 label_text += " ("; | |
| 419 // TODO(rkc): Fix this for RTL. | |
| 420 // http://code.google.com/p/chromium-os/issues/detail?id=17621 | |
| 421 label_text += l10n_util::GetStringUTF8(IDS_PLATFORM_LABEL); | |
| 422 label_text += ' '; | |
| 423 label_text += version_text_; | |
| 424 label_text += ')'; | |
| 425 | |
| 426 if (!enterprise_domain_text_.empty()) { | |
| 427 label_text += ' '; | |
| 428 if (enterprise_status_text_.empty()) { | |
| 429 label_text += l10n_util::GetStringFUTF8( | |
| 430 IDS_LOGIN_MANAGED_BY_LABEL_FORMAT, | |
| 431 UTF8ToUTF16(enterprise_domain_text_)); | |
| 432 } else { | |
| 433 label_text += l10n_util::GetStringFUTF8( | |
| 434 IDS_LOGIN_MANAGED_BY_WITH_STATUS_LABEL_FORMAT, | |
| 435 UTF8ToUTF16(enterprise_domain_text_), | |
| 436 UTF8ToUTF16(enterprise_status_text_)); | |
| 437 } | |
| 438 } | |
| 439 | |
| 440 // Workaround over incorrect width calculation in old fonts. | |
| 441 // TODO(glotov): remove the following line when new fonts are used. | |
| 442 label_text += ' '; | |
| 443 | |
| 444 os_version_label_->SetText(UTF8ToWide(label_text)); | |
| 445 } | |
| 446 | |
| 447 void BackgroundView::UpdateEnterpriseInfo() { | |
| 448 policy::BrowserPolicyConnector* policy_connector = | |
| 449 g_browser_process->browser_policy_connector(); | |
| 450 | |
| 451 std::string status_text; | |
| 452 policy::CloudPolicySubsystem* cloud_policy_subsystem = | |
| 453 policy_connector->device_cloud_policy_subsystem(); | |
| 454 if (cloud_policy_subsystem) { | |
| 455 switch (cloud_policy_subsystem->state()) { | |
| 456 case policy::CloudPolicySubsystem::UNENROLLED: | |
| 457 status_text = l10n_util::GetStringUTF8( | |
| 458 IDS_LOGIN_MANAGED_BY_STATUS_PENDING); | |
| 459 break; | |
| 460 case policy::CloudPolicySubsystem::UNMANAGED: | |
| 461 case policy::CloudPolicySubsystem::BAD_GAIA_TOKEN: | |
| 462 case policy::CloudPolicySubsystem::LOCAL_ERROR: | |
| 463 status_text = l10n_util::GetStringUTF8( | |
| 464 IDS_LOGIN_MANAGED_BY_STATUS_LOST_CONNECTION); | |
| 465 break; | |
| 466 case policy::CloudPolicySubsystem::NETWORK_ERROR: | |
| 467 status_text = l10n_util::GetStringUTF8( | |
| 468 IDS_LOGIN_MANAGED_BY_STATUS_NETWORK_ERROR); | |
| 469 break; | |
| 470 case policy::CloudPolicySubsystem::TOKEN_FETCHED: | |
| 471 case policy::CloudPolicySubsystem::SUCCESS: | |
| 472 break; | |
| 473 } | |
| 474 } | |
| 475 | |
| 476 SetEnterpriseInfo(policy_connector->GetEnterpriseDomain(), status_text); | |
| 477 } | |
| 478 | |
| 479 void BackgroundView::SetEnterpriseInfo(const std::string& domain_name, | |
| 480 const std::string& status_text) { | |
| 481 if (domain_name != enterprise_domain_text_ || | |
| 482 status_text != enterprise_status_text_) { | |
| 483 enterprise_domain_text_ = domain_name; | |
| 484 enterprise_status_text_ = status_text; | |
| 485 UpdateVersionLabel(); | |
| 486 } | |
| 487 } | |
| 488 | |
| 489 void BackgroundView::OnVersion( | |
| 490 VersionLoader::Handle handle, std::string version) { | |
| 491 version_text_.swap(version); | |
| 492 UpdateVersionLabel(); | |
| 493 } | |
| 494 | |
| 495 void BackgroundView::OnBootTimes( | |
| 496 BootTimesLoader::Handle handle, BootTimesLoader::BootTimes boot_times) { | |
| 497 const char* kBootTimesNoChromeExec = | |
| 498 "Non-firmware boot took %.2f seconds (kernel %.2fs, system %.2fs)"; | |
| 499 const char* kBootTimesChromeExec = | |
| 500 "Non-firmware boot took %.2f seconds " | |
| 501 "(kernel %.2fs, system %.2fs, chrome %.2fs)"; | |
| 502 std::string boot_times_text; | |
| 503 | |
| 504 if (boot_times.chrome > 0) { | |
| 505 boot_times_text = | |
| 506 base::StringPrintf( | |
| 507 kBootTimesChromeExec, | |
| 508 boot_times.total, | |
| 509 boot_times.pre_startup, | |
| 510 boot_times.system, | |
| 511 boot_times.chrome); | |
| 512 } else { | |
| 513 boot_times_text = | |
| 514 base::StringPrintf( | |
| 515 kBootTimesNoChromeExec, | |
| 516 boot_times.total, | |
| 517 boot_times.pre_startup, | |
| 518 boot_times.system); | |
| 519 } | |
| 520 // Use UTF8ToWide once this string is localized. | |
| 521 boot_times_label_->SetText(ASCIIToWide(boot_times_text)); | |
| 522 } | |
| 523 | |
| 524 void BackgroundView::OnPolicyStateChanged( | |
| 525 policy::CloudPolicySubsystem::PolicySubsystemState state, | |
| 526 policy::CloudPolicySubsystem::ErrorDetails error_details) { | |
| 527 UpdateEnterpriseInfo(); | |
| 528 } | |
| 529 | |
| 530 } // namespace chromeos | 385 } // namespace chromeos |
| OLD | NEW |