[Android] Introduce new UMA action for when user copies Image URL from context menu
[chromium-blink-merge.git] / mojo / services / network / http_connection_impl.h
blob79fc72dbf46c011051d2f3684d366548817eb3ec
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"
16 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h"
18 namespace net {
19 class HttpServerRequestInfo;
22 namespace mojo {
24 class HttpServerImpl;
26 class HttpConnectionImpl : public HttpConnection,
27 public ErrorHandler {
28 public:
29 // |server| must outlive this object.
30 HttpConnectionImpl(int connection_id,
31 HttpServerImpl* server,
32 HttpConnectionDelegatePtr delegate,
33 HttpConnectionPtr* connection);
35 ~HttpConnectionImpl() override;
37 void OnReceivedHttpRequest(const net::HttpServerRequestInfo& info);
38 void OnReceivedWebSocketRequest(const net::HttpServerRequestInfo& info);
39 void OnReceivedWebSocketMessage(const std::string& data);
41 private:
42 class SimpleDataPipeReader;
43 class WebSocketImpl;
45 // HttpConnection implementation.
46 void SetSendBufferSize(uint32_t size,
47 const SetSendBufferSizeCallback& callback) override;
48 void SetReceiveBufferSize(
49 uint32_t size,
50 const SetReceiveBufferSizeCallback& callback) override;
52 // ErrorHandler implementation.
53 void OnConnectionError() override;
55 void OnFinishedReadingResponseBody(HttpResponsePtr response_ptr,
56 SimpleDataPipeReader* reader,
57 scoped_ptr<std::string> body);
59 void Close();
61 // Checks whether Close() has been called.
62 bool IsClosing() const { return !binding_.is_bound(); }
64 // Checks whether all wrap-up work has been done during the closing process.
65 // If yes, notifies the owner, which may result in the destruction of this
66 // object.
67 void NotifyOwnerCloseIfAllDone();
69 void OnWebSocketClosed();
71 const int connection_id_;
72 HttpServerImpl* const server_;
73 HttpConnectionDelegatePtr delegate_;
74 Binding<HttpConnection> binding_;
75 // Owns its elements.
76 std::set<SimpleDataPipeReader*> response_body_readers_;
78 scoped_ptr<WebSocketImpl> web_socket_;
80 DISALLOW_COPY_AND_ASSIGN(HttpConnectionImpl);
83 } // namespace mojo
85 #endif // MOJO_SERVICES_NETWORK_HTTP_CONNECTION_IMPL_H_