Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: jingle/glue/fake_socket_factory.h

Issue 400093002: Remove jingle_glue_test_util target (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « jingle/glue/fake_network_manager.cc ('k') | jingle/glue/fake_socket_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #ifndef JINGLE_GLUE_FAKE_SOCKET_FACTORY_H_
6 #define JINGLE_GLUE_FAKE_SOCKET_FACTORY_H_
7
8 #include <map>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "net/base/ip_endpoint.h"
16 #include "third_party/libjingle/source/talk/base/asyncpacketsocket.h"
17 #include "third_party/libjingle/source/talk/p2p/base/packetsocketfactory.h"
18
19 namespace base {
20 class MessageLoop;
21 }
22
23 namespace jingle_glue {
24
25 class FakeSocketManager;
26
27 class FakeUDPPacketSocket : public talk_base::AsyncPacketSocket,
28 public base::NonThreadSafe {
29 public:
30 FakeUDPPacketSocket(FakeSocketManager* fake_socket_manager,
31 const net::IPEndPoint& address);
32 virtual ~FakeUDPPacketSocket();
33
34 const net::IPEndPoint& endpoint() const { return endpoint_; }
35 void DeliverPacket(const net::IPEndPoint& from,
36 const std::vector<char>& data);
37
38 // talk_base::AsyncPacketSocket implementation.
39 virtual talk_base::SocketAddress GetLocalAddress() const OVERRIDE;
40 virtual talk_base::SocketAddress GetRemoteAddress() const OVERRIDE;
41 virtual int Send(const void *pv, size_t cb,
42 const talk_base::PacketOptions& options) OVERRIDE;
43 virtual int SendTo(const void *pv, size_t cb,
44 const talk_base::SocketAddress& addr,
45 const talk_base::PacketOptions& options) OVERRIDE;
46 virtual int Close() OVERRIDE;
47 virtual State GetState() const OVERRIDE;
48 virtual int GetOption(talk_base::Socket::Option opt, int* value) OVERRIDE;
49 virtual int SetOption(talk_base::Socket::Option opt, int value) OVERRIDE;
50 virtual int GetError() const OVERRIDE;
51 virtual void SetError(int error) OVERRIDE;
52
53 private:
54 enum InternalState {
55 IS_OPEN,
56 IS_CLOSED,
57 };
58
59 scoped_refptr<FakeSocketManager> fake_socket_manager_;
60 net::IPEndPoint endpoint_;
61 talk_base::SocketAddress local_address_;
62 talk_base::SocketAddress remote_address_;
63 InternalState state_;
64 int error_;
65
66 DISALLOW_COPY_AND_ASSIGN(FakeUDPPacketSocket);
67 };
68
69 class FakeSocketManager : public base::RefCountedThreadSafe<FakeSocketManager> {
70 public:
71 FakeSocketManager();
72
73 void SendPacket(const net::IPEndPoint& from,
74 const net::IPEndPoint& to,
75 const std::vector<char>& data);
76
77 void AddSocket(FakeUDPPacketSocket* socket_factory);
78 void RemoveSocket(FakeUDPPacketSocket* socket_factory);
79
80 private:
81 friend class base::RefCountedThreadSafe<FakeSocketManager>;
82
83 ~FakeSocketManager();
84
85 void DeliverPacket(const net::IPEndPoint& from,
86 const net::IPEndPoint& to,
87 const std::vector<char>& data);
88
89 base::MessageLoop* message_loop_;
90 std::map<net::IPEndPoint, FakeUDPPacketSocket*> endpoints_;
91
92 DISALLOW_COPY_AND_ASSIGN(FakeSocketManager);
93 };
94
95 class FakeSocketFactory : public talk_base::PacketSocketFactory {
96 public:
97 FakeSocketFactory(FakeSocketManager* socket_manager,
98 const net::IPAddressNumber& address);
99 virtual ~FakeSocketFactory();
100
101 // talk_base::PacketSocketFactory implementation.
102 virtual talk_base::AsyncPacketSocket* CreateUdpSocket(
103 const talk_base::SocketAddress& local_address,
104 int min_port, int max_port) OVERRIDE;
105 virtual talk_base::AsyncPacketSocket* CreateServerTcpSocket(
106 const talk_base::SocketAddress& local_address, int min_port, int max_port,
107 int opts) OVERRIDE;
108 virtual talk_base::AsyncPacketSocket* CreateClientTcpSocket(
109 const talk_base::SocketAddress& local_address,
110 const talk_base::SocketAddress& remote_address,
111 const talk_base::ProxyInfo& proxy_info,
112 const std::string& user_agent,
113 int opts) OVERRIDE;
114
115 private:
116 scoped_refptr<FakeSocketManager> socket_manager_;
117 net::IPAddressNumber address_;
118 int last_allocated_port_;
119
120 DISALLOW_COPY_AND_ASSIGN(FakeSocketFactory);
121 };
122
123 } // namespace jingle_glue
124
125 #endif // JINGLE_GLUE_FAKE_SOCKET_FACTORY_H_
OLDNEW
« no previous file with comments | « jingle/glue/fake_network_manager.cc ('k') | jingle/glue/fake_socket_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698