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.
5 #ifndef MOJO_SERVICES_NETWORK_URL_LOADER_IMPL_H_
6 #define MOJO_SERVICES_NETWORK_URL_LOADER_IMPL_H_
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"
12 #include "mojo/services/public/interfaces/network/url_loader.mojom.h"
13 #include "net/base/net_errors.h"
14 #include "net/url_request/url_request.h"
19 class NetToMojoPendingBuffer
;
21 class URLLoaderImpl
: public InterfaceImpl
<URLLoader
>,
22 public net::URLRequest::Delegate
{
24 explicit URLLoaderImpl(NetworkContext
* context
);
25 ~URLLoaderImpl() override
;
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
;
34 // net::URLRequest::Delegate methods:
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
;
43 const Callback
<void(URLResponsePtr
)>& callback
);
44 void SendResponse(URLResponsePtr response
);
45 void OnResponseBodyStreamReady(MojoResult result
);
47 void DidRead(uint32_t num_bytes
, bool completed_synchronously
);
49 NetworkContext
* context_
;
50 scoped_ptr
<net::URLRequest
> url_request_
;
51 Callback
<void(URLResponsePtr
)> callback_
;
52 ScopedDataPipeProducerHandle response_body_stream_
;
53 scoped_refptr
<NetToMojoPendingBuffer
> pending_write_
;
54 common::HandleWatcher handle_watcher_
;
55 uint32 response_body_buffer_size_
;
56 bool auto_follow_redirects_
;
58 base::WeakPtrFactory
<URLLoaderImpl
> weak_ptr_factory_
;
63 #endif // MOJO_SERVICES_NETWORK_URL_LOADER_IMPL_H_