| 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/chromeos/login/screens/eula_screen.h" | 5 #include "chrome/browser/chromeos/login/screens/eula_screen.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/customization_document.h" | 11 #include "chrome/browser/chromeos/customization_document.h" |
| 10 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" | 12 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" |
| 11 #include "chrome/browser/chromeos/login/wizard_controller.h" | 13 #include "chrome/browser/chromeos/login/screens/eula_view.h" |
| 12 #include "chromeos/dbus/cryptohome_client.h" | 14 #include "chromeos/dbus/cryptohome_client.h" |
| 13 #include "chromeos/dbus/dbus_method_call_status.h" | 15 #include "chromeos/dbus/dbus_method_call_status.h" |
| 14 #include "chromeos/dbus/dbus_thread_manager.h" | 16 #include "chromeos/dbus/dbus_thread_manager.h" |
| 15 | 17 |
| 16 namespace chromeos { | 18 namespace chromeos { |
| 17 | 19 |
| 20 namespace { |
| 21 |
| 22 const char kContextKeyUsageStatsEnabled[] = "usageStatsEnabled"; |
| 23 |
| 24 } // namespace |
| 25 |
| 18 EulaScreen::EulaScreen(BaseScreenDelegate* base_screen_delegate, | 26 EulaScreen::EulaScreen(BaseScreenDelegate* base_screen_delegate, |
| 19 Delegate* delegate, | 27 Delegate* delegate, |
| 20 EulaScreenActor* actor) | 28 EulaView* view) |
| 21 : BaseScreen(base_screen_delegate), | 29 : EulaModel(base_screen_delegate), |
| 22 delegate_(delegate), | 30 delegate_(delegate), |
| 23 actor_(actor), | 31 view_(view), |
| 24 password_fetcher_(this) { | 32 password_fetcher_(this) { |
| 25 DCHECK(actor_); | 33 DCHECK(view_); |
| 26 DCHECK(delegate_); | 34 DCHECK(delegate_); |
| 27 if (actor_) | 35 if (view_) |
| 28 actor_->SetDelegate(this); | 36 view_->Bind(*this); |
| 29 } | 37 } |
| 30 | 38 |
| 31 EulaScreen::~EulaScreen() { | 39 EulaScreen::~EulaScreen() { |
| 32 if (actor_) | 40 if (view_) |
| 33 actor_->SetDelegate(NULL); | 41 view_->Unbind(); |
| 34 } | 42 } |
| 35 | 43 |
| 36 void EulaScreen::PrepareToShow() { | 44 void EulaScreen::PrepareToShow() { |
| 37 if (actor_) | 45 if (view_) |
| 38 actor_->PrepareToShow(); | 46 view_->PrepareToShow(); |
| 39 } | 47 } |
| 40 | 48 |
| 41 void EulaScreen::Show() { | 49 void EulaScreen::Show() { |
| 42 // Command to own the TPM. | 50 // Command to own the TPM. |
| 43 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( | 51 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( |
| 44 EmptyVoidDBusMethodCallback()); | 52 EmptyVoidDBusMethodCallback()); |
| 45 if (actor_) | 53 if (view_) |
| 46 actor_->Show(); | 54 view_->Show(); |
| 47 } | 55 } |
| 48 | 56 |
| 49 void EulaScreen::Hide() { | 57 void EulaScreen::Hide() { |
| 50 if (actor_) | 58 if (view_) |
| 51 actor_->Hide(); | 59 view_->Hide(); |
| 52 } | |
| 53 | |
| 54 std::string EulaScreen::GetName() const { | |
| 55 return WizardController::kEulaScreenName; | |
| 56 } | 60 } |
| 57 | 61 |
| 58 GURL EulaScreen::GetOemEulaUrl() const { | 62 GURL EulaScreen::GetOemEulaUrl() const { |
| 59 const StartupCustomizationDocument* customization = | 63 const StartupCustomizationDocument* customization = |
| 60 StartupCustomizationDocument::GetInstance(); | 64 StartupCustomizationDocument::GetInstance(); |
| 61 if (customization->IsReady()) { | 65 if (customization->IsReady()) { |
| 62 // Previously we're using "initial locale" that device initially | 66 // Previously we're using "initial locale" that device initially |
| 63 // booted with out-of-box. http://crbug.com/145142 | 67 // booted with out-of-box. http://crbug.com/145142 |
| 64 std::string locale = g_browser_process->GetApplicationLocale(); | 68 std::string locale = g_browser_process->GetApplicationLocale(); |
| 65 std::string eula_page = customization->GetEULAPage(locale); | 69 std::string eula_page = customization->GetEULAPage(locale); |
| 66 if (!eula_page.empty()) | 70 if (!eula_page.empty()) |
| 67 return GURL(eula_page); | 71 return GURL(eula_page); |
| 68 | 72 |
| 69 VLOG(1) << "No eula found for locale: " << locale; | 73 VLOG(1) << "No eula found for locale: " << locale; |
| 70 } else { | 74 } else { |
| 71 LOG(ERROR) << "No manifest found."; | 75 LOG(ERROR) << "No manifest found."; |
| 72 } | 76 } |
| 73 return GURL(); | 77 return GURL(); |
| 74 } | 78 } |
| 75 | 79 |
| 76 void EulaScreen::OnExit(bool accepted, bool usage_stats_enabled) { | 80 void EulaScreen::OnAcceptButtonClicked() { |
| 77 if (delegate_) | 81 Finish(BaseScreenDelegate::EULA_ACCEPTED); |
| 78 delegate_->SetUsageStatisticsReporting(usage_stats_enabled); | 82 } |
| 79 Finish(accepted ? BaseScreenDelegate::EULA_ACCEPTED | 83 |
| 80 : BaseScreenDelegate::EULA_BACK); | 84 void EulaScreen::OnBackButtonClicked() { |
| 85 Finish(BaseScreenDelegate::EULA_BACK); |
| 81 } | 86 } |
| 82 | 87 |
| 83 void EulaScreen::InitiatePasswordFetch() { | 88 void EulaScreen::InitiatePasswordFetch() { |
| 84 if (tpm_password_.empty()) { | 89 if (tpm_password_.empty()) { |
| 85 password_fetcher_.Fetch(); | 90 password_fetcher_.Fetch(); |
| 86 // Will call actor after password has been fetched. | 91 // Will call view after password has been fetched. |
| 87 } else if (actor_) { | 92 } else if (view_) { |
| 88 actor_->OnPasswordFetched(tpm_password_); | 93 view_->OnPasswordFetched(tpm_password_); |
| 89 } | 94 } |
| 90 } | 95 } |
| 91 | 96 |
| 92 void EulaScreen::OnPasswordFetched(const std::string& tpm_password) { | 97 void EulaScreen::OnPasswordFetched(const std::string& tpm_password) { |
| 93 tpm_password_ = tpm_password; | 98 tpm_password_ = tpm_password; |
| 94 if (actor_) | 99 if (view_) |
| 95 actor_->OnPasswordFetched(tpm_password_); | 100 view_->OnPasswordFetched(tpm_password_); |
| 96 } | 101 } |
| 97 | 102 |
| 98 bool EulaScreen::IsUsageStatsEnabled() const { | 103 bool EulaScreen::IsUsageStatsEnabled() const { |
| 99 return delegate_ && delegate_->GetUsageStatisticsReporting(); | 104 return delegate_ && delegate_->GetUsageStatisticsReporting(); |
| 100 } | 105 } |
| 101 | 106 |
| 102 void EulaScreen::OnActorDestroyed(EulaScreenActor* actor) { | 107 void EulaScreen::OnViewDestroyed(EulaView* view) { |
| 103 if (actor_ == actor) | 108 if (view_ == view) |
| 104 actor_ = NULL; | 109 view_ = NULL; |
| 110 } |
| 111 |
| 112 void EulaScreen::OnContextKeyUpdated( |
| 113 const ::login::ScreenContext::KeyType& key) { |
| 114 if (key == kContextKeyUsageStatsEnabled && delegate_) { |
| 115 delegate_->SetUsageStatisticsReporting( |
| 116 context_.GetBoolean(kContextKeyUsageStatsEnabled)); |
| 117 } |
| 105 } | 118 } |
| 106 | 119 |
| 107 } // namespace chromeos | 120 } // namespace chromeos |
| OLD | NEW |