OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "content/browser/loader/stream_resource_handler.h" | |
6 | |
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" | |
15 | |
16 namespace content { | |
17 | |
18 StreamResourceHandler::StreamResourceHandler( | |
19 net::URLRequest* request, | |
20 StreamRegistry* registry, | |
21 const GURL& security_origin) | |
22 : request_(request), | |
23 read_buffer_(NULL) { | |
24 // TODO(zork): Find a way to share this with the blob URL creation in WebKit. | |
25 GURL url(std::string(chrome::kBlobScheme) + ":" + | |
26 security_origin.spec() + base::GenerateGUID()); | |
27 stream_ = new Stream(registry, this, security_origin, url); | |
28 } | |
29 | |
30 StreamResourceHandler::~StreamResourceHandler() { | |
31 } | |
32 | |
33 bool StreamResourceHandler::OnUploadProgress(int request_id, | |
34 uint64 position, | |
35 uint64 size) { | |
36 return true; | |
37 } | |
38 | |
39 bool StreamResourceHandler::OnRequestRedirected(int request_id, | |
40 const GURL& url, | |
41 ResourceResponse* resp, | |
42 bool* defer) { | |
43 return true; | |
44 } | |
45 | |
46 bool StreamResourceHandler::OnResponseStarted(int request_id, | |
47 ResourceResponse* resp, | |
48 bool* defer) { | |
49 return true; | |
50 } | |
51 | |
52 bool StreamResourceHandler::OnWillStart(int request_id, | |
53 const GURL& url, | |
54 bool* defer) { | |
55 return true; | |
56 } | |
57 | |
58 bool StreamResourceHandler::OnWillRead(int request_id, | |
59 net::IOBuffer** buf, | |
60 int* buf_size, | |
61 int min_size) { | |
62 static const int kReadBufSize = 32768; | |
63 | |
64 DCHECK(buf && buf_size); | |
65 if (!read_buffer_) | |
66 read_buffer_ = new net::IOBuffer(kReadBufSize); | |
67 *buf = read_buffer_.get(); | |
68 *buf_size = kReadBufSize; | |
69 | |
70 return true; | |
71 } | |
72 | |
73 bool StreamResourceHandler::OnReadCompleted(int request_id, | |
74 int bytes_read, | |
75 bool* defer) { | |
76 if (!bytes_read) | |
77 return true; | |
78 | |
79 // We have more data to read. | |
80 DCHECK(read_buffer_); | |
81 | |
82 // Release the ownership of the buffer, and store a reference | |
83 // to it. A new one will be allocated in OnWillRead(). | |
84 net::IOBuffer* buffer = NULL; | |
85 read_buffer_.swap(&buffer); | |
86 stream_->AddData(buffer, bytes_read); | |
87 | |
88 if (!stream_->can_add_data()) | |
89 *defer = true; | |
90 | |
91 return true; | |
92 } | |
93 | |
94 bool StreamResourceHandler::OnResponseCompleted( | |
95 int request_id, | |
96 const net::URLRequestStatus& urs, | |
darin (slow to review)
2013/03/14 23:27:54
nit: urs -> status
try to avoid uncommon acronyms
Zachary Kuznia
2013/03/15 00:22:24
Done.
| |
97 const std::string& sec_info) { | |
98 stream_->Finalize(); | |
99 return urs.status() == net::URLRequestStatus::SUCCESS; | |
100 } | |
101 | |
102 void StreamResourceHandler::OnDataDownloaded( | |
103 int request_id, | |
104 int bytes_downloaded) { | |
105 NOTREACHED(); | |
106 } | |
107 | |
108 void StreamResourceHandler::OnSpaceAvailable(Stream* stream) { | |
109 controller()->Resume(); | |
110 } | |
111 | |
112 } // namespace content | |
113 | |
OLD | NEW |