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 3// found in the LICENSE file. 4 5#include "chrome/browser/chromeos/login/screens/eula_screen.h" 6 7#include "base/logging.h" 8#include "chrome/browser/browser_process.h" 9#include "chrome/browser/chromeos/customization_document.h" 10#include "chrome/browser/chromeos/login/screens/screen_observer.h" 11#include "chrome/browser/chromeos/login/wizard_controller.h" 12#include "chromeos/cryptohome/cryptohome_library.h" 13 14namespace chromeos { 15 16EulaScreen::EulaScreen(ScreenObserver* observer, EulaScreenActor* actor) 17 : WizardScreen(observer), actor_(actor), password_fetcher_(this) { 18 DCHECK(actor_); 19 if (actor_) 20 actor_->SetDelegate(this); 21} 22 23EulaScreen::~EulaScreen() { 24 if (actor_) 25 actor_->SetDelegate(NULL); 26} 27 28void EulaScreen::PrepareToShow() { 29 if (actor_) 30 actor_->PrepareToShow(); 31} 32 33void EulaScreen::Show() { 34 // Command to own the TPM. 35 CryptohomeLibrary::Get()->TpmCanAttemptOwnership(); 36 if (actor_) 37 actor_->Show(); 38} 39 40void EulaScreen::Hide() { 41 if (actor_) 42 actor_->Hide(); 43} 44 45std::string EulaScreen::GetName() const { 46 return WizardController::kEulaScreenName; 47} 48 49GURL EulaScreen::GetOemEulaUrl() const { 50 const StartupCustomizationDocument* customization = 51 StartupCustomizationDocument::GetInstance(); 52 if (customization->IsReady()) { 53 // Previously we're using "initial locale" that device initially 54 // booted with out-of-box. http://crbug.com/145142 55 std::string locale = g_browser_process->GetApplicationLocale(); 56 std::string eula_page = customization->GetEULAPage(locale); 57 if (!eula_page.empty()) 58 return GURL(eula_page); 59 60 VLOG(1) << "No eula found for locale: " << locale; 61 } else { 62 LOG(ERROR) << "No manifest found."; 63 } 64 return GURL(); 65} 66 67void EulaScreen::OnExit(bool accepted, bool usage_stats_enabled) { 68 get_screen_observer()->SetUsageStatisticsReporting(usage_stats_enabled); 69 get_screen_observer()->OnExit(accepted 70 ? ScreenObserver::EULA_ACCEPTED 71 : ScreenObserver::EULA_BACK); 72} 73 74void EulaScreen::InitiatePasswordFetch() { 75 if (tpm_password_.empty()) { 76 password_fetcher_.Fetch(); 77 // Will call actor after password has been fetched. 78 } else if (actor_) { 79 actor_->OnPasswordFetched(tpm_password_); 80 } 81} 82 83void EulaScreen::OnPasswordFetched(const std::string& tpm_password) { 84 tpm_password_ = tpm_password; 85 if (actor_) 86 actor_->OnPasswordFetched(tpm_password_); 87} 88 89bool EulaScreen::IsUsageStatsEnabled() const { 90 return get_screen_observer()->GetUsageStatisticsReporting(); 91} 92 93void EulaScreen::OnActorDestroyed(EulaScreenActor* actor) { 94 if (actor_ == actor) 95 actor_ = NULL; 96} 97 98} // namespace chromeos 99