Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / mojo / services / network / url_loader_impl.h
blob0413487eee19a78446e2002afe604680a1b0e825
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/application/public/cpp/app_lifetime_helper.h"
11 #include "mojo/common/handle_watcher.h"
12 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
13 #include "net/base/net_errors.h"
14 #include "net/url_request/url_request.h"
15 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
16 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h"
18 namespace mojo {
20 class NetworkContext;
21 class NetToMojoPendingBuffer;
23 class URLLoaderImpl : public URLLoader,
24 public net::URLRequest::Delegate {
25 public:
26 URLLoaderImpl(NetworkContext* context,
27 InterfaceRequest<URLLoader> request,
28 scoped_ptr<mojo::AppRefCount> app_refcount);
29 ~URLLoaderImpl() override;
31 // Called when the associated NetworkContext is going away.
32 void Cleanup();
34 private:
35 // URLLoader methods:
36 void Start(URLRequestPtr request,
37 const Callback<void(URLResponsePtr)>& callback) override;
38 void FollowRedirect(const Callback<void(URLResponsePtr)>& callback) override;
39 void QueryStatus(const Callback<void(URLLoaderStatusPtr)>& callback) override;
41 void OnConnectionError();
43 // net::URLRequest::Delegate methods:
44 void OnReceivedRedirect(net::URLRequest* url_request,
45 const net::RedirectInfo& redirect_info,
46 bool* defer_redirect) override;
47 void OnResponseStarted(net::URLRequest* url_request) override;
48 void OnReadCompleted(net::URLRequest* url_request, int bytes_read) override;
50 void SendError(
51 int error,
52 const Callback<void(URLResponsePtr)>& callback);
53 void SendResponse(URLResponsePtr response);
54 void OnResponseBodyStreamReady(MojoResult result);
55 void OnResponseBodyStreamClosed(MojoResult result);
56 void ReadMore();
57 void DidRead(uint32_t num_bytes, bool completed_synchronously);
58 void ListenForPeerClosed();
59 void DeleteIfNeeded();
61 NetworkContext* context_;
62 scoped_ptr<net::URLRequest> url_request_;
63 Callback<void(URLResponsePtr)> callback_;
64 ScopedDataPipeProducerHandle response_body_stream_;
65 scoped_refptr<NetToMojoPendingBuffer> pending_write_;
66 common::HandleWatcher handle_watcher_;
67 uint32 response_body_buffer_size_;
68 bool auto_follow_redirects_;
69 bool connected_;
70 Binding<URLLoader> binding_;
71 scoped_ptr<mojo::AppRefCount> app_refcount_;
73 base::WeakPtrFactory<URLLoaderImpl> weak_ptr_factory_;
76 } // namespace mojo
78 #endif // MOJO_SERVICES_NETWORK_URL_LOADER_IMPL_H_