OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_CHILD_URL_LOADER_CLIENT_IMPL_H_ | 5 #ifndef CONTENT_CHILD_URL_LOADER_CLIENT_IMPL_H_ |
6 #define CONTENT_CHILD_URL_LOADER_CLIENT_IMPL_H_ | 6 #define CONTENT_CHILD_URL_LOADER_CLIENT_IMPL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <vector> |
9 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
11 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
12 #include "content/common/url_loader.mojom.h" | 13 #include "content/common/url_loader.mojom.h" |
13 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
14 #include "mojo/public/cpp/bindings/associated_binding.h" | 15 #include "mojo/public/cpp/bindings/associated_binding.h" |
15 #include "mojo/public/cpp/system/data_pipe.h" | 16 #include "mojo/public/cpp/system/data_pipe.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
(...skipping 16 matching lines...) Expand all Loading... |
35 class CONTENT_EXPORT URLLoaderClientImpl final : public mojom::URLLoaderClient { | 36 class CONTENT_EXPORT URLLoaderClientImpl final : public mojom::URLLoaderClient { |
36 public: | 37 public: |
37 URLLoaderClientImpl(int request_id, | 38 URLLoaderClientImpl(int request_id, |
38 ResourceDispatcher* resource_dispatcher, | 39 ResourceDispatcher* resource_dispatcher, |
39 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 40 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
40 ~URLLoaderClientImpl() override; | 41 ~URLLoaderClientImpl() override; |
41 | 42 |
42 void Bind(mojom::URLLoaderClientAssociatedPtrInfo* client_ptr_info, | 43 void Bind(mojom::URLLoaderClientAssociatedPtrInfo* client_ptr_info, |
43 mojo::AssociatedGroup* associated_group); | 44 mojo::AssociatedGroup* associated_group); |
44 | 45 |
| 46 // Sets |is_deferred_|. From now, the received messages are not dispatched |
| 47 // to clients until UnsetDefersLoading is called. |
| 48 void SetDefersLoading(); |
| 49 |
| 50 // Unsets |is_deferred_|. |
| 51 void UnsetDefersLoading(); |
| 52 |
| 53 // Disaptches the messages received after SetDefersLoading is called. |
| 54 void FlushDeferredMessages(); |
| 55 |
45 // mojom::URLLoaderClient implementation | 56 // mojom::URLLoaderClient implementation |
46 void OnReceiveResponse(const ResourceResponseHead& response_head, | 57 void OnReceiveResponse(const ResourceResponseHead& response_head, |
47 mojom::DownloadedTempFilePtr downloaded_file) override; | 58 mojom::DownloadedTempFilePtr downloaded_file) override; |
48 void OnReceiveRedirect(const net::RedirectInfo& redirect_info, | 59 void OnReceiveRedirect(const net::RedirectInfo& redirect_info, |
49 const ResourceResponseHead& response_head) override; | 60 const ResourceResponseHead& response_head) override; |
50 void OnDataDownloaded(int64_t data_len, int64_t encoded_data_len) override; | 61 void OnDataDownloaded(int64_t data_len, int64_t encoded_data_len) override; |
51 void OnTransferSizeUpdated(int32_t transfer_size_diff) override; | 62 void OnTransferSizeUpdated(int32_t transfer_size_diff) override; |
52 void OnStartLoadingResponseBody( | 63 void OnStartLoadingResponseBody( |
53 mojo::ScopedDataPipeConsumerHandle body) override; | 64 mojo::ScopedDataPipeConsumerHandle body) override; |
54 void OnComplete(const ResourceRequestCompletionStatus& status) override; | 65 void OnComplete(const ResourceRequestCompletionStatus& status) override; |
55 | 66 |
56 private: | 67 private: |
57 void Dispatch(const IPC::Message& message); | 68 void Dispatch(const IPC::Message& message); |
58 | 69 |
59 mojo::AssociatedBinding<mojom::URLLoaderClient> binding_; | 70 mojo::AssociatedBinding<mojom::URLLoaderClient> binding_; |
60 scoped_refptr<URLResponseBodyConsumer> body_consumer_; | 71 scoped_refptr<URLResponseBodyConsumer> body_consumer_; |
61 mojom::DownloadedTempFilePtr downloaded_file_; | 72 mojom::DownloadedTempFilePtr downloaded_file_; |
| 73 std::vector<IPC::Message> deferred_messages_; |
62 const int request_id_; | 74 const int request_id_; |
63 bool has_received_response_ = false; | 75 bool has_received_response_ = false; |
| 76 bool is_deferred_ = false; |
| 77 int32_t accumulated_transfer_size_diff_during_deferred_ = 0; |
64 ResourceDispatcher* const resource_dispatcher_; | 78 ResourceDispatcher* const resource_dispatcher_; |
| 79 const scoped_refptr<base::RefCountedData<bool>> is_destroyed_; |
65 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 80 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
66 }; | 81 }; |
67 | 82 |
68 } // namespace content | 83 } // namespace content |
69 | 84 |
70 #endif // CONTENT_CHILD_URL_LOADER_CLIENT_IMPL_H_ | 85 #endif // CONTENT_CHILD_URL_LOADER_CLIENT_IMPL_H_ |
OLD | NEW |