| 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 <vector> |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 14 #include "content/common/url_loader.mojom.h" | 14 #include "content/common/url_loader.mojom.h" |
| 15 #include "ipc/ipc_message.h" | 15 #include "ipc/ipc_message.h" |
| 16 #include "mojo/public/cpp/bindings/binding.h" | |
| 17 #include "mojo/public/cpp/system/data_pipe.h" | 16 #include "mojo/public/cpp/system/data_pipe.h" |
| 18 | 17 |
| 19 namespace base { | 18 namespace base { |
| 20 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
| 21 } // namespace base | 20 } // namespace base |
| 22 | 21 |
| 23 namespace net { | 22 namespace net { |
| 24 struct RedirectInfo; | 23 struct RedirectInfo; |
| 25 } // namespace net | 24 } // namespace net |
| 26 | 25 |
| 27 namespace content { | 26 namespace content { |
| 28 class ResourceDispatcher; | 27 class ResourceDispatcher; |
| 29 class URLResponseBodyConsumer; | 28 class URLResponseBodyConsumer; |
| 30 struct ResourceRequestCompletionStatus; | 29 struct ResourceRequestCompletionStatus; |
| 31 struct ResourceResponseHead; | 30 struct ResourceResponseHead; |
| 32 | 31 |
| 33 class CONTENT_EXPORT URLLoaderClientImpl final : public mojom::URLLoaderClient { | 32 class CONTENT_EXPORT URLLoaderClientImpl final : public mojom::URLLoaderClient { |
| 34 public: | 33 public: |
| 35 URLLoaderClientImpl(int request_id, | 34 URLLoaderClientImpl(int request_id, |
| 36 ResourceDispatcher* resource_dispatcher, | 35 ResourceDispatcher* resource_dispatcher, |
| 37 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 36 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 38 ~URLLoaderClientImpl() override; | 37 ~URLLoaderClientImpl() override; |
| 39 | 38 |
| 40 void Bind(mojom::URLLoaderClientPtr* client_ptr); | |
| 41 | |
| 42 // Sets |is_deferred_|. From now, the received messages are not dispatched | 39 // Sets |is_deferred_|. From now, the received messages are not dispatched |
| 43 // to clients until UnsetDefersLoading is called. | 40 // to clients until UnsetDefersLoading is called. |
| 44 void SetDefersLoading(); | 41 void SetDefersLoading(); |
| 45 | 42 |
| 46 // Unsets |is_deferred_|. | 43 // Unsets |is_deferred_|. |
| 47 void UnsetDefersLoading(); | 44 void UnsetDefersLoading(); |
| 48 | 45 |
| 49 // Disaptches the messages received after SetDefersLoading is called. | 46 // Disaptches the messages received after SetDefersLoading is called. |
| 50 void FlushDeferredMessages(); | 47 void FlushDeferredMessages(); |
| 51 | 48 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 62 void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override; | 59 void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override; |
| 63 void OnTransferSizeUpdated(int32_t transfer_size_diff) override; | 60 void OnTransferSizeUpdated(int32_t transfer_size_diff) override; |
| 64 void OnStartLoadingResponseBody( | 61 void OnStartLoadingResponseBody( |
| 65 mojo::ScopedDataPipeConsumerHandle body) override; | 62 mojo::ScopedDataPipeConsumerHandle body) override; |
| 66 void OnComplete(const ResourceRequestCompletionStatus& status) override; | 63 void OnComplete(const ResourceRequestCompletionStatus& status) override; |
| 67 | 64 |
| 68 private: | 65 private: |
| 69 bool NeedsStoringMessage() const; | 66 bool NeedsStoringMessage() const; |
| 70 void StoreAndDispatch(const IPC::Message& message); | 67 void StoreAndDispatch(const IPC::Message& message); |
| 71 | 68 |
| 72 mojo::Binding<mojom::URLLoaderClient> binding_; | |
| 73 scoped_refptr<URLResponseBodyConsumer> body_consumer_; | 69 scoped_refptr<URLResponseBodyConsumer> body_consumer_; |
| 74 mojom::DownloadedTempFilePtr downloaded_file_; | 70 mojom::DownloadedTempFilePtr downloaded_file_; |
| 75 std::vector<IPC::Message> deferred_messages_; | 71 std::vector<IPC::Message> deferred_messages_; |
| 76 const int request_id_; | 72 const int request_id_; |
| 77 bool has_received_response_ = false; | 73 bool has_received_response_ = false; |
| 78 bool is_deferred_ = false; | 74 bool is_deferred_ = false; |
| 79 int32_t accumulated_transfer_size_diff_during_deferred_ = 0; | 75 int32_t accumulated_transfer_size_diff_during_deferred_ = 0; |
| 80 ResourceDispatcher* const resource_dispatcher_; | 76 ResourceDispatcher* const resource_dispatcher_; |
| 81 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 77 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 82 base::WeakPtrFactory<URLLoaderClientImpl> weak_factory_; | 78 base::WeakPtrFactory<URLLoaderClientImpl> weak_factory_; |
| 83 }; | 79 }; |
| 84 | 80 |
| 85 } // namespace content | 81 } // namespace content |
| 86 | 82 |
| 87 #endif // CONTENT_CHILD_URL_LOADER_CLIENT_IMPL_H_ | 83 #endif // CONTENT_CHILD_URL_LOADER_CLIENT_IMPL_H_ |
| OLD | NEW |