Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: chrome/browser/chromeos/login/screens/eula_screen.cc

Issue 755203002: Added usage of ScreenContext in EulaScreen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed comments. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chromeos/customization_document.h" 9 #include "chrome/browser/chromeos/customization_document.h"
10 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" 10 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h"
11 #include "chrome/browser/chromeos/login/screens/eula_view.h"
11 #include "chrome/browser/chromeos/login/wizard_controller.h" 12 #include "chrome/browser/chromeos/login/wizard_controller.h"
12 #include "chromeos/dbus/cryptohome_client.h" 13 #include "chromeos/dbus/cryptohome_client.h"
13 #include "chromeos/dbus/dbus_method_call_status.h" 14 #include "chromeos/dbus/dbus_method_call_status.h"
14 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
15 16
16 namespace chromeos { 17 namespace chromeos {
17 18
19 namespace {
20
21 const char kContextKeyUsageStatsEnabled[] = "usageStatsEnabled";
22
23 } // namespace
24
18 EulaScreen::EulaScreen(BaseScreenDelegate* base_screen_delegate, 25 EulaScreen::EulaScreen(BaseScreenDelegate* base_screen_delegate,
19 Delegate* delegate, 26 Delegate* delegate,
20 EulaScreenActor* actor) 27 EulaView* view)
21 : BaseScreen(base_screen_delegate), 28 : EulaModel(base_screen_delegate),
22 delegate_(delegate), 29 delegate_(delegate),
23 actor_(actor), 30 view_(view),
24 password_fetcher_(this) { 31 password_fetcher_(this) {
25 DCHECK(actor_); 32 DCHECK(view_);
26 DCHECK(delegate_); 33 DCHECK(delegate_);
27 if (actor_) 34 if (view_)
28 actor_->SetDelegate(this); 35 view_->SetModel(this);
36
37 subscription_ = context_.AddKeyObserver(
38 kContextKeyUsageStatsEnabled,
39 base::Bind(&EulaScreen::OnUsageStatisticsReportingChanged,
40 base::Unretained(this)));
29 } 41 }
30 42
31 EulaScreen::~EulaScreen() { 43 EulaScreen::~EulaScreen() {
32 if (actor_) 44 if (view_)
33 actor_->SetDelegate(NULL); 45 view_->SetModel(nullptr);
34 } 46 }
35 47
36 void EulaScreen::PrepareToShow() { 48 void EulaScreen::PrepareToShow() {
37 if (actor_) 49 if (view_)
38 actor_->PrepareToShow(); 50 view_->PrepareToShow();
39 } 51 }
40 52
41 void EulaScreen::Show() { 53 void EulaScreen::Show() {
42 // Command to own the TPM. 54 // Command to own the TPM.
43 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( 55 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership(
44 EmptyVoidDBusMethodCallback()); 56 EmptyVoidDBusMethodCallback());
45 if (actor_) 57 if (view_)
46 actor_->Show(); 58 view_->Show();
47 } 59 }
48 60
49 void EulaScreen::Hide() { 61 void EulaScreen::Hide() {
50 if (actor_) 62 if (view_)
51 actor_->Hide(); 63 view_->Hide();
52 } 64 }
53 65
54 std::string EulaScreen::GetName() const { 66 std::string EulaScreen::GetName() const {
55 return WizardController::kEulaScreenName; 67 return WizardController::kEulaScreenName;
56 } 68 }
57 69
58 GURL EulaScreen::GetOemEulaUrl() const { 70 GURL EulaScreen::GetOemEulaUrl() const {
59 const StartupCustomizationDocument* customization = 71 const StartupCustomizationDocument* customization =
60 StartupCustomizationDocument::GetInstance(); 72 StartupCustomizationDocument::GetInstance();
61 if (customization->IsReady()) { 73 if (customization->IsReady()) {
62 // Previously we're using "initial locale" that device initially 74 // Previously we're using "initial locale" that device initially
63 // booted with out-of-box. http://crbug.com/145142 75 // booted with out-of-box. http://crbug.com/145142
64 std::string locale = g_browser_process->GetApplicationLocale(); 76 std::string locale = g_browser_process->GetApplicationLocale();
65 std::string eula_page = customization->GetEULAPage(locale); 77 std::string eula_page = customization->GetEULAPage(locale);
66 if (!eula_page.empty()) 78 if (!eula_page.empty())
67 return GURL(eula_page); 79 return GURL(eula_page);
68 80
69 VLOG(1) << "No eula found for locale: " << locale; 81 VLOG(1) << "No eula found for locale: " << locale;
70 } else { 82 } else {
71 LOG(ERROR) << "No manifest found."; 83 LOG(ERROR) << "No manifest found.";
72 } 84 }
73 return GURL(); 85 return GURL();
74 } 86 }
75 87
76 void EulaScreen::OnExit(bool accepted, bool usage_stats_enabled) { 88 void EulaScreen::OnAcceptButtonClicked() {
77 if (delegate_) 89 Finish(BaseScreenDelegate::EULA_ACCEPTED);
78 delegate_->SetUsageStatisticsReporting(usage_stats_enabled); 90 }
79 Finish(accepted ? BaseScreenDelegate::EULA_ACCEPTED 91
80 : BaseScreenDelegate::EULA_BACK); 92 void EulaScreen::OnBackButtonClicked() {
93 Finish(BaseScreenDelegate::EULA_BACK);
81 } 94 }
82 95
83 void EulaScreen::InitiatePasswordFetch() { 96 void EulaScreen::InitiatePasswordFetch() {
84 if (tpm_password_.empty()) { 97 if (tpm_password_.empty()) {
85 password_fetcher_.Fetch(); 98 password_fetcher_.Fetch();
86 // Will call actor after password has been fetched. 99 // Will call view after password has been fetched.
87 } else if (actor_) { 100 } else if (view_) {
88 actor_->OnPasswordFetched(tpm_password_); 101 view_->OnPasswordFetched(tpm_password_);
89 } 102 }
90 } 103 }
91 104
92 void EulaScreen::OnPasswordFetched(const std::string& tpm_password) { 105 void EulaScreen::OnPasswordFetched(const std::string& tpm_password) {
93 tpm_password_ = tpm_password; 106 tpm_password_ = tpm_password;
94 if (actor_) 107 if (view_)
95 actor_->OnPasswordFetched(tpm_password_); 108 view_->OnPasswordFetched(tpm_password_);
96 } 109 }
97 110
98 bool EulaScreen::IsUsageStatsEnabled() const { 111 bool EulaScreen::IsUsageStatsEnabled() const {
99 return delegate_ && delegate_->GetUsageStatisticsReporting(); 112 return delegate_ && delegate_->GetUsageStatisticsReporting();
100 } 113 }
101 114
102 void EulaScreen::OnActorDestroyed(EulaScreenActor* actor) { 115 void EulaScreen::OnViewDestroyed(EulaView* view) {
103 if (actor_ == actor) 116 if (view_ == view)
104 actor_ = NULL; 117 view_ = NULL;
118 }
119
120 void EulaScreen::OnUsageStatisticsReportingChanged(
121 const ::login::ScreenContext::KeyType& key,
122 const base::Value& value) {
123 bool usage_stats_enabled = false;
124 if (!value.GetAsBoolean(&usage_stats_enabled)) {
125 LOG(ERROR) << "Wrong type for " << kContextKeyUsageStatsEnabled
126 << " context value";
127 } else if (delegate_) {
128 delegate_->SetUsageStatisticsReporting(usage_stats_enabled);
129 }
105 } 130 }
106 131
107 } // namespace chromeos 132 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698