Chromium Code Reviews| Index: chrome/renderer/p2p/socket_client.h |
| diff --git a/chrome/renderer/p2p/socket_client.h b/chrome/renderer/p2p/socket_client.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1718ace9bb838caea156e9f4bcb9c3eb053651f7 |
| --- /dev/null |
| +++ b/chrome/renderer/p2p/socket_client.h |
| @@ -0,0 +1,71 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_RENDERER_P2P_SOCKET_CLIENT_H_ |
| +#define CHROME_RENDERER_P2P_SOCKET_CLIENT_H_ |
| + |
| +#include <vector> |
| + |
| +#include "base/ref_counted.h" |
| +#include "chrome/common/p2p_sockets.h" |
| + |
| +class P2PSocketsDispatcher; |
| +class Task; |
| + |
| +// P2P socket that rountes all calls over . Can be created |
|
awong
2011/03/01 20:21:55
Comment is unfinished.
Sergey Ulanov
2011/03/02 16:12:29
Done.
|
| +// and used from |
| +class P2PSocketClient : public base::RefCountedThreadSafe<P2PSocketClient> { |
|
Alpha Left Google
2011/03/01 21:32:20
Why is this refcounted? Should this be only used o
Sergey Ulanov
2011/03/02 16:12:29
It can be used from any thread. It will be used in
|
| + public: |
| + class Delegate { |
| + public: |
| + virtual ~Delegate(); |
| + |
| + virtual void OnOpen(P2PSocketAddress address) = 0; |
| + virtual void OnError() = 0; |
| + virtual void OnDataReceived(P2PSocketAddress address, |
| + const std::vector<char>& data) = 0; |
| + }; |
| + |
| + explicit P2PSocketClient(P2PSocketsDispatcher* dispatcher); |
| + ~P2PSocketClient(); |
|
awong
2011/03/01 20:21:55
Should the destructor be private or protected?
Sergey Ulanov
2011/03/02 16:12:29
Done.
|
| + |
| + // Initialize socket of the specified |type| and connected to the |
| + // specified |address|. |address| matters only when |type| is set to |
| + // P2P_SOCKET_TCP_CLIENT. |
| + void Init(P2PSocketType type, P2PSocketAddress address, Delegate* delegate); |
| + |
| + // Send the |data| to the |address|. |
| + void Send(P2PSocketAddress address, const std::vector<char>& data); |
| + |
| + // Must be called before the socket is destroyed. The delegate may |
| + // not be called after |closed_task| is executed. |
| + void Close(Task* closed_task); |
| + |
| + int id() const { return id_; } |
|
awong
2011/03/01 20:21:55
What is this id? Add comment?
Sergey Ulanov
2011/03/02 16:12:29
it is id of the socket. Renamed it to socket_id().
|
| + |
| + private: |
| + enum State { |
| + STATE_UNINITIALIZED, |
|
Alpha Left Google
2011/03/01 21:32:20
nit: use kStateXXX.
Sergey Ulanov
2011/03/02 16:12:29
http://www.chromium.org/developers/coding-style sa
|
| + STATE_OPENING, |
| + STATE_OPEN, |
| + STATE_CLOSED, |
| + STATE_ERROR, |
| + }; |
| + |
| + friend class P2PSocketsDispatcher; |
| + |
| + void OnSocketCreated(P2PSocketAddress address); |
| + void OnError(); |
| + void OnDataReceived(P2PSocketAddress address, |
| + const std::vector<char>& data); |
| + |
| + P2PSocketsDispatcher* dispatcher_; |
| + int id_; |
| + Delegate* delegate_; |
| + State state_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(P2PSocketClient); |
| +}; |
| + |
| +#endif // CHROME_RENDERER_P2P_SOCKET_CLIENT_H_ |