| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_IMPL_H_ | 5 #ifndef CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_IMPL_H_ |
| 6 #define CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_IMPL_H_ | 6 #define CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_IMPL_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 } | 28 } |
| 29 | 29 |
| 30 class GURL; | 30 class GURL; |
| 31 | 31 |
| 32 class SyncWebSocketImpl : public SyncWebSocket { | 32 class SyncWebSocketImpl : public SyncWebSocket { |
| 33 public: | 33 public: |
| 34 explicit SyncWebSocketImpl(net::URLRequestContextGetter* context_getter); | 34 explicit SyncWebSocketImpl(net::URLRequestContextGetter* context_getter); |
| 35 virtual ~SyncWebSocketImpl(); | 35 virtual ~SyncWebSocketImpl(); |
| 36 | 36 |
| 37 // Overridden from SyncWebSocket: | 37 // Overridden from SyncWebSocket: |
| 38 virtual bool IsConnected() OVERRIDE; |
| 38 virtual bool Connect(const GURL& url) OVERRIDE; | 39 virtual bool Connect(const GURL& url) OVERRIDE; |
| 39 virtual bool Send(const std::string& message) OVERRIDE; | 40 virtual bool Send(const std::string& message) OVERRIDE; |
| 40 virtual bool ReceiveNextMessage(std::string* message) OVERRIDE; | 41 virtual bool ReceiveNextMessage(std::string* message) OVERRIDE; |
| 41 virtual bool HasNextMessage() OVERRIDE; | 42 virtual bool HasNextMessage() OVERRIDE; |
| 42 | 43 |
| 43 private: | 44 private: |
| 44 struct CoreTraits; | 45 struct CoreTraits; |
| 45 class Core : public WebSocketListener, | 46 class Core : public WebSocketListener, |
| 46 public base::RefCountedThreadSafe<Core, CoreTraits> { | 47 public base::RefCountedThreadSafe<Core, CoreTraits> { |
| 47 public: | 48 public: |
| 48 explicit Core(net::URLRequestContextGetter* context_getter); | 49 explicit Core(net::URLRequestContextGetter* context_getter); |
| 49 | 50 |
| 51 bool IsConnected(); |
| 52 |
| 50 bool Connect(const GURL& url); | 53 bool Connect(const GURL& url); |
| 51 | 54 |
| 52 bool Send(const std::string& message); | 55 bool Send(const std::string& message); |
| 53 | 56 |
| 54 bool ReceiveNextMessage(std::string* message); | 57 bool ReceiveNextMessage(std::string* message); |
| 55 | 58 |
| 56 bool HasNextMessage(); | 59 bool HasNextMessage(); |
| 57 | 60 |
| 58 // Overriden from WebSocketListener: | 61 // Overriden from WebSocketListener: |
| 59 virtual void OnMessageReceived(const std::string& message) OVERRIDE; | 62 virtual void OnMessageReceived(const std::string& message) OVERRIDE; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 80 void OnDestruct() const; | 83 void OnDestruct() const; |
| 81 | 84 |
| 82 scoped_refptr<net::URLRequestContextGetter> context_getter_; | 85 scoped_refptr<net::URLRequestContextGetter> context_getter_; |
| 83 | 86 |
| 84 // Only accessed on IO thread. | 87 // Only accessed on IO thread. |
| 85 scoped_ptr<WebSocket> socket_; | 88 scoped_ptr<WebSocket> socket_; |
| 86 | 89 |
| 87 base::Lock lock_; | 90 base::Lock lock_; |
| 88 | 91 |
| 89 // Protected by |lock_|. | 92 // Protected by |lock_|. |
| 90 bool closed_; | 93 bool is_connected_; |
| 91 | 94 |
| 92 // Protected by |lock_|. | 95 // Protected by |lock_|. |
| 93 std::list<std::string> received_queue_; | 96 std::list<std::string> received_queue_; |
| 94 | 97 |
| 95 // Protected by |lock_|. | 98 // Protected by |lock_|. |
| 96 // Signaled when the socket closes or a message is received. | 99 // Signaled when the socket closes or a message is received. |
| 97 base::ConditionVariable on_update_event_; | 100 base::ConditionVariable on_update_event_; |
| 98 }; | 101 }; |
| 99 | 102 |
| 100 scoped_refptr<Core> core_; | 103 scoped_refptr<Core> core_; |
| 101 }; | 104 }; |
| 102 | 105 |
| 103 struct SyncWebSocketImpl::CoreTraits { | 106 struct SyncWebSocketImpl::CoreTraits { |
| 104 static void Destruct(const SyncWebSocketImpl::Core* core) { | 107 static void Destruct(const SyncWebSocketImpl::Core* core) { |
| 105 core->OnDestruct(); | 108 core->OnDestruct(); |
| 106 } | 109 } |
| 107 }; | 110 }; |
| 108 | 111 |
| 109 #endif // CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_IMPL_H_ | 112 #endif // CHROME_TEST_CHROMEDRIVER_NET_SYNC_WEBSOCKET_IMPL_H_ |
| OLD | NEW |