Chromium Code Reviews| 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 #ifndef CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/browser/loader/resource_handler.h" | 10 #include "content/browser/loader/resource_handler.h" |
| 11 #include "content/browser/streams/stream_write_observer.h" | 11 #include "content/browser/loader/stream_writer.h" |
| 12 #include "url/gurl.h" | |
| 13 | 12 |
| 14 namespace net { | 13 namespace net { |
| 15 class URLRequest; | 14 class URLRequest; |
| 16 } // namespace net | 15 } // namespace net |
| 17 | 16 |
| 18 namespace content { | 17 namespace content { |
| 19 | 18 |
| 20 class StreamRegistry; | 19 class StreamRegistry; |
| 21 | 20 |
| 22 // Redirect this resource to a stream. | 21 // Redirect this resource to a stream. |
|
mmenke
2014/10/15 20:05:43
Maybe "resource" -> "resource response"?
Admitted
mmenke
2014/10/15 20:05:43
stream -> Stream
| |
| 23 class StreamResourceHandler : public StreamWriteObserver, | 22 class StreamResourceHandler : public ResourceHandler { |
| 24 public ResourceHandler { | |
| 25 public: | 23 public: |
| 26 // |origin| will be used to construct the URL for the Stream. See | 24 // |origin| will be used to construct the URL for the Stream. See |
| 27 // WebCore::BlobURL and and WebCore::SecurityOrigin in Blink to understand | 25 // WebCore::BlobURL and and WebCore::SecurityOrigin in Blink to understand |
| 28 // how origin check is done on resource loading. | 26 // how origin check is done on resource loading. |
| 29 StreamResourceHandler(net::URLRequest* request, | 27 StreamResourceHandler(net::URLRequest* request, |
| 30 StreamRegistry* registry, | 28 StreamRegistry* registry, |
| 31 const GURL& origin); | 29 const GURL& origin); |
| 32 virtual ~StreamResourceHandler(); | 30 virtual ~StreamResourceHandler(); |
| 33 | 31 |
| 32 virtual void SetController(ResourceController* controller) override; | |
| 33 | |
| 34 virtual bool OnUploadProgress(uint64 position, uint64 size) override; | 34 virtual bool OnUploadProgress(uint64 position, uint64 size) override; |
| 35 | 35 |
| 36 // Not needed, as this event handler ought to be the final resource. | 36 // Not needed, as this event handler ought to be the final resource. |
| 37 virtual bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 37 virtual bool OnRequestRedirected(const net::RedirectInfo& redirect_info, |
| 38 ResourceResponse* resp, | 38 ResourceResponse* resp, |
| 39 bool* defer) override; | 39 bool* defer) override; |
| 40 | 40 |
| 41 virtual bool OnResponseStarted(ResourceResponse* resp, | 41 virtual bool OnResponseStarted(ResourceResponse* resp, |
| 42 bool* defer) override; | 42 bool* defer) override; |
| 43 | 43 |
| 44 virtual bool OnWillStart(const GURL& url, bool* defer) override; | 44 virtual bool OnWillStart(const GURL& url, bool* defer) override; |
| 45 | 45 |
| 46 virtual bool OnBeforeNetworkStart(const GURL& url, bool* defer) override; | 46 virtual bool OnBeforeNetworkStart(const GURL& url, bool* defer) override; |
| 47 | 47 |
| 48 // Create a new buffer to store received data. | 48 // Create a new buffer to store received data. |
| 49 virtual bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 49 virtual bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 50 int* buf_size, | 50 int* buf_size, |
| 51 int min_size) override; | 51 int min_size) override; |
| 52 | 52 |
| 53 // A read was completed, forward the data to the Stream. | 53 // A read was completed, forward the data to the Stream. |
| 54 virtual bool OnReadCompleted(int bytes_read, bool* defer) override; | 54 virtual bool OnReadCompleted(int bytes_read, bool* defer) override; |
| 55 | 55 |
| 56 virtual void OnResponseCompleted(const net::URLRequestStatus& status, | 56 virtual void OnResponseCompleted(const net::URLRequestStatus& status, |
| 57 const std::string& sec_info, | 57 const std::string& sec_info, |
| 58 bool* defer) override; | 58 bool* defer) override; |
| 59 | 59 |
| 60 virtual void OnDataDownloaded(int bytes_downloaded) override; | 60 virtual void OnDataDownloaded(int bytes_downloaded) override; |
| 61 | 61 |
| 62 Stream* stream() { return stream_.get(); } | 62 Stream* stream() { return writer_.stream(); } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 virtual void OnSpaceAvailable(Stream* stream) override; | 65 StreamWriter writer_; |
| 66 virtual void OnClose(Stream* stream) override; | |
| 67 | 66 |
| 68 scoped_refptr<Stream> stream_; | |
| 69 scoped_refptr<net::IOBuffer> read_buffer_; | |
| 70 DISALLOW_COPY_AND_ASSIGN(StreamResourceHandler); | 67 DISALLOW_COPY_AND_ASSIGN(StreamResourceHandler); |
|
mmenke
2014/10/15 20:05:43
While you're here... include base/macros.h?
| |
| 71 }; | 68 }; |
| 72 | 69 |
| 73 } // namespace content | 70 } // namespace content |
| 74 | 71 |
| 75 #endif // CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ | 72 #endif // CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ |
| OLD | NEW |