This source file includes following definitions.
- actor_
- PrepareToShow
- Show
- Hide
- GetName
- OnDecline
- OnAccept
- OnActorDestroyed
- StartDownload
- OnDownloadTimeout
- OnURLFetchComplete
#include "chrome/browser/chromeos/login/screens/terms_of_service_screen.h"
#include <string>
#include "base/location.h"
#include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/screens/screen_observer.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_status.h"
#include "url/gurl.h"
namespace chromeos {
TermsOfServiceScreen::TermsOfServiceScreen(ScreenObserver* screen_observer,
TermsOfServiceScreenActor* actor)
: WizardScreen(screen_observer),
actor_(actor) {
DCHECK(actor_);
if (actor_)
actor_->SetDelegate(this);
}
TermsOfServiceScreen::~TermsOfServiceScreen() {
if (actor_)
actor_->SetDelegate(NULL);
}
void TermsOfServiceScreen::PrepareToShow() {
}
void TermsOfServiceScreen::Show() {
if (!actor_)
return;
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
actor_->SetDomain(connector->GetEnterpriseDomain());
actor_->Show();
StartDownload();
}
void TermsOfServiceScreen::Hide() {
if (actor_)
actor_->Hide();
}
std::string TermsOfServiceScreen::GetName() const {
return WizardController::kTermsOfServiceScreenName;
}
void TermsOfServiceScreen::OnDecline() {
get_screen_observer()->OnExit(ScreenObserver::TERMS_OF_SERVICE_DECLINED);
}
void TermsOfServiceScreen::OnAccept() {
get_screen_observer()->OnExit(ScreenObserver::TERMS_OF_SERVICE_ACCEPTED);
}
void TermsOfServiceScreen::OnActorDestroyed(TermsOfServiceScreenActor* actor) {
if (actor_ == actor)
actor_ = NULL;
}
void TermsOfServiceScreen::StartDownload() {
const PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
std::string terms_of_service_url =
prefs->GetString(prefs::kTermsOfServiceURL);
if (terms_of_service_url.empty()) {
if (actor_)
actor_->OnLoadError();
return;
}
terms_of_service_fetcher_.reset(net::URLFetcher::Create(
GURL(terms_of_service_url), net::URLFetcher::GET, this));
terms_of_service_fetcher_->SetRequestContext(
g_browser_process->system_request_context());
terms_of_service_fetcher_->AddExtraRequestHeader("Accept: text/plain");
terms_of_service_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3);
terms_of_service_fetcher_->Start();
download_timer_.Start(FROM_HERE, base::TimeDelta::FromMinutes(1),
this, &TermsOfServiceScreen::OnDownloadTimeout);
}
void TermsOfServiceScreen::OnDownloadTimeout() {
terms_of_service_fetcher_.reset();
if (actor_)
actor_->OnLoadError();
}
void TermsOfServiceScreen::OnURLFetchComplete(const net::URLFetcher* source) {
if (source != terms_of_service_fetcher_.get()) {
NOTREACHED() << "Callback from foreign URL fetcher";
return;
}
download_timer_.Stop();
scoped_ptr<net::URLFetcher> fetcher(terms_of_service_fetcher_.Pass());
if (!actor_)
return;
std::string terms_of_service;
std::string mime_type;
if (!source->GetStatus().is_success() ||
!source->GetResponseHeaders()->GetMimeType(&mime_type) ||
mime_type != "text/plain" ||
!source->GetResponseAsString(&terms_of_service)) {
actor_->OnLoadError();
} else {
actor_->OnLoadSuccess(terms_of_service);
}
}
}