Home | History | Annotate | Download | only in screens
      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 
     14 namespace chromeos {
     15 
     16 EulaScreen::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 
     23 EulaScreen::~EulaScreen() {
     24   if (actor_)
     25     actor_->SetDelegate(NULL);
     26 }
     27 
     28 void EulaScreen::PrepareToShow() {
     29   if (actor_)
     30     actor_->PrepareToShow();
     31 }
     32 
     33 void EulaScreen::Show() {
     34   // Command to own the TPM.
     35   CryptohomeLibrary::Get()->TpmCanAttemptOwnership();
     36   if (actor_)
     37     actor_->Show();
     38 }
     39 
     40 void EulaScreen::Hide() {
     41   if (actor_)
     42     actor_->Hide();
     43 }
     44 
     45 std::string EulaScreen::GetName() const {
     46   return WizardController::kEulaScreenName;
     47 }
     48 
     49 GURL 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 
     67 void 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 
     74 void 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 
     83 void EulaScreen::OnPasswordFetched(const std::string& tpm_password) {
     84   tpm_password_ = tpm_password;
     85   if (actor_)
     86     actor_->OnPasswordFetched(tpm_password_);
     87 }
     88 
     89 bool EulaScreen::IsUsageStatsEnabled() const {
     90   return get_screen_observer()->GetUsageStatisticsReporting();
     91 }
     92 
     93 void EulaScreen::OnActorDestroyed(EulaScreenActor* actor) {
     94   if (actor_ == actor)
     95     actor_ = NULL;
     96 }
     97 
     98 }  // namespace chromeos
     99