OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/terms_of_service_screen.h" | 5 #include "chrome/browser/chromeos/login/screens/terms_of_service_screen.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
22 #include "net/url_request/url_fetcher.h" | 22 #include "net/url_request/url_fetcher.h" |
23 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
24 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
26 | 26 |
27 namespace chromeos { | 27 namespace chromeos { |
28 | 28 |
29 TermsOfServiceScreen::TermsOfServiceScreen( | 29 TermsOfServiceScreen::TermsOfServiceScreen( |
30 BaseScreenDelegate* base_screen_delegate, | 30 BaseScreenDelegate* base_screen_delegate, |
31 TermsOfServiceScreenActor* actor) | 31 TermsOfServiceScreenView* view) |
32 : BaseScreen(base_screen_delegate, OobeScreen::SCREEN_TERMS_OF_SERVICE), | 32 : BaseScreen(base_screen_delegate, OobeScreen::SCREEN_TERMS_OF_SERVICE), |
33 actor_(actor) { | 33 view_(view) { |
34 DCHECK(actor_); | 34 DCHECK(view_); |
35 if (actor_) | 35 if (view_) |
36 actor_->SetDelegate(this); | 36 view_->SetDelegate(this); |
37 } | 37 } |
38 | 38 |
39 TermsOfServiceScreen::~TermsOfServiceScreen() { | 39 TermsOfServiceScreen::~TermsOfServiceScreen() { |
40 if (actor_) | 40 if (view_) |
41 actor_->SetDelegate(NULL); | 41 view_->SetDelegate(NULL); |
42 } | 42 } |
43 | 43 |
44 void TermsOfServiceScreen::Show() { | 44 void TermsOfServiceScreen::Show() { |
45 if (!actor_) | 45 if (!view_) |
46 return; | 46 return; |
47 | 47 |
48 // Set the domain name whose Terms of Service are being shown. | 48 // Set the domain name whose Terms of Service are being shown. |
49 policy::BrowserPolicyConnectorChromeOS* connector = | 49 policy::BrowserPolicyConnectorChromeOS* connector = |
50 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 50 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
51 actor_->SetDomain(connector->GetEnterpriseDomain()); | 51 view_->SetDomain(connector->GetEnterpriseDomain()); |
52 | 52 |
53 // Show the screen. | 53 // Show the screen. |
54 actor_->Show(); | 54 view_->Show(); |
55 | 55 |
56 // Start downloading the Terms of Service. | 56 // Start downloading the Terms of Service. |
57 StartDownload(); | 57 StartDownload(); |
58 } | 58 } |
59 | 59 |
60 void TermsOfServiceScreen::Hide() { | 60 void TermsOfServiceScreen::Hide() { |
61 if (actor_) | 61 if (view_) |
62 actor_->Hide(); | 62 view_->Hide(); |
63 } | 63 } |
64 | 64 |
65 void TermsOfServiceScreen::OnDecline() { | 65 void TermsOfServiceScreen::OnDecline() { |
66 Finish(BaseScreenDelegate::TERMS_OF_SERVICE_DECLINED); | 66 Finish(BaseScreenDelegate::TERMS_OF_SERVICE_DECLINED); |
67 } | 67 } |
68 | 68 |
69 void TermsOfServiceScreen::OnAccept() { | 69 void TermsOfServiceScreen::OnAccept() { |
70 Finish(BaseScreenDelegate::TERMS_OF_SERVICE_ACCEPTED); | 70 Finish(BaseScreenDelegate::TERMS_OF_SERVICE_ACCEPTED); |
71 } | 71 } |
72 | 72 |
73 void TermsOfServiceScreen::OnActorDestroyed(TermsOfServiceScreenActor* actor) { | 73 void TermsOfServiceScreen::OnViewDestroyed(TermsOfServiceScreenView* view) { |
74 if (actor_ == actor) | 74 if (view_ == view) |
75 actor_ = NULL; | 75 view_ = NULL; |
76 } | 76 } |
77 | 77 |
78 void TermsOfServiceScreen::StartDownload() { | 78 void TermsOfServiceScreen::StartDownload() { |
79 const PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); | 79 const PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); |
80 // If an URL from which the Terms of Service can be downloaded has not been | 80 // If an URL from which the Terms of Service can be downloaded has not been |
81 // set, show an error message to the user. | 81 // set, show an error message to the user. |
82 std::string terms_of_service_url = | 82 std::string terms_of_service_url = |
83 prefs->GetString(prefs::kTermsOfServiceURL); | 83 prefs->GetString(prefs::kTermsOfServiceURL); |
84 if (terms_of_service_url.empty()) { | 84 if (terms_of_service_url.empty()) { |
85 if (actor_) | 85 if (view_) |
86 actor_->OnLoadError(); | 86 view_->OnLoadError(); |
87 return; | 87 return; |
88 } | 88 } |
89 | 89 |
90 // Start downloading the Terms of Service. | 90 // Start downloading the Terms of Service. |
91 terms_of_service_fetcher_ = net::URLFetcher::Create( | 91 terms_of_service_fetcher_ = net::URLFetcher::Create( |
92 GURL(terms_of_service_url), net::URLFetcher::GET, this); | 92 GURL(terms_of_service_url), net::URLFetcher::GET, this); |
93 terms_of_service_fetcher_->SetRequestContext( | 93 terms_of_service_fetcher_->SetRequestContext( |
94 g_browser_process->system_request_context()); | 94 g_browser_process->system_request_context()); |
95 // Request a text/plain MIME type as only plain-text Terms of Service are | 95 // Request a text/plain MIME type as only plain-text Terms of Service are |
96 // accepted. | 96 // accepted. |
97 terms_of_service_fetcher_->AddExtraRequestHeader("Accept: text/plain"); | 97 terms_of_service_fetcher_->AddExtraRequestHeader("Accept: text/plain"); |
98 // Retry up to three times if network changes are detected during the | 98 // Retry up to three times if network changes are detected during the |
99 // download. | 99 // download. |
100 terms_of_service_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3); | 100 terms_of_service_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3); |
101 terms_of_service_fetcher_->Start(); | 101 terms_of_service_fetcher_->Start(); |
102 | 102 |
103 // Abort the download attempt if it takes longer than one minute. | 103 // Abort the download attempt if it takes longer than one minute. |
104 download_timer_.Start(FROM_HERE, base::TimeDelta::FromMinutes(1), | 104 download_timer_.Start(FROM_HERE, base::TimeDelta::FromMinutes(1), |
105 this, &TermsOfServiceScreen::OnDownloadTimeout); | 105 this, &TermsOfServiceScreen::OnDownloadTimeout); |
106 } | 106 } |
107 | 107 |
108 void TermsOfServiceScreen::OnDownloadTimeout() { | 108 void TermsOfServiceScreen::OnDownloadTimeout() { |
109 // Abort the download attempt. | 109 // Abort the download attempt. |
110 terms_of_service_fetcher_.reset(); | 110 terms_of_service_fetcher_.reset(); |
111 | 111 |
112 // Show an error message to the user. | 112 // Show an error message to the user. |
113 if (actor_) | 113 if (view_) |
114 actor_->OnLoadError(); | 114 view_->OnLoadError(); |
115 } | 115 } |
116 | 116 |
117 void TermsOfServiceScreen::OnURLFetchComplete(const net::URLFetcher* source) { | 117 void TermsOfServiceScreen::OnURLFetchComplete(const net::URLFetcher* source) { |
118 if (source != terms_of_service_fetcher_.get()) { | 118 if (source != terms_of_service_fetcher_.get()) { |
119 NOTREACHED() << "Callback from foreign URL fetcher"; | 119 NOTREACHED() << "Callback from foreign URL fetcher"; |
120 return; | 120 return; |
121 } | 121 } |
122 | 122 |
123 download_timer_.Stop(); | 123 download_timer_.Stop(); |
124 | 124 |
125 // Destroy the fetcher when this method returns. | 125 // Destroy the fetcher when this method returns. |
126 std::unique_ptr<net::URLFetcher> fetcher( | 126 std::unique_ptr<net::URLFetcher> fetcher( |
127 std::move(terms_of_service_fetcher_)); | 127 std::move(terms_of_service_fetcher_)); |
128 if (!actor_) | 128 if (!view_) |
129 return; | 129 return; |
130 | 130 |
131 std::string terms_of_service; | 131 std::string terms_of_service; |
132 std::string mime_type; | 132 std::string mime_type; |
133 // If the Terms of Service could not be downloaded, do not have a MIME type of | 133 // If the Terms of Service could not be downloaded, do not have a MIME type of |
134 // text/plain or are empty, show an error message to the user. | 134 // text/plain or are empty, show an error message to the user. |
135 if (!source->GetStatus().is_success() || | 135 if (!source->GetStatus().is_success() || |
136 !source->GetResponseHeaders()->GetMimeType(&mime_type) || | 136 !source->GetResponseHeaders()->GetMimeType(&mime_type) || |
137 mime_type != "text/plain" || | 137 mime_type != "text/plain" || |
138 !source->GetResponseAsString(&terms_of_service)) { | 138 !source->GetResponseAsString(&terms_of_service)) { |
139 actor_->OnLoadError(); | 139 view_->OnLoadError(); |
140 } else { | 140 } else { |
141 // If the Terms of Service were downloaded successfully, show them to the | 141 // If the Terms of Service were downloaded successfully, show them to the |
142 // user. | 142 // user. |
143 actor_->OnLoadSuccess(terms_of_service); | 143 view_->OnLoadSuccess(terms_of_service); |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 } // namespace chromeos | 147 } // namespace chromeos |
OLD | NEW |