Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / mojo / services / network / url_loader_impl.h
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 "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.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"
15
16 namespace mojo {
17 class NetworkContext;
18
19 class URLLoaderImpl : public InterfaceImpl<URLLoader>,
20                       public net::URLRequest::Delegate {
21  public:
22   explicit URLLoaderImpl(NetworkContext* context);
23   virtual ~URLLoaderImpl();
24
25  private:
26   class PendingWriteToDataPipe;
27   class DependentIOBuffer;
28
29   // InterfaceImpl<> methods:
30   virtual void OnConnectionError() OVERRIDE;
31
32   // URLLoader methods:
33   virtual void Start(
34       URLRequestPtr request,
35       ScopedDataPipeProducerHandle response_body_stream) OVERRIDE;
36   virtual void FollowRedirect() OVERRIDE;
37
38   // net::URLRequest::Delegate methods:
39   virtual void OnReceivedRedirect(net::URLRequest* url_request,
40                                   const GURL& new_url,
41                                   bool* defer_redirect) OVERRIDE;
42   virtual void OnResponseStarted(net::URLRequest* url_request) OVERRIDE;
43   virtual void OnReadCompleted(net::URLRequest* url_request, int bytes_read)
44       OVERRIDE;
45
46   void SendError(int error);
47   void ReadMore();
48   void DidRead(uint32_t num_bytes, bool completed_synchronously);
49
50   NetworkContext* context_;
51   scoped_ptr<net::URLRequest> url_request_;
52   ScopedDataPipeProducerHandle response_body_stream_;
53   scoped_refptr<PendingWriteToDataPipe> pending_write_;
54   bool auto_follow_redirects_;
55
56   base::WeakPtrFactory<URLLoaderImpl> weak_ptr_factory_;
57 };
58
59 }  // namespace mojo
60
61 #endif  // MOJO_SERVICES_NETWORK_URL_LOADER_IMPL_H_