James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 1 | // Copyright 2014 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 MOJO_SERVICES_NETWORK_URL_LOADER_IMPL_H_ |
| 6 | #define MOJO_SERVICES_NETWORK_URL_LOADER_IMPL_H_ |
| 7 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 8 | #include "base/memory/scoped_ptr.h" |
| 9 | #include "base/memory/weak_ptr.h" |
| 10 | #include "mojo/common/handle_watcher.h" |
| 11 | #include "mojo/public/cpp/bindings/interface_impl.h" |
Colin Blundell | b470fa1 | 2014-12-10 16:28:40 +0100 | [diff] [blame] | 12 | #include "mojo/services/network/public/interfaces/url_loader.mojom.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 13 | #include "net/base/net_errors.h" |
| 14 | #include "net/url_request/url_request.h" |
| 15 | |
| 16 | namespace mojo { |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 17 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 18 | class NetworkContext; |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 19 | class NetToMojoPendingBuffer; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 20 | |
| 21 | class URLLoaderImpl : public InterfaceImpl<URLLoader>, |
| 22 | public net::URLRequest::Delegate { |
| 23 | public: |
| 24 | explicit URLLoaderImpl(NetworkContext* context); |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 25 | ~URLLoaderImpl() override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 26 | |
| 27 | private: |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 28 | // URLLoader methods: |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 29 | void Start(URLRequestPtr request, |
| 30 | const Callback<void(URLResponsePtr)>& callback) override; |
| 31 | void FollowRedirect(const Callback<void(URLResponsePtr)>& callback) override; |
| 32 | void QueryStatus(const Callback<void(URLLoaderStatusPtr)>& callback) override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 33 | |
| 34 | // net::URLRequest::Delegate methods: |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 35 | void OnReceivedRedirect(net::URLRequest* url_request, |
| 36 | const net::RedirectInfo& redirect_info, |
| 37 | bool* defer_redirect) override; |
| 38 | void OnResponseStarted(net::URLRequest* url_request) override; |
| 39 | void OnReadCompleted(net::URLRequest* url_request, int bytes_read) override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 40 | |
| 41 | void SendError( |
| 42 | int error, |
| 43 | const Callback<void(URLResponsePtr)>& callback); |
| 44 | void SendResponse(URLResponsePtr response); |
| 45 | void OnResponseBodyStreamReady(MojoResult result); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 46 | void ReadMore(); |
| 47 | void DidRead(uint32_t num_bytes, bool completed_synchronously); |
| 48 | |
| 49 | NetworkContext* context_; |
| 50 | scoped_ptr<net::URLRequest> url_request_; |
| 51 | Callback<void(URLResponsePtr)> callback_; |
| 52 | ScopedDataPipeProducerHandle response_body_stream_; |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 53 | scoped_refptr<NetToMojoPendingBuffer> pending_write_; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 54 | common::HandleWatcher handle_watcher_; |
| 55 | uint32 response_body_buffer_size_; |
| 56 | bool auto_follow_redirects_; |
| 57 | |
| 58 | base::WeakPtrFactory<URLLoaderImpl> weak_ptr_factory_; |
| 59 | }; |
| 60 | |
| 61 | } // namespace mojo |
| 62 | |
| 63 | #endif // MOJO_SERVICES_NETWORK_URL_LOADER_IMPL_H_ |