blob: 54d7f2af302b64835eacf226ecb074ae09cbdafd [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// 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 Robinson646469d2014-10-03 15:33:28 -07008#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 Blundellb470fa12014-12-10 16:28:40 +010012#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
James Robinson646469d2014-10-03 15:33:28 -070013#include "net/base/net_errors.h"
14#include "net/url_request/url_request.h"
15
16namespace mojo {
James Robinsone2ac7e82014-10-15 13:21:59 -070017
James Robinson646469d2014-10-03 15:33:28 -070018class NetworkContext;
James Robinsone2ac7e82014-10-15 13:21:59 -070019class NetToMojoPendingBuffer;
James Robinson646469d2014-10-03 15:33:28 -070020
21class URLLoaderImpl : public InterfaceImpl<URLLoader>,
22 public net::URLRequest::Delegate {
23 public:
24 explicit URLLoaderImpl(NetworkContext* context);
James Robinsone1b30cf2014-10-21 12:25:40 -070025 ~URLLoaderImpl() override;
James Robinson646469d2014-10-03 15:33:28 -070026
27 private:
James Robinson646469d2014-10-03 15:33:28 -070028 // URLLoader methods:
James Robinsone1b30cf2014-10-21 12:25:40 -070029 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 Robinson646469d2014-10-03 15:33:28 -070033
34 // net::URLRequest::Delegate methods:
James Robinsone1b30cf2014-10-21 12:25:40 -070035 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 Robinson646469d2014-10-03 15:33:28 -070040
41 void SendError(
42 int error,
43 const Callback<void(URLResponsePtr)>& callback);
44 void SendResponse(URLResponsePtr response);
45 void OnResponseBodyStreamReady(MojoResult result);
James Robinson646469d2014-10-03 15:33:28 -070046 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 Robinsone2ac7e82014-10-15 13:21:59 -070053 scoped_refptr<NetToMojoPendingBuffer> pending_write_;
James Robinson646469d2014-10-03 15:33:28 -070054 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_