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

Unified Diff: headless/public/util/black_hole_protocol_handler.cc

Issue 2049363003: Adds support for headless chrome embedder mojo services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 5 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: headless/public/util/black_hole_protocol_handler.cc
diff --git a/headless/public/util/black_hole_protocol_handler.cc b/headless/public/util/black_hole_protocol_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3f036c597065a000b5f65e1c1e1307e627dd688e
--- /dev/null
+++ b/headless/public/util/black_hole_protocol_handler.cc
@@ -0,0 +1,66 @@
+// 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 "headless/public/util/black_hole_protocol_handler.h"
+
+#include "base/threading/thread_task_runner_handle.h"
+#include "net/base/io_buffer.h"
+#include "net/base/net_errors.h"
+#include "net/url_request/url_request_job.h"
+
+namespace headless {
+namespace {
+class BlackHoleRequestJob : public net::URLRequestJob {
+ public:
+ BlackHoleRequestJob(net::URLRequest* request,
+ net::NetworkDelegate* network_delegate);
+
+ // net::URLRequestJob implementation:
+ void Start() override;
+ void Kill() override;
+
+ private:
+ ~BlackHoleRequestJob() override;
+
+ void StartAsync();
+
+ base::WeakPtrFactory<BlackHoleRequestJob> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(BlackHoleRequestJob);
+};
+
+BlackHoleRequestJob::BlackHoleRequestJob(net::URLRequest* request,
+ net::NetworkDelegate* network_delegate)
+ : net::URLRequestJob(request, network_delegate), weak_factory_(this) {}
+
+BlackHoleRequestJob::~BlackHoleRequestJob() {}
+
+void BlackHoleRequestJob::Start() {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&BlackHoleRequestJob::StartAsync, weak_factory_.GetWeakPtr()));
+}
+
+void BlackHoleRequestJob::StartAsync() {
+ // Fail every request!
+ NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
+ net::ERR_FILE_NOT_FOUND));
+}
+
+void BlackHoleRequestJob::Kill() {
+ weak_factory_.InvalidateWeakPtrs();
+ URLRequestJob::Kill();
+}
+} // namespace
+
+BlackHoleProtocolHandler::BlackHoleProtocolHandler() {}
+BlackHoleProtocolHandler::~BlackHoleProtocolHandler() {}
+
+net::URLRequestJob* BlackHoleProtocolHandler::MaybeCreateJob(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate) const {
+ return new BlackHoleRequestJob(request, network_delegate);
+}
+
+} // namespace headless
« no previous file with comments | « headless/public/util/black_hole_protocol_handler.h ('k') | headless/public/util/in_memory_protocol_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698