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