Chromium Code Reviews| Index: chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator.cc |
| diff --git a/chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator.cc b/chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..10febeb90b67c30e4d6489c269515e398b1865f7 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator.cc |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator.h" |
| + |
| +#include "base/bind.h" |
| +#include "chrome/browser/chromeos/login/screens/arc_terms_of_service_screen_actor.h" |
| +#include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| +#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
| + |
| +namespace arc { |
| + |
| +namespace { |
| + |
| +chromeos::ArcTermsOfServiceScreenActor* actor_for_testing = nullptr; |
|
hidehiko
2017/01/31 13:55:30
Oops, sorry I overlooked in prev iteration...
Glob
khmel
2017/01/31 15:25:22
I got many comments from other reviewers that g_ i
|
| + |
| +chromeos::ArcTermsOfServiceScreenActor* GetScreenActor() { |
| + // Inject testing instance. |
| + if (actor_for_testing) |
| + return actor_for_testing; |
| + |
| + chromeos::LoginDisplayHost* host = chromeos::LoginDisplayHost::default_host(); |
| + if (!host) |
|
hidehiko
2017/01/31 13:55:30
Considering the DCHECK at L47, this should not hap
khmel
2017/01/31 15:25:22
Done.
|
| + return nullptr; |
| + DCHECK(host->GetOobeUI()); |
| + return host->GetOobeUI()->GetArcTermsOfServiceScreenActor(); |
| +} |
| + |
| +} // namespace |
| + |
| +// static |
| +void ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( |
| + chromeos::ArcTermsOfServiceScreenActor* actor) { |
| + actor_for_testing = actor; |
| +} |
| + |
| +ArcTermsOfServiceOobeNegotiator::ArcTermsOfServiceOobeNegotiator() = default; |
| + |
| +ArcTermsOfServiceOobeNegotiator::~ArcTermsOfServiceOobeNegotiator() { |
| + DCHECK(!screen_actor_); |
| +} |
| + |
| +void ArcTermsOfServiceOobeNegotiator::StartNegotiationImpl() { |
| + DCHECK(!screen_actor_); |
| + screen_actor_ = GetScreenActor(); |
| + DCHECK(screen_actor_); |
| + screen_actor_->AddObserver(this); |
| +} |
| + |
| +void ArcTermsOfServiceOobeNegotiator::HandleTermsAccepted(bool accepted) { |
| + DCHECK(screen_actor_); |
| + screen_actor_->RemoveObserver(this); |
| + screen_actor_ = nullptr; |
| + ReportResult(accepted); |
| +} |
| + |
| +void ArcTermsOfServiceOobeNegotiator::OnSkip() { |
| + HandleTermsAccepted(false); |
| +} |
| + |
| +void ArcTermsOfServiceOobeNegotiator::OnAccept() { |
| + HandleTermsAccepted(true); |
| +} |
| + |
| +void ArcTermsOfServiceOobeNegotiator::OnActorDestroyed( |
| + chromeos::ArcTermsOfServiceScreenActor* actor) { |
| + DCHECK_EQ(actor, screen_actor_); |
| + HandleTermsAccepted(false); |
| +} |
| + |
| +} // namespace arc |