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