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 } | |
kinuko
2013/03/13 11:05:59
nit: no need of { } for one-line body
Zachary Kuznia
2013/03/13 11:13:10
Done.
| |
68 *buf = read_buffer_.get(); | |
69 *buf_size = kReadBufSize; | |
70 | |
71 return true; | |
72 } | |
73 | |
74 bool StreamResourceHandler::OnReadCompleted(int request_id, | |
75 int bytes_read, | |
76 bool* defer) { | |
77 if (!bytes_read) | |
78 return true; | |
79 | |
80 // We have more data to read. | |
81 DCHECK(read_buffer_); | |
82 | |
83 // Release the ownership of the buffer, and store a reference | |
84 // to it. A new one will be allocated in OnWillRead(). | |
85 net::IOBuffer* buffer = NULL; | |
86 read_buffer_.swap(&buffer); | |
87 stream_->AddData(buffer, bytes_read); | |
88 | |
89 if (!stream_->can_add_data()) { | |
90 *defer = true; | |
91 } | |
kinuko
2013/03/13 11:05:59
nit: ditto for { }
Zachary Kuznia
2013/03/13 11:13:10
Done.
| |
92 | |
93 return true; | |
94 } | |
95 | |
96 bool StreamResourceHandler::OnResponseCompleted( | |
97 int request_id, | |
98 const net::URLRequestStatus& urs, | |
99 const std::string& sec_info) { | |
100 stream_->Finalize(); | |
101 if (urs.status() != net::URLRequestStatus::SUCCESS) | |
kinuko
2013/03/13 11:05:59
nit: return urs.status() == net::URLRequestStatus:
Zachary Kuznia
2013/03/13 11:13:10
Done.
| |
102 return false; | |
103 | |
104 return true; | |
105 } | |
106 | |
107 void StreamResourceHandler::OnDataDownloaded( | |
108 int request_id, | |
109 int bytes_downloaded) { | |
110 NOTREACHED(); | |
111 } | |
112 | |
113 void StreamResourceHandler::OnSpaceAvailable(Stream* stream) { | |
114 controller()->Resume(); | |
115 } | |
116 | |
117 } // namespace content | |
118 | |
OLD | NEW |