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

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

Issue 8857004: Delete UDPClientSocket on same thread as creation. Also refactor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to fix hunk failure. 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/socket/socket_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_
7 #pragma once 7 #pragma once
8 8
9 #include "chrome/browser/extensions/extension_function.h" 9 #include "chrome/browser/extensions/extension_function.h"
10 10
11 #include <string> 11 #include <string>
12 12
13 namespace extensions { 13 namespace extensions {
14 14
15 class SocketController;
16
15 extern const char kBytesWrittenKey[]; 17 extern const char kBytesWrittenKey[];
16 extern const char kSocketIdKey[]; 18 extern const char kSocketIdKey[];
17 extern const char kUdpSocketType[]; 19 extern const char kUdpSocketType[];
18 20
21 class SocketApiFunction : public AsyncExtensionFunction {
22 protected:
23 // Set up for work. Guaranteed to happen on UI thread.
24 virtual bool Prepare() = 0;
25
26 // Do actual work. Guaranteed to happen on IO thread.
27 virtual void Work() = 0;
28
29 // Respond. Guaranteed to happen on UI thread.
30 virtual bool Respond() = 0;
31
32 virtual bool RunImpl() OVERRIDE;
33
34 SocketController* controller();
35
36 private:
37 void WorkOnIOThread();
38 void RespondOnUIThread();
39 };
40
19 // Many of these socket functions are synchronous in the sense that 41 // Many of these socket functions are synchronous in the sense that
20 // they don't involve blocking operations, but we've made them all 42 // they don't involve blocking operations, but we've made them all
21 // AsyncExtensionFunctions because the underlying UDPClientSocket 43 // AsyncExtensionFunctions because the underlying UDPClientSocket
22 // library wants all operations to happen on the same thread as the 44 // library wants all operations to happen on the same thread as the
23 // one that created the socket. Too bad. 45 // one that created the socket. Too bad.
24 46
25 class SocketCreateFunction : public AsyncExtensionFunction { 47 class SocketCreateFunction : public SocketApiFunction {
26 public:
27 SocketCreateFunction();
28 virtual ~SocketCreateFunction();
29 virtual bool RunImpl() OVERRIDE;
30
31 protected: 48 protected:
32 void WorkOnIOThread(); 49 virtual bool Prepare() OVERRIDE;
33 void RespondOnUIThread(); 50 virtual void Work() OVERRIDE;
51 virtual bool Respond() OVERRIDE;
34 52
35 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.create") 53 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.create")
36 }; 54 };
37 55
38 class SocketDestroyFunction : public AsyncExtensionFunction { 56 class SocketDestroyFunction : public SocketApiFunction {
39 public:
40 SocketDestroyFunction();
41 virtual ~SocketDestroyFunction();
42 virtual bool RunImpl() OVERRIDE;
43
44 protected: 57 protected:
45 void WorkOnIOThread(); 58 virtual bool Prepare() OVERRIDE;
46 void RespondOnUIThread(); 59 virtual void Work() OVERRIDE;
60 virtual bool Respond() OVERRIDE;
47 61
48 private: 62 private:
49 int socket_id_; 63 int socket_id_;
50 64
51 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.destroy") 65 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.destroy")
52 }; 66 };
53 67
54 class SocketConnectFunction : public AsyncExtensionFunction { 68 class SocketConnectFunction : public SocketApiFunction {
55 public:
56 SocketConnectFunction();
57 virtual ~SocketConnectFunction();
58 virtual bool RunImpl() OVERRIDE;
59
60 protected: 69 protected:
61 void WorkOnIOThread(); 70 virtual bool Prepare() OVERRIDE;
62 void RespondOnUIThread(); 71 virtual void Work() OVERRIDE;
72 virtual bool Respond() OVERRIDE;
63 73
64 private: 74 private:
65 int socket_id_; 75 int socket_id_;
66 std::string address_; 76 std::string address_;
67 int port_; 77 int port_;
68 78
69 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.connect") 79 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.connect")
70 }; 80 };
71 81
72 class SocketCloseFunction : public AsyncExtensionFunction { 82 class SocketCloseFunction : public SocketApiFunction {
73 public:
74 SocketCloseFunction();
75 virtual ~SocketCloseFunction();
76 virtual bool RunImpl() OVERRIDE;
77
78 protected: 83 protected:
79 void WorkOnIOThread(); 84 virtual bool Prepare() OVERRIDE;
80 void RespondOnUIThread(); 85 virtual void Work() OVERRIDE;
86 virtual bool Respond() OVERRIDE;
81 87
82 private: 88 private:
83 int socket_id_; 89 int socket_id_;
84 90
85 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.close") 91 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.close")
86 }; 92 };
87 93
88 class SocketWriteFunction : public AsyncExtensionFunction { 94 class SocketWriteFunction : public SocketApiFunction {
89 public: 95 protected:
90 SocketWriteFunction(); 96 virtual bool Prepare() OVERRIDE;
91 virtual ~SocketWriteFunction(); 97 virtual void Work() OVERRIDE;
92 virtual bool RunImpl() OVERRIDE; 98 virtual bool Respond() OVERRIDE;
93 99
94 protected: 100 private:
95 void WorkOnIOThread();
96 void RespondOnUIThread();
97
98 int socket_id_; 101 int socket_id_;
99 std::string message_; 102 std::string message_;
100 103
101 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.write") 104 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.write")
102 }; 105 };
103 106
104 } // namespace extensions 107 } // namespace extensions
105 108
106 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ 109 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/socket/socket_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698