OLD | NEW |
| (Empty) |
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 | |
8 #include <stdint.h> | |
9 | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "mojo/message_pump/handle_watcher.h" | |
13 #include "mojo/public/cpp/bindings/binding.h" | |
14 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" | |
15 #include "mojo/shell/public/cpp/message_loop_ref.h" | |
16 #include "net/base/net_errors.h" | |
17 #include "net/url_request/url_request.h" | |
18 | |
19 namespace mojo { | |
20 | |
21 class NetworkContext; | |
22 class NetToMojoPendingBuffer; | |
23 | |
24 class URLLoaderImpl : public URLLoader, | |
25 public net::URLRequest::Delegate { | |
26 public: | |
27 URLLoaderImpl(NetworkContext* context, | |
28 InterfaceRequest<URLLoader> request, | |
29 scoped_ptr<mojo::MessageLoopRef> app_refcount); | |
30 ~URLLoaderImpl() override; | |
31 | |
32 // Called when the associated NetworkContext is going away. | |
33 void Cleanup(); | |
34 | |
35 private: | |
36 // URLLoader methods: | |
37 void Start(URLRequestPtr request, | |
38 const Callback<void(URLResponsePtr)>& callback) override; | |
39 void FollowRedirect(const Callback<void(URLResponsePtr)>& callback) override; | |
40 void QueryStatus(const Callback<void(URLLoaderStatusPtr)>& callback) override; | |
41 | |
42 void OnConnectionError(); | |
43 | |
44 // net::URLRequest::Delegate methods: | |
45 void OnReceivedRedirect(net::URLRequest* url_request, | |
46 const net::RedirectInfo& redirect_info, | |
47 bool* defer_redirect) override; | |
48 void OnResponseStarted(net::URLRequest* url_request) override; | |
49 void OnReadCompleted(net::URLRequest* url_request, int bytes_read) override; | |
50 | |
51 void SendError( | |
52 int error, | |
53 const Callback<void(URLResponsePtr)>& callback); | |
54 void SendResponse(URLResponsePtr response); | |
55 void OnResponseBodyStreamReady(MojoResult result); | |
56 void OnResponseBodyStreamClosed(MojoResult result); | |
57 void ReadMore(); | |
58 void DidRead(uint32_t num_bytes, bool completed_synchronously); | |
59 void ListenForPeerClosed(); | |
60 void DeleteIfNeeded(); | |
61 | |
62 NetworkContext* context_; | |
63 scoped_ptr<net::URLRequest> url_request_; | |
64 Callback<void(URLResponsePtr)> callback_; | |
65 ScopedDataPipeProducerHandle response_body_stream_; | |
66 scoped_refptr<NetToMojoPendingBuffer> pending_write_; | |
67 common::HandleWatcher handle_watcher_; | |
68 uint32_t response_body_buffer_size_; | |
69 uint32_t response_body_bytes_read_; | |
70 bool auto_follow_redirects_; | |
71 bool connected_; | |
72 Binding<URLLoader> binding_; | |
73 scoped_ptr<mojo::MessageLoopRef> app_refcount_; | |
74 | |
75 base::WeakPtrFactory<URLLoaderImpl> weak_ptr_factory_; | |
76 }; | |
77 | |
78 } // namespace mojo | |
79 | |
80 #endif // MOJO_SERVICES_NETWORK_URL_LOADER_IMPL_H_ | |
OLD | NEW |