Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / loader / stream_resource_handler.cc
blob82fc9c63a98e352bf818f47f841a30138d9b28a0
1 // Copyright (c) 2013 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.
5 #include "content/browser/loader/stream_resource_handler.h"
7 #include "base/guid.h"
8 #include "base/logging.h"
9 #include "content/browser/streams/stream.h"
10 #include "content/browser/streams/stream_registry.h"
11 #include "content/public/browser/resource_controller.h"
12 #include "content/public/common/url_constants.h"
13 #include "net/base/io_buffer.h"
14 #include "net/url_request/url_request_status.h"
16 namespace content {
18 StreamResourceHandler::StreamResourceHandler(net::URLRequest* request,
19 StreamRegistry* registry,
20 const GURL& origin)
21 : ResourceHandler(request),
22 read_buffer_(NULL) {
23 // TODO(tyoshino): Find a way to share this with the blob URL creation in
24 // WebKit.
25 GURL url(std::string(kBlobScheme) + ":" + origin.spec() +
26 base::GenerateGUID());
27 stream_ = new Stream(registry, this, url);
30 StreamResourceHandler::~StreamResourceHandler() {
31 stream_->RemoveWriteObserver(this);
34 bool StreamResourceHandler::OnUploadProgress(int request_id,
35 uint64 position,
36 uint64 size) {
37 return true;
40 bool StreamResourceHandler::OnRequestRedirected(int request_id,
41 const GURL& url,
42 ResourceResponse* resp,
43 bool* defer) {
44 return true;
47 bool StreamResourceHandler::OnResponseStarted(int request_id,
48 ResourceResponse* resp,
49 bool* defer) {
50 return true;
53 bool StreamResourceHandler::OnWillStart(int request_id,
54 const GURL& url,
55 bool* defer) {
56 return true;
59 bool StreamResourceHandler::OnBeforeNetworkStart(int request_id,
60 const GURL& url,
61 bool* defer) {
62 return true;
65 bool StreamResourceHandler::OnWillRead(int request_id,
66 scoped_refptr<net::IOBuffer>* buf,
67 int* buf_size,
68 int min_size) {
69 static const int kReadBufSize = 32768;
71 DCHECK(buf && buf_size);
72 if (!read_buffer_.get())
73 read_buffer_ = new net::IOBuffer(kReadBufSize);
74 *buf = read_buffer_.get();
75 *buf_size = kReadBufSize;
77 return true;
80 bool StreamResourceHandler::OnReadCompleted(int request_id,
81 int bytes_read,
82 bool* defer) {
83 if (!bytes_read)
84 return true;
86 // We have more data to read.
87 DCHECK(read_buffer_.get());
89 // Release the ownership of the buffer, and store a reference
90 // to it. A new one will be allocated in OnWillRead().
91 net::IOBuffer* buffer = NULL;
92 read_buffer_.swap(&buffer);
93 stream_->AddData(buffer, bytes_read);
95 if (!stream_->can_add_data())
96 *defer = true;
98 return true;
101 void StreamResourceHandler::OnResponseCompleted(
102 int request_id,
103 const net::URLRequestStatus& status,
104 const std::string& sec_info,
105 bool* defer) {
106 stream_->Finalize();
109 void StreamResourceHandler::OnDataDownloaded(
110 int request_id,
111 int bytes_downloaded) {
112 NOTREACHED();
115 void StreamResourceHandler::OnSpaceAvailable(Stream* stream) {
116 controller()->Resume();
119 void StreamResourceHandler::OnClose(Stream* stream) {
120 controller()->Cancel();
123 } // namespace content