Chromium Code Reviews| 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/logging.h" | |
| 8 #include "content/public/browser/resource_controller.h" | |
| 9 #include "net/base/io_buffer.h" | |
| 10 #include "net/url_request/url_request_status.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 StreamResourceHandler::StreamResourceHandler( | |
| 15 net::URLRequest* request, | |
| 16 scoped_refptr<ChromeStream> stream) | |
| 17 : request_(request), | |
| 18 stream_(stream), | |
| 19 read_buffer_(NULL) { | |
| 20 stream_->AddObserver(this); | |
| 21 } | |
| 22 | |
| 23 StreamResourceHandler::~StreamResourceHandler() { | |
| 24 stream_->RemoveObserver(this); | |
| 25 } | |
| 26 | |
| 27 bool StreamResourceHandler::OnUploadProgress(int request_id, | |
| 28 uint64 position, | |
| 29 uint64 size) { | |
| 30 return true; | |
| 31 } | |
| 32 | |
| 33 bool StreamResourceHandler::OnRequestRedirected(int request_id, | |
| 34 const GURL& url, | |
| 35 ResourceResponse* resp, | |
| 36 bool* defer) { | |
| 37 return true; | |
| 38 } | |
| 39 | |
| 40 bool StreamResourceHandler::OnResponseStarted(int request_id, | |
| 41 ResourceResponse* resp, | |
| 42 bool* defer) { | |
| 43 return true; | |
| 44 } | |
| 45 | |
| 46 bool StreamResourceHandler::OnWillStart(int request_id, | |
| 47 const GURL& url, | |
| 48 bool* defer) { | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 bool StreamResourceHandler::OnWillRead(int request_id, | |
| 53 net::IOBuffer** buf, | |
| 54 int* buf_size, | |
| 55 int min_size) { | |
| 56 static const int kReadBufSize = 32768; | |
| 57 | |
| 58 DCHECK(buf && buf_size); | |
| 59 if (!read_buffer_) { | |
| 60 read_buffer_ = new net::IOBuffer(kReadBufSize); | |
| 61 } | |
| 62 *buf = read_buffer_.get(); | |
| 63 *buf_size = kReadBufSize; | |
| 64 | |
| 65 return true; | |
| 66 } | |
| 67 | |
| 68 bool StreamResourceHandler::OnReadCompleted(int request_id, | |
| 69 int bytes_read, | |
| 70 bool* defer) { | |
| 71 if (!bytes_read) | |
| 72 return true; | |
| 73 | |
| 74 // We have more data to read. | |
| 75 DCHECK(read_buffer_); | |
| 76 | |
| 77 // Release the ownership of the buffer, and store a reference | |
| 78 // to it. A new one will be allocated in OnWillRead(). | |
| 79 net::IOBuffer* buffer = NULL; | |
| 80 read_buffer_.swap(&buffer); | |
| 81 stream_->AddData(buffer, bytes_read); | |
| 82 | |
| 83 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.
| |
| 84 *defer = true; | |
| 85 } | |
| 86 | |
| 87 return true; | |
| 88 } | |
| 89 | |
| 90 bool StreamResourceHandler::OnResponseCompleted( | |
| 91 int request_id, | |
| 92 const net::URLRequestStatus& urs, | |
| 93 const std::string& sec_info) { | |
| 94 stream_->MarkComplete(); | |
| 95 if (urs.status() != net::URLRequestStatus::SUCCESS) | |
| 96 return false; | |
| 97 | |
| 98 return true; | |
| 99 } | |
| 100 | |
| 101 void StreamResourceHandler::OnDataDownloaded( | |
| 102 int request_id, | |
| 103 int bytes_downloaded) { | |
| 104 NOTREACHED(); | |
| 105 } | |
| 106 | |
| 107 void StreamResourceHandler::OnDataAvailable(ChromeStream* stream) { | |
| 108 } | |
| 109 | |
| 110 void StreamResourceHandler::OnStreamComplete(ChromeStream* stream) { | |
| 111 } | |
| 112 | |
| 113 void StreamResourceHandler::OnBufferAvailable(ChromeStream* stream) { | |
| 114 controller()->Resume(); | |
| 115 } | |
| 116 | |
| 117 } // namespace content | |
| 118 | |
| OLD | NEW |