| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_ASYNC_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "content/browser/loader/resource_handler.h" | 15 #include "content/browser/loader/resource_handler.h" |
| 16 #include "content/browser/loader/resource_message_delegate.h" | 16 #include "content/browser/loader/resource_message_delegate.h" |
| 17 #include "content/browser/loader/upload_progress_tracker.h" |
| 17 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 18 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace net { | 22 namespace net { |
| 22 class URLRequest; | 23 class URLRequest; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace content { | 26 namespace content { |
| 26 class ResourceBuffer; | 27 class ResourceBuffer; |
| 27 class ResourceDispatcherHostImpl; | 28 class ResourceDispatcherHostImpl; |
| 28 class UploadProgressTracker; | |
| 29 | 29 |
| 30 // Used to complete an asynchronous resource request in response to resource | 30 // Used to complete an asynchronous resource request in response to resource |
| 31 // load events from the resource dispatcher host. | 31 // load events from the resource dispatcher host. |
| 32 class CONTENT_EXPORT AsyncResourceHandler : public ResourceHandler, | 32 class CONTENT_EXPORT AsyncResourceHandler |
| 33 public ResourceMessageDelegate { | 33 : public ResourceHandler, |
| 34 public ResourceMessageDelegate, |
| 35 public UploadProgressTracker::Client { |
| 34 public: | 36 public: |
| 35 AsyncResourceHandler(net::URLRequest* request, | 37 AsyncResourceHandler(net::URLRequest* request, |
| 36 ResourceDispatcherHostImpl* rdh); | 38 ResourceDispatcherHostImpl* rdh); |
| 37 ~AsyncResourceHandler() override; | 39 ~AsyncResourceHandler() override; |
| 38 | 40 |
| 39 bool OnMessageReceived(const IPC::Message& message) override; | 41 bool OnMessageReceived(const IPC::Message& message) override; |
| 40 | 42 |
| 41 // ResourceHandler implementation: | 43 // ResourceHandler implementation: |
| 42 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 44 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, |
| 43 ResourceResponse* response, | 45 ResourceResponse* response, |
| 44 bool* defer) override; | 46 bool* defer) override; |
| 45 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; | 47 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; |
| 46 bool OnWillStart(const GURL& url, bool* defer) override; | 48 bool OnWillStart(const GURL& url, bool* defer) override; |
| 47 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 49 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 48 int* buf_size, | 50 int* buf_size, |
| 49 int min_size) override; | 51 int min_size) override; |
| 50 bool OnReadCompleted(int bytes_read, bool* defer) override; | 52 bool OnReadCompleted(int bytes_read, bool* defer) override; |
| 51 void OnResponseCompleted(const net::URLRequestStatus& status, | 53 void OnResponseCompleted(const net::URLRequestStatus& status, |
| 52 bool* defer) override; | 54 bool* defer) override; |
| 53 void OnDataDownloaded(int bytes_downloaded) override; | 55 void OnDataDownloaded(int bytes_downloaded) override; |
| 54 | 56 |
| 57 // UploadProgressTracker::Client implementation: |
| 58 net::UploadProgress GetUploadProgress() override; |
| 59 void ReportUploadProgress(int64_t current_position, |
| 60 int64_t total_size) override; |
| 61 |
| 55 private: | 62 private: |
| 56 class InliningHelper; | 63 class InliningHelper; |
| 57 | 64 |
| 58 // IPC message handlers: | 65 // IPC message handlers: |
| 59 void OnFollowRedirect(int request_id); | 66 void OnFollowRedirect(int request_id); |
| 60 void OnDataReceivedACK(int request_id); | 67 void OnDataReceivedACK(int request_id); |
| 61 void OnUploadProgressACK(int request_id); | 68 void OnUploadProgressACK(int request_id); |
| 62 | 69 |
| 63 bool EnsureResourceBufferIsInitialized(); | 70 bool EnsureResourceBufferIsInitialized(); |
| 64 void ResumeIfDeferred(); | 71 void ResumeIfDeferred(); |
| 65 void OnDefer(); | 72 void OnDefer(); |
| 66 bool CheckForSufficientResource(); | 73 bool CheckForSufficientResource(); |
| 67 int CalculateEncodedDataLengthToReport(); | 74 int CalculateEncodedDataLengthToReport(); |
| 68 int CalculateEncodedBodyLengthToReport(); | 75 int CalculateEncodedBodyLengthToReport(); |
| 69 void RecordHistogram(); | 76 void RecordHistogram(); |
| 70 void SendUploadProgress(int64_t current_position, int64_t total_size); | |
| 71 | 77 |
| 72 scoped_refptr<ResourceBuffer> buffer_; | 78 scoped_refptr<ResourceBuffer> buffer_; |
| 73 ResourceDispatcherHostImpl* rdh_; | 79 ResourceDispatcherHostImpl* rdh_; |
| 74 | 80 |
| 75 // Number of messages we've sent to the renderer that we haven't gotten an | 81 // Number of messages we've sent to the renderer that we haven't gotten an |
| 76 // ACK for. This allows us to avoid having too many messages in flight. | 82 // ACK for. This allows us to avoid having too many messages in flight. |
| 77 int pending_data_count_; | 83 int pending_data_count_; |
| 78 | 84 |
| 79 int allocation_size_; | 85 int allocation_size_; |
| 80 | 86 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 92 std::unique_ptr<UploadProgressTracker> upload_progress_tracker_; | 98 std::unique_ptr<UploadProgressTracker> upload_progress_tracker_; |
| 93 | 99 |
| 94 int64_t reported_transfer_size_; | 100 int64_t reported_transfer_size_; |
| 95 | 101 |
| 96 DISALLOW_COPY_AND_ASSIGN(AsyncResourceHandler); | 102 DISALLOW_COPY_AND_ASSIGN(AsyncResourceHandler); |
| 97 }; | 103 }; |
| 98 | 104 |
| 99 } // namespace content | 105 } // namespace content |
| 100 | 106 |
| 101 #endif // CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_ | 107 #endif // CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_ |
| OLD | NEW |