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

Side by Side Diff: chrome/browser/chromeos/arc/extensions/fake_arc_support.cc

Issue 2534883002: Extract ArcTermsOfServiceNegotiator implementation. (Closed)
Patch Set: Address comments Created 4 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/arc/extensions/fake_arc_support.h"
6
7 #include <string>
8
9 #include "base/bind.h"
10 #include "base/json/json_reader.h"
11 #include "base/json/json_writer.h"
12 #include "base/logging.h"
13 #include "base/values.h"
14 #include "chrome/browser/chromeos/arc/extensions/arc_support_message_host.h"
15
16 namespace arc {
17
18 FakeArcSupport::FakeArcSupport(ArcSupportHost* support_host)
19 : support_host_(support_host), weak_ptr_factory_(this) {
20 DCHECK(support_host_);
21 support_host_->SetRequestOpenAppCallbackForTesting(
22 base::Bind(&FakeArcSupport::Open, weak_ptr_factory_.GetWeakPtr()));
23 }
24
25 FakeArcSupport::~FakeArcSupport() {
26 // Ensure that message host is disconnected.
27 if (native_message_host_)
28 Close();
29 }
30
31 void FakeArcSupport::Open(Profile* profile) {
32 DCHECK(!native_message_host_);
33 native_message_host_ = ArcSupportMessageHost::Create();
34 native_message_host_->Start(this);
35 support_host_->SetMessageHost(
36 static_cast<ArcSupportMessageHost*>(native_message_host_.get()));
37 }
38
39 void FakeArcSupport::Close() {
40 DCHECK(native_message_host_);
41 native_message_host_->OnMessage("{\"event\": \"onWindowClosed\"}");
42 support_host_->UnsetMessageHost(
43 static_cast<ArcSupportMessageHost*>(native_message_host_.get()));
44 native_message_host_.reset();
45 }
46
47 void FakeArcSupport::ClickAgreeButton() {
48 DCHECK(native_message_host_);
49 DCHECK_EQ(ui_page_, ArcSupportHost::UIPage::TERMS);
50
51 base::DictionaryValue message;
52 message.SetString("event", "onAgreed");
53 message.SetBoolean("isMetricsEnabled", metrics_mode_);
54 message.SetBoolean("isBackupRestoreEnabled", backup_and_restore_mode_);
55 message.SetBoolean("isLocationServiceEnabled", location_service_mode_);
56
57 std::string message_string;
58 if (!base::JSONWriter::Write(message, &message_string)) {
59 NOTREACHED();
60 return;
61 }
62 native_message_host_->OnMessage(message_string);
63 }
64
65 void FakeArcSupport::ClickRetryButton() {
66 DCHECK(native_message_host_);
67 DCHECK_EQ(ui_page_, ArcSupportHost::UIPage::ERROR);
68 native_message_host_->OnMessage("{\"event\": \"onRetryClicked\"}");
69 }
70
71 void FakeArcSupport::PostMessageFromNativeHost(
72 const std::string& message_string) {
73 std::unique_ptr<base::DictionaryValue> message =
74 base::DictionaryValue::From(base::JSONReader::Read(message_string));
75 DCHECK(message);
76
77 std::string action;
78 if (!message->GetString("action", &action)) {
79 NOTREACHED() << message_string;
80 return;
81 }
82
83 if (action == "initialize") {
84 // Do nothing as emulation.
85 } else if (action == "showPage") {
86 std::string page;
87 if (!message->GetString("page", &page)) {
88 NOTREACHED() << message_string;
89 return;
90 }
91 if (page == "terms") {
92 ui_page_ = ArcSupportHost::UIPage::TERMS;
93 } else if (page == "lso-loading") {
94 ui_page_ = ArcSupportHost::UIPage::LSO;
95 } else if (page == "arc-loading") {
96 ui_page_ = ArcSupportHost::UIPage::ARC_LOADING;
97 } else {
98 NOTREACHED() << message_string;
99 }
100 } else if (action == "showErrorPage") {
101 ui_page_ = ArcSupportHost::UIPage::ERROR;
102 } else if (action == "setMetricsMode") {
103 if (!message->GetBoolean("enabled", &metrics_mode_)) {
104 NOTREACHED() << message_string;
105 return;
106 }
107 } else if (action == "setBackupAndRestoreMode") {
108 if (!message->GetBoolean("enabled", &backup_and_restore_mode_)) {
109 NOTREACHED() << message_string;
110 return;
111 }
112 } else if (action == "setLocationServiceMode") {
113 if (!message->GetBoolean("enabled", &location_service_mode_)) {
114 NOTREACHED() << message_string;
115 return;
116 }
117 } else {
118 // Unknown or unsupported action.
119 NOTREACHED() << message_string;
120 }
121 }
122
123 void FakeArcSupport::CloseChannel(const std::string& error_message) {
124 NOTREACHED();
125 }
126
127 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698