OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_NETWORK_URL_LOADER_IMPL_H_ |
| 6 #define CONTENT_NETWORK_URL_LOADER_IMPL_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 11 |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "content/common/content_export.h" |
| 14 #include "content/common/url_loader.mojom.h" |
| 15 #include "mojo/public/cpp/bindings/binding.h" |
| 16 #include "mojo/public/cpp/system/simple_watcher.h" |
| 17 #include "net/url_request/url_request.h" |
| 18 |
| 19 namespace content { |
| 20 |
| 21 class NetworkContext; |
| 22 class NetToMojoPendingBuffer; |
| 23 |
| 24 class CONTENT_EXPORT URLLoaderImpl : public mojom::URLLoader, |
| 25 public net::URLRequest::Delegate { |
| 26 public: |
| 27 URLLoaderImpl(NetworkContext* context, |
| 28 mojom::URLLoaderRequest url_loader_request, |
| 29 const ResourceRequest& request, |
| 30 mojom::URLLoaderClientPtr url_loader_client); |
| 31 ~URLLoaderImpl() override; |
| 32 |
| 33 // Called when the associated NetworkContext is going away. |
| 34 void Cleanup(); |
| 35 |
| 36 // mojom::URLLoader implementation: |
| 37 void FollowRedirect() override; |
| 38 void SetPriority(net::RequestPriority priority, |
| 39 int32_t intra_priority_value) override; |
| 40 |
| 41 // net::URLRequest::Delegate methods: |
| 42 void OnReceivedRedirect(net::URLRequest* url_request, |
| 43 const net::RedirectInfo& redirect_info, |
| 44 bool* defer_redirect) override; |
| 45 void OnResponseStarted(net::URLRequest* url_request) override; |
| 46 void OnReadCompleted(net::URLRequest* url_request, int bytes_read) override; |
| 47 |
| 48 private: |
| 49 void ReadMore(); |
| 50 void DidRead(uint32_t num_bytes, bool completed_synchronously); |
| 51 void NotifyCompleted(int error_code); |
| 52 void SendDataPipeIfNecessary(); |
| 53 void OnConnectionError(); |
| 54 void OnResponseBodyStreamClosed(MojoResult result); |
| 55 void OnResponseBodyStreamReady(MojoResult result); |
| 56 void DeleteIfNeeded(); |
| 57 |
| 58 NetworkContext* context_; |
| 59 bool connected_; |
| 60 std::unique_ptr<net::URLRequest> url_request_; |
| 61 mojo::Binding<mojom::URLLoader> binding_; |
| 62 mojom::URLLoaderClientPtr url_loader_client_; |
| 63 |
| 64 mojo::ScopedDataPipeProducerHandle response_body_stream_; |
| 65 mojo::ScopedDataPipeConsumerHandle response_body_consumer_handle_; |
| 66 scoped_refptr<NetToMojoPendingBuffer> pending_write_; |
| 67 mojo::SimpleWatcher writable_handle_watcher_; |
| 68 mojo::SimpleWatcher peer_closed_handle_watcher_; |
| 69 |
| 70 base::WeakPtrFactory<URLLoaderImpl> weak_ptr_factory_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(URLLoaderImpl); |
| 73 }; |
| 74 |
| 75 } // namespace content |
| 76 |
| 77 #endif // CONTENT_NETWORK_URL_LOADER_IMPL_H_ |
OLD | NEW |