Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / mojo / services / network / http_connection_impl.h
blobc54218d6dac846227aca72c904fb4dbad472eefc
1 // Copyright 2015 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_HTTP_CONNECTION_IMPL_H_
6 #define MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_
8 #include <set>
9 #include <string>
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "mojo/services/network/public/interfaces/http_connection.mojom.h"
14 #include "mojo/services/network/public/interfaces/http_message.mojom.h"
15 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
17 namespace net {
18 class HttpServerRequestInfo;
21 namespace mojo {
23 class HttpServerImpl;
25 class HttpConnectionImpl : public HttpConnection {
26 public:
27 // |server| must outlive this object.
28 HttpConnectionImpl(int connection_id,
29 HttpServerImpl* server,
30 HttpConnectionDelegatePtr delegate,
31 HttpConnectionPtr* connection);
33 ~HttpConnectionImpl() override;
35 void OnReceivedHttpRequest(const net::HttpServerRequestInfo& info);
36 void OnReceivedWebSocketRequest(const net::HttpServerRequestInfo& info);
37 void OnReceivedWebSocketMessage(const std::string& data);
39 private:
40 class SimpleDataPipeReader;
41 class WebSocketImpl;
43 // HttpConnection implementation.
44 void SetSendBufferSize(uint32_t size,
45 const SetSendBufferSizeCallback& callback) override;
46 void SetReceiveBufferSize(
47 uint32_t size,
48 const SetReceiveBufferSizeCallback& callback) override;
50 void OnConnectionError();
52 void OnFinishedReadingResponseBody(HttpResponsePtr response_ptr,
53 SimpleDataPipeReader* reader,
54 scoped_ptr<std::string> body);
56 void Close();
58 // Checks whether Close() has been called.
59 bool IsClosing() const { return !binding_.is_bound(); }
61 // Checks whether all wrap-up work has been done during the closing process.
62 // If yes, notifies the owner, which may result in the destruction of this
63 // object.
64 void NotifyOwnerCloseIfAllDone();
66 void OnWebSocketClosed();
68 const int connection_id_;
69 HttpServerImpl* const server_;
70 HttpConnectionDelegatePtr delegate_;
71 Binding<HttpConnection> binding_;
72 // Owns its elements.
73 std::set<SimpleDataPipeReader*> response_body_readers_;
75 scoped_ptr<WebSocketImpl> web_socket_;
77 DISALLOW_COPY_AND_ASSIGN(HttpConnectionImpl);
80 } // namespace mojo
82 #endif // MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_