| 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 <string> | 11 #include <string> |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/timer/timer.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/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 18 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 class URLRequest; | 22 class URLRequest; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 class ResourceBuffer; | 26 class ResourceBuffer; |
| 27 class ResourceDispatcherHostImpl; | 27 class ResourceDispatcherHostImpl; |
| 28 class UploadProgressTracker; |
| 28 | 29 |
| 29 // Used to complete an asynchronous resource request in response to resource | 30 // Used to complete an asynchronous resource request in response to resource |
| 30 // load events from the resource dispatcher host. | 31 // load events from the resource dispatcher host. |
| 31 class CONTENT_EXPORT AsyncResourceHandler : public ResourceHandler, | 32 class CONTENT_EXPORT AsyncResourceHandler : public ResourceHandler, |
| 32 public ResourceMessageDelegate { | 33 public ResourceMessageDelegate { |
| 33 public: | 34 public: |
| 34 AsyncResourceHandler(net::URLRequest* request, | 35 AsyncResourceHandler(net::URLRequest* request, |
| 35 ResourceDispatcherHostImpl* rdh); | 36 ResourceDispatcherHostImpl* rdh); |
| 36 ~AsyncResourceHandler() override; | 37 ~AsyncResourceHandler() override; |
| 37 | 38 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 52 void OnDataDownloaded(int bytes_downloaded) override; | 53 void OnDataDownloaded(int bytes_downloaded) override; |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 class InliningHelper; | 56 class InliningHelper; |
| 56 | 57 |
| 57 // IPC message handlers: | 58 // IPC message handlers: |
| 58 void OnFollowRedirect(int request_id); | 59 void OnFollowRedirect(int request_id); |
| 59 void OnDataReceivedACK(int request_id); | 60 void OnDataReceivedACK(int request_id); |
| 60 void OnUploadProgressACK(int request_id); | 61 void OnUploadProgressACK(int request_id); |
| 61 | 62 |
| 62 void ReportUploadProgress(); | |
| 63 | |
| 64 bool EnsureResourceBufferIsInitialized(); | 63 bool EnsureResourceBufferIsInitialized(); |
| 65 void ResumeIfDeferred(); | 64 void ResumeIfDeferred(); |
| 66 void OnDefer(); | 65 void OnDefer(); |
| 67 bool CheckForSufficientResource(); | 66 bool CheckForSufficientResource(); |
| 68 int CalculateEncodedDataLengthToReport(); | 67 int CalculateEncodedDataLengthToReport(); |
| 69 int CalculateEncodedBodyLengthToReport(); | 68 int CalculateEncodedBodyLengthToReport(); |
| 70 void RecordHistogram(); | 69 void RecordHistogram(); |
| 70 void SendUploadProgress(int64_t current_position, int64_t total_size); |
| 71 | 71 |
| 72 scoped_refptr<ResourceBuffer> buffer_; | 72 scoped_refptr<ResourceBuffer> buffer_; |
| 73 ResourceDispatcherHostImpl* rdh_; | 73 ResourceDispatcherHostImpl* rdh_; |
| 74 | 74 |
| 75 // Number of messages we've sent to the renderer that we haven't gotten an | 75 // 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. | 76 // ACK for. This allows us to avoid having too many messages in flight. |
| 77 int pending_data_count_; | 77 int pending_data_count_; |
| 78 | 78 |
| 79 int allocation_size_; | 79 int allocation_size_; |
| 80 | 80 |
| 81 bool first_chunk_read_ = false; | 81 bool first_chunk_read_ = false; |
| 82 | 82 |
| 83 bool did_defer_; | 83 bool did_defer_; |
| 84 | 84 |
| 85 bool has_checked_for_sufficient_resources_; | 85 bool has_checked_for_sufficient_resources_; |
| 86 bool sent_received_response_msg_; | 86 bool sent_received_response_msg_; |
| 87 bool sent_data_buffer_msg_; | 87 bool sent_data_buffer_msg_; |
| 88 | 88 |
| 89 std::unique_ptr<InliningHelper> inlining_helper_; | 89 std::unique_ptr<InliningHelper> inlining_helper_; |
| 90 base::TimeTicks response_started_ticks_; | 90 base::TimeTicks response_started_ticks_; |
| 91 | 91 |
| 92 uint64_t last_upload_position_; | 92 std::unique_ptr<UploadProgressTracker> upload_progress_tracker_; |
| 93 bool waiting_for_upload_progress_ack_; | |
| 94 base::TimeTicks last_upload_ticks_; | |
| 95 base::RepeatingTimer progress_timer_; | |
| 96 | 93 |
| 97 int64_t reported_transfer_size_; | 94 int64_t reported_transfer_size_; |
| 98 | 95 |
| 99 DISALLOW_COPY_AND_ASSIGN(AsyncResourceHandler); | 96 DISALLOW_COPY_AND_ASSIGN(AsyncResourceHandler); |
| 100 }; | 97 }; |
| 101 | 98 |
| 102 } // namespace content | 99 } // namespace content |
| 103 | 100 |
| 104 #endif // CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_ | 101 #endif // CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_ |
| OLD | NEW |