Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / extensions / browser / api / socket / udp_socket.h
blob9b63b2cccf9c0cbc2cc0f27d039a1e73ea4cbf3a
1 // Copyright 2014 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 EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_
6 #define EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_
8 #include <string>
9 #include <vector>
11 #include "extensions/browser/api/socket/socket.h"
12 #include "net/udp/udp_socket.h"
14 namespace extensions {
16 class UDPSocket : public Socket {
17 public:
18 explicit UDPSocket(const std::string& owner_extension_id);
19 ~UDPSocket() override;
21 void Connect(const std::string& address,
22 uint16 port,
23 const CompletionCallback& callback) override;
24 void Disconnect() override;
25 int Bind(const std::string& address, uint16 port) override;
26 void Read(int count, const ReadCompletionCallback& callback) override;
27 void RecvFrom(int count, const RecvFromCompletionCallback& callback) override;
28 void SendTo(scoped_refptr<net::IOBuffer> io_buffer,
29 int byte_count,
30 const std::string& address,
31 uint16 port,
32 const CompletionCallback& callback) override;
34 bool IsConnected() override;
36 bool GetPeerAddress(net::IPEndPoint* address) override;
37 bool GetLocalAddress(net::IPEndPoint* address) override;
38 Socket::SocketType GetSocketType() const override;
40 bool IsBound();
42 int JoinGroup(const std::string& address);
43 int LeaveGroup(const std::string& address);
45 int SetMulticastTimeToLive(int ttl);
46 int SetMulticastLoopbackMode(bool loopback);
48 int SetBroadcast(bool enabled);
50 const std::vector<std::string>& GetJoinedGroups() const;
52 protected:
53 int WriteImpl(net::IOBuffer* io_buffer,
54 int io_buffer_size,
55 const net::CompletionCallback& callback) override;
57 private:
58 // Make net::IPEndPoint can be refcounted
59 typedef base::RefCountedData<net::IPEndPoint> IPEndPoint;
61 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result);
62 void OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer,
63 scoped_refptr<IPEndPoint> address,
64 int result);
65 void OnSendToComplete(int result);
67 net::UDPSocket socket_;
69 ReadCompletionCallback read_callback_;
71 RecvFromCompletionCallback recv_from_callback_;
73 CompletionCallback send_to_callback_;
75 std::vector<std::string> multicast_groups_;
78 // UDP Socket instances from the "sockets.udp" namespace. These are regular
79 // socket objects with additional properties related to the behavior defined in
80 // the "sockets.udp" namespace.
81 class ResumableUDPSocket : public UDPSocket {
82 public:
83 explicit ResumableUDPSocket(const std::string& owner_extension_id);
85 // Overriden from ApiResource
86 bool IsPersistent() const override;
88 const std::string& name() const { return name_; }
89 void set_name(const std::string& name) { name_ = name; }
91 bool persistent() const { return persistent_; }
92 void set_persistent(bool persistent) { persistent_ = persistent; }
94 int buffer_size() const { return buffer_size_; }
95 void set_buffer_size(int buffer_size) { buffer_size_ = buffer_size; }
97 bool paused() const { return paused_; }
98 void set_paused(bool paused) { paused_ = paused; }
100 private:
101 friend class ApiResourceManager<ResumableUDPSocket>;
102 static const char* service_name() { return "ResumableUDPSocketManager"; }
104 // Application-defined string - see sockets_udp.idl.
105 std::string name_;
106 // Flag indicating whether the socket is left open when the application is
107 // suspended - see sockets_udp.idl.
108 bool persistent_;
109 // The size of the buffer used to receive data - see sockets_udp.idl.
110 int buffer_size_;
111 // Flag indicating whether a connected socket blocks its peer from sending
112 // more data - see sockets_udp.idl.
113 bool paused_;
116 } // namespace extensions
118 #endif // EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_