OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/loader/stream_resource_handler.h" | 5 #include "content/browser/loader/stream_resource_handler.h" |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/browser/streams/stream.h" | 9 #include "content/browser/streams/stream.h" |
10 #include "content/browser/streams/stream_registry.h" | 10 #include "content/browser/streams/stream_registry.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 return true; | 56 return true; |
57 } | 57 } |
58 | 58 |
59 bool StreamResourceHandler::OnWillRead(int request_id, | 59 bool StreamResourceHandler::OnWillRead(int request_id, |
60 net::IOBuffer** buf, | 60 net::IOBuffer** buf, |
61 int* buf_size, | 61 int* buf_size, |
62 int min_size) { | 62 int min_size) { |
63 static const int kReadBufSize = 32768; | 63 static const int kReadBufSize = 32768; |
64 | 64 |
65 DCHECK(buf && buf_size); | 65 DCHECK(buf && buf_size); |
66 if (!read_buffer_) | 66 if (!read_buffer_.get()) |
67 read_buffer_ = new net::IOBuffer(kReadBufSize); | 67 read_buffer_ = new net::IOBuffer(kReadBufSize); |
68 *buf = read_buffer_.get(); | 68 *buf = read_buffer_.get(); |
69 *buf_size = kReadBufSize; | 69 *buf_size = kReadBufSize; |
70 | 70 |
71 return true; | 71 return true; |
72 } | 72 } |
73 | 73 |
74 bool StreamResourceHandler::OnReadCompleted(int request_id, | 74 bool StreamResourceHandler::OnReadCompleted(int request_id, |
75 int bytes_read, | 75 int bytes_read, |
76 bool* defer) { | 76 bool* defer) { |
77 if (!bytes_read) | 77 if (!bytes_read) |
78 return true; | 78 return true; |
79 | 79 |
80 // We have more data to read. | 80 // We have more data to read. |
81 DCHECK(read_buffer_); | 81 DCHECK(read_buffer_.get()); |
82 | 82 |
83 // Release the ownership of the buffer, and store a reference | 83 // Release the ownership of the buffer, and store a reference |
84 // to it. A new one will be allocated in OnWillRead(). | 84 // to it. A new one will be allocated in OnWillRead(). |
85 net::IOBuffer* buffer = NULL; | 85 net::IOBuffer* buffer = NULL; |
86 read_buffer_.swap(&buffer); | 86 read_buffer_.swap(&buffer); |
87 stream_->AddData(buffer, bytes_read); | 87 stream_->AddData(buffer, bytes_read); |
88 | 88 |
89 if (!stream_->can_add_data()) | 89 if (!stream_->can_add_data()) |
90 *defer = true; | 90 *defer = true; |
91 | 91 |
(...skipping 17 matching lines...) Expand all Loading... |
109 void StreamResourceHandler::OnSpaceAvailable(Stream* stream) { | 109 void StreamResourceHandler::OnSpaceAvailable(Stream* stream) { |
110 controller()->Resume(); | 110 controller()->Resume(); |
111 } | 111 } |
112 | 112 |
113 void StreamResourceHandler::OnClose(Stream* stream) { | 113 void StreamResourceHandler::OnClose(Stream* stream) { |
114 controller()->Cancel(); | 114 controller()->Cancel(); |
115 } | 115 } |
116 | 116 |
117 } // namespace content | 117 } // namespace content |
118 | 118 |
OLD | NEW |