Chromium Code Reviews| Index: content/browser/loader/stream_resource_handler.cc |
| diff --git a/content/browser/loader/stream_resource_handler.cc b/content/browser/loader/stream_resource_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a4e87bc54c6318864dc7137db9ddbc4bb8a5a519 |
| --- /dev/null |
| +++ b/content/browser/loader/stream_resource_handler.cc |
| @@ -0,0 +1,118 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/loader/stream_resource_handler.h" |
| + |
| +#include "base/logging.h" |
| +#include "content/public/browser/resource_controller.h" |
| +#include "net/base/io_buffer.h" |
| +#include "net/url_request/url_request_status.h" |
| + |
| +namespace content { |
| + |
| +StreamResourceHandler::StreamResourceHandler( |
| + net::URLRequest* request, |
| + scoped_refptr<ChromeStream> stream) |
| + : request_(request), |
| + stream_(stream), |
| + read_buffer_(NULL) { |
| + stream_->AddObserver(this); |
| +} |
| + |
| +StreamResourceHandler::~StreamResourceHandler() { |
| + stream_->RemoveObserver(this); |
| +} |
| + |
| +bool StreamResourceHandler::OnUploadProgress(int request_id, |
| + uint64 position, |
| + uint64 size) { |
| + return true; |
| +} |
| + |
| +bool StreamResourceHandler::OnRequestRedirected(int request_id, |
| + const GURL& url, |
| + ResourceResponse* resp, |
| + bool* defer) { |
| + return true; |
| +} |
| + |
| +bool StreamResourceHandler::OnResponseStarted(int request_id, |
| + ResourceResponse* resp, |
| + bool* defer) { |
| + return true; |
| +} |
| + |
| +bool StreamResourceHandler::OnWillStart(int request_id, |
| + const GURL& url, |
| + bool* defer) { |
| + return true; |
| +} |
| + |
| +bool StreamResourceHandler::OnWillRead(int request_id, |
| + net::IOBuffer** buf, |
| + int* buf_size, |
| + int min_size) { |
| + static const int kReadBufSize = 32768; |
| + |
| + DCHECK(buf && buf_size); |
| + if (!read_buffer_) { |
| + read_buffer_ = new net::IOBuffer(kReadBufSize); |
| + } |
| + *buf = read_buffer_.get(); |
| + *buf_size = kReadBufSize; |
| + |
| + return true; |
| +} |
| + |
| +bool StreamResourceHandler::OnReadCompleted(int request_id, |
| + int bytes_read, |
| + bool* defer) { |
| + if (!bytes_read) |
| + return true; |
| + |
| + // We have more data to read. |
| + DCHECK(read_buffer_); |
| + |
| + // Release the ownership of the buffer, and store a reference |
| + // to it. A new one will be allocated in OnWillRead(). |
| + net::IOBuffer* buffer = NULL; |
| + read_buffer_.swap(&buffer); |
| + stream_->AddData(buffer, bytes_read); |
| + |
| + if (stream_->should_defer()) { |
|
darin (slow to review)
2013/02/13 09:18:12
nit: instead of should_defer(), I'd use a name tha
Zachary Kuznia
2013/02/13 16:37:14
Done.
|
| + *defer = true; |
| + } |
| + |
| + return true; |
| +} |
| + |
| +bool StreamResourceHandler::OnResponseCompleted( |
| + int request_id, |
| + const net::URLRequestStatus& urs, |
| + const std::string& sec_info) { |
| + stream_->MarkComplete(); |
| + if (urs.status() != net::URLRequestStatus::SUCCESS) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| +void StreamResourceHandler::OnDataDownloaded( |
| + int request_id, |
| + int bytes_downloaded) { |
| + NOTREACHED(); |
| +} |
| + |
| +void StreamResourceHandler::OnDataAvailable(ChromeStream* stream) { |
| +} |
| + |
| +void StreamResourceHandler::OnStreamComplete(ChromeStream* stream) { |
| +} |
| + |
| +void StreamResourceHandler::OnBufferAvailable(ChromeStream* stream) { |
| + controller()->Resume(); |
| +} |
| + |
| +} // namespace content |
| + |