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

Side by Side Diff: headless/public/util/in_memory_request_job.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, 4 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
« no previous file with comments | « headless/public/util/in_memory_request_job.h ('k') | headless/test/data/page_one.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "headless/public/util/in_memory_request_job.h"
6
7 #include "base/threading/thread_task_runner_handle.h"
8 #include "headless/public/util/in_memory_protocol_handler.h"
9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h"
11 #include "net/url_request/url_request_status.h"
12
13 namespace headless {
14
15 InMemoryRequestJob::InMemoryRequestJob(
16 net::URLRequest* request,
17 net::NetworkDelegate* network_delegate,
18 const InMemoryProtocolHandler::Response* response)
19 : net::URLRequestJob(request, network_delegate),
20 response_(response),
21 data_offset_(0),
22 weak_factory_(this) {}
23
24 InMemoryRequestJob::~InMemoryRequestJob() {}
25
26 void InMemoryRequestJob::Start() {
27 // Start reading asynchronously so that all error reporting and data
28 // callbacks happen as they would for network requests.
29 base::ThreadTaskRunnerHandle::Get()->PostTask(
30 FROM_HERE,
31 base::Bind(&InMemoryRequestJob::StartAsync, weak_factory_.GetWeakPtr()));
32 }
33
34 void InMemoryRequestJob::StartAsync() {
35 if (!response_) {
36 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
37 net::ERR_FILE_NOT_FOUND));
38 return;
39 }
40 NotifyHeadersComplete();
41 }
42
43 void InMemoryRequestJob::Kill() {
44 weak_factory_.InvalidateWeakPtrs();
45 URLRequestJob::Kill();
46 }
47
48 int InMemoryRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size) {
49 DCHECK(response_);
50 DCHECK_LE(data_offset_, response_->data.size());
51 int remaining =
52 base::checked_cast<int>(response_->data.size() - data_offset_);
53 if (buf_size > remaining)
54 buf_size = remaining;
55 memcpy(buf->data(), response_->data.data() + data_offset_, buf_size);
56 data_offset_ += buf_size;
57 return buf_size;
58 }
59
60 bool InMemoryRequestJob::GetMimeType(std::string* mime_type) const {
61 *mime_type = response_->mime_type;
62 return true;
63 }
64
65 } // namespace headless
OLDNEW
« no previous file with comments | « headless/public/util/in_memory_request_job.h ('k') | headless/test/data/page_one.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698