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

Side by Side Diff: chrome/browser/extensions/api/messaging/arc_support_host.cc

Issue 1681813003: arc: Use incognito profile for OptIn and cookie fetcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased, added reseting windowClosedInternally before window creation Created 4 years, 10 months 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 "arc_support_host.h"
6 #include "base/json/json_reader.h"
7 #include "base/json/json_writer.h"
8 #include "base/thread_task_runner_handle.h"
9 #include "base/values.h"
10
11 namespace {
12 const char kAction[] = "action";
13 const char kActionFetchAuthCode[] = "fetchAuthCode";
14 const char kActionCancelAuthCode[] = "cancelAuthCode";
15 const char kActionCloseUI[] = "closeUI";
16 } // namespace
17
18 // static
19 const char ArcSupportHost::kHostName[] = "com.google.arc_support";
20
21 // static
22 const char* const ArcSupportHost::kHostOrigin[] = {
23 "chrome-extension://cnbgggchhmkkdmeppjobngjoejnihlei/"
24 };
25
26 // static
27 scoped_ptr<extensions::NativeMessageHost> ArcSupportHost::Create() {
28 return scoped_ptr<NativeMessageHost>(new ArcSupportHost());
29 }
30
31 ArcSupportHost::ArcSupportHost() {
32 arc::ArcAuthService::Get()->AddObserver(this);
33 }
34
35 ArcSupportHost::~ArcSupportHost() {
36 arc::ArcAuthService::Get()->RemoveObserver(this);
37 }
38
39 void ArcSupportHost::Start(Client* client) {
40 DCHECK(!client_);
41 client_ = client;
42 }
43
44 void ArcSupportHost::OnOptInUINeedToClose() {
45 if (!client_)
46 return;
47
48 base::DictionaryValue response;
49 response.SetString(kAction, kActionCloseUI);
50 std::string response_string;
51 base::JSONWriter::Write(response, &response_string);
52 client_->PostMessageFromNativeHost(response_string);
53 }
54
55 void ArcSupportHost::OnMessage(const std::string& request_string) {
56 scoped_ptr<base::Value> request_value =
57 base::JSONReader::Read(request_string);
58 scoped_ptr<base::DictionaryValue> request(
59 static_cast<base::DictionaryValue*>(request_value.release()));
60 if (!request.get()) {
61 NOTREACHED();
62 return;
63 }
64
65 std::string action;
66 if (!request->GetString(kAction, &action)) {
67 NOTREACHED();
68 return;
69 }
70
71 if (action == kActionFetchAuthCode) {
72 arc::ArcAuthService::Get()->FetchAuthCode();
73 } else if (action == kActionCancelAuthCode) {
74 arc::ArcAuthService::Get()->CancelAuthCode();
75 } else {
76 NOTREACHED();
77 }
78 }
79
80 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner()
81 const {
82 return base::ThreadTaskRunnerHandle::Get();
83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698