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

Unified Diff: chrome/browser/extensions/api/messaging/arc_opt_in_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: cleanup 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/messaging/arc_opt_in_host.cc
diff --git a/chrome/browser/extensions/api/messaging/arc_opt_in_host.cc b/chrome/browser/extensions/api/messaging/arc_opt_in_host.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4f3b18da24c0a1cbf6a47936c9b390d66fdb53b3
--- /dev/null
+++ b/chrome/browser/extensions/api/messaging/arc_opt_in_host.cc
@@ -0,0 +1,74 @@
+// 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/extensions/api/messaging/arc_opt_in_host.h"
+
+#include "base/json/json_reader.h"
+#include "base/json/json_writer.h"
+#include "base/values.h"
+
+namespace {
+const char kAction[] = "action";
+const char kActionFetchAuthCode[] = "fetchAuthCode";
+const char kActionCloseUI[] = "closeUI";
+}
xiyuan 2016/02/11 17:57:20 nit: } // namespace
khmel 2016/02/12 02:45:23 Done.
+
+// static
+const char ArcOptInHost::kHostName[] = "com.google.arc_opt_in";
+
+// static
+const char* const ArcOptInHost::kHostOrigin[] = {
+ "chrome-extension://cnbgggchhmkkdmeppjobngjoejnihlei/"
+};
+
+ArcOptInHost::ArcOptInHost() {
+ arc::ArcAuthService::Get()->AddObserver(this);
+}
+
+ArcOptInHost::~ArcOptInHost() {
+ arc::ArcAuthService::Get()->RemoveObserver(this);
+}
+
+void ArcOptInHost::Start(Client* client) {
+ DCHECK(!client_);
+ client_ = client;
+}
+
+void ArcOptInHost::OnOptInUINeedToClose() {
+ if (!client_)
+ return;
+
+ base::DictionaryValue response;
+ response.SetString(kAction, kActionCloseUI);
+ std::string response_string;
+ base::JSONWriter::Write(response, &response_string);
+ client_->PostMessageFromNativeHost(response_string);
+}
+
+void ArcOptInHost::OnMessage(const std::string& request_string) {
+ scoped_ptr<base::Value> request_value =
+ base::JSONReader::Read(request_string);
+ scoped_ptr<base::DictionaryValue> request(
+ static_cast<base::DictionaryValue*>(request_value.release()));
+ if (!request.get()) {
+ NOTREACHED();
+ return;
+ }
+
+ std::string action;
+ if (!request->GetString(kAction, &action)) {
+ NOTREACHED();
+ return;
+ }
+
+ if (action == kActionFetchAuthCode) {
+ arc::ArcAuthService::Get()->CheckAuthCode();
+ } else {
+ NOTREACHED();
+ }
+}
+
+scoped_refptr<base::SingleThreadTaskRunner> ArcOptInHost::task_runner() const {
+ return base::ThreadTaskRunnerHandle::Get();
+}

Powered by Google App Engine
This is Rietveld 408576698