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

Side by Side Diff: chrome/browser/extensions/api/socket/socket_api_controller.h

Issue 8857004: Delete UDPClientSocket on same thread as creation. Also refactor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial. Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_CONTROLLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_CONTROLLER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_CONTROLLER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <map> 10 #include <map>
11 11
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/singleton.h"
14 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
15 #include "net/base/completion_callback.h" 14 #include "net/base/completion_callback.h"
16 15
17 class Profile; 16 class Profile;
18 17
19 namespace base { 18 namespace base {
20 class ListValue; 19 class ListValue;
21 class Value; 20 class Value;
22 } 21 }
23 22
24 namespace net { 23 namespace net {
25 class UDPClientSocket; 24 class UDPClientSocket;
26 class IPEndPoint; 25 class IPEndPoint;
27 } 26 }
28 27
29 namespace extensions { 28 namespace extensions {
30 29
31 class Socket; 30 class Socket;
32 31
33 // The SocketController singleton keeps track of all our Sockets, and provides 32 // SocketController keeps track of a collection of Sockets and provides a
34 // a convenient set of methods to manipulate them. 33 // convenient set of methods to manipulate them.
35 class SocketController { 34 class SocketController {
36 public: 35 public:
37 static SocketController* GetInstance();
38
39 SocketController(); 36 SocketController();
40 virtual ~SocketController(); 37 virtual ~SocketController();
41 38
42 // Create/Destroy are a pair. They represent the allocation and deallocation 39 // Create/Destroy are a pair. They represent the allocation and deallocation
43 // of the Socket object in memory. 40 // of the Socket object in memory.
44 // 41 //
45 // TODO(miket): we currently require the app developer to remember to call 42 // TODO(miket): we currently require the app developer to remember to call
46 // Destroy, which is a buzzkill in JavaScript. I believe that to solve this, 43 // Destroy, which is a buzzkill in JavaScript. I believe that to solve this,
47 // we'll have to associate each Socket with a creator extension, and then 44 // we'll have to associate each Socket with a creator extension, and then
48 // clean up when the extension goes out of scope. As the API is defined 45 // clean up when the extension goes out of scope. As the API is defined
(...skipping 18 matching lines...) Expand all
67 net::IPEndPoint* ip_end_point); 64 net::IPEndPoint* ip_end_point);
68 65
69 private: 66 private:
70 int next_socket_id_; 67 int next_socket_id_;
71 typedef std::map<int, Socket*> SocketMap; 68 typedef std::map<int, Socket*> SocketMap;
72 SocketMap socket_map_; 69 SocketMap socket_map_;
73 70
74 // Convenience method for accessing SocketMap. 71 // Convenience method for accessing SocketMap.
75 Socket* GetSocket(int socket_id); 72 Socket* GetSocket(int socket_id);
76 73
77 friend struct DefaultSingletonTraits<SocketController>;
78
79 DISALLOW_COPY_AND_ASSIGN(SocketController); 74 DISALLOW_COPY_AND_ASSIGN(SocketController);
80 }; 75 };
81 76
82 } // namespace extensions 77 } // namespace extensions
83 78
84 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_CONTROLLER_H_ 79 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698