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

Side by Side Diff: chrome/browser/extensions/api/serial/serial_api.h

Issue 10777003: Refactor APIResourceController to ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge/antony/fix build. Created 8 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
OLDNEW
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_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_API_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/extensions/api/api_function.h" 11 #include "chrome/browser/extensions/api/api_function.h"
12 #include "chrome/browser/extensions/api/api_resource_manager.h"
12 #include "chrome/common/extensions/api/experimental_serial.h" 13 #include "chrome/common/extensions/api/experimental_serial.h"
13 #include "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
14 15
15 namespace extensions { 16 namespace extensions {
16 17
17 class APIResourceEventNotifier; 18 class ApiResourceEventNotifier;
18 class SerialConnection; 19 class SerialConnection;
19 20
20 extern const char kConnectionIdKey[]; 21 extern const char kConnectionIdKey[];
21 22
22 class SerialGetPortsFunction : public AsyncAPIFunction { 23 class SerialAsyncApiFunction : public AsyncApiFunction {
24 public:
25 SerialAsyncApiFunction();
26
27 protected:
28 virtual ~SerialAsyncApiFunction();
29
30 // AsyncApiFunction:
31 virtual bool PrePrepare() OVERRIDE;
32
33 ApiResourceManager<SerialConnection>* manager_;
34 };
35
36 class SerialGetPortsFunction : public SerialAsyncApiFunction {
23 public: 37 public:
24 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.getPorts") 38 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.getPorts")
25 39
26 SerialGetPortsFunction(); 40 SerialGetPortsFunction();
27 41
28 protected: 42 protected:
29 virtual ~SerialGetPortsFunction() {} 43 virtual ~SerialGetPortsFunction() {}
30 44
31 // AsyncAPIFunction: 45 // AsyncApiFunction:
32 virtual bool Prepare() OVERRIDE; 46 virtual bool Prepare() OVERRIDE;
33 virtual void Work() OVERRIDE; 47 virtual void Work() OVERRIDE;
34 virtual bool Respond() OVERRIDE; 48 virtual bool Respond() OVERRIDE;
35 }; 49 };
36 50
37 class SerialOpenFunction : public AsyncAPIFunction { 51 class SerialOpenFunction : public SerialAsyncApiFunction {
38 public: 52 public:
39 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.open") 53 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.open")
40 54
41 SerialOpenFunction(); 55 SerialOpenFunction();
42 56
43 protected: 57 protected:
44 virtual ~SerialOpenFunction(); 58 virtual ~SerialOpenFunction();
45 59
46 // AsyncAPIFunction: 60 // AsyncApiFunction:
47 virtual bool Prepare() OVERRIDE; 61 virtual bool Prepare() OVERRIDE;
48 virtual void AsyncWorkStart() OVERRIDE; 62 virtual void AsyncWorkStart() OVERRIDE;
49 virtual void Work() OVERRIDE; 63 virtual void Work() OVERRIDE;
50 virtual bool Respond() OVERRIDE; 64 virtual bool Respond() OVERRIDE;
51 65
52 // Overrideable for testing. 66 // Overrideable for testing.
53 virtual SerialConnection* CreateSerialConnection( 67 virtual SerialConnection* CreateSerialConnection(
54 const std::string& port, 68 const std::string& port,
55 int bitrate, 69 int bitrate,
56 APIResourceEventNotifier* event_notifier); 70 ApiResourceEventNotifier* event_notifier);
57 virtual bool DoesPortExist(const std::string& port); 71 virtual bool DoesPortExist(const std::string& port);
58 72
59 private: 73 private:
60 scoped_ptr<api::experimental_serial::Open::Params> params_; 74 scoped_ptr<api::experimental_serial::Open::Params> params_;
61 int src_id_; 75 int src_id_;
62 int bitrate_; 76 int bitrate_;
63 77
64 // SerialConnection will take ownership. 78 // SerialConnection will take ownership.
65 APIResourceEventNotifier* event_notifier_; 79 ApiResourceEventNotifier* event_notifier_;
66 }; 80 };
67 81
68 class SerialCloseFunction : public AsyncAPIFunction { 82 class SerialCloseFunction : public SerialAsyncApiFunction {
69 public: 83 public:
70 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.close") 84 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.close")
71 85
72 SerialCloseFunction(); 86 SerialCloseFunction();
73 87
74 protected: 88 protected:
75 virtual ~SerialCloseFunction(); 89 virtual ~SerialCloseFunction();
76 90
77 // AsyncAPIFunction: 91 // AsyncApiFunction:
78 virtual bool Prepare() OVERRIDE; 92 virtual bool Prepare() OVERRIDE;
79 virtual void Work() OVERRIDE; 93 virtual void Work() OVERRIDE;
80 virtual bool Respond() OVERRIDE; 94 virtual bool Respond() OVERRIDE;
81 95
82 private: 96 private:
83 scoped_ptr<api::experimental_serial::Close::Params> params_; 97 scoped_ptr<api::experimental_serial::Close::Params> params_;
84 }; 98 };
85 99
86 class SerialReadFunction : public AsyncAPIFunction { 100 class SerialReadFunction : public SerialAsyncApiFunction {
87 public: 101 public:
88 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.read") 102 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.read")
89 103
90 SerialReadFunction(); 104 SerialReadFunction();
91 105
92 protected: 106 protected:
93 virtual ~SerialReadFunction(); 107 virtual ~SerialReadFunction();
94 108
95 // AsyncAPIFunction: 109 // AsyncApiFunction:
96 virtual bool Prepare() OVERRIDE; 110 virtual bool Prepare() OVERRIDE;
97 virtual void Work() OVERRIDE; 111 virtual void Work() OVERRIDE;
98 virtual bool Respond() OVERRIDE; 112 virtual bool Respond() OVERRIDE;
99 113
100 private: 114 private:
101 scoped_ptr<api::experimental_serial::Read::Params> params_; 115 scoped_ptr<api::experimental_serial::Read::Params> params_;
102 }; 116 };
103 117
104 class SerialWriteFunction : public AsyncAPIFunction { 118 class SerialWriteFunction : public SerialAsyncApiFunction {
105 public: 119 public:
106 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.write") 120 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.write")
107 121
108 SerialWriteFunction(); 122 SerialWriteFunction();
109 123
110 protected: 124 protected:
111 virtual ~SerialWriteFunction(); 125 virtual ~SerialWriteFunction();
112 126
113 // AsyncAPIFunction: 127 // AsyncApiFunction:
114 virtual bool Prepare() OVERRIDE; 128 virtual bool Prepare() OVERRIDE;
115 virtual void Work() OVERRIDE; 129 virtual void Work() OVERRIDE;
116 virtual bool Respond() OVERRIDE; 130 virtual bool Respond() OVERRIDE;
117 131
118 private: 132 private:
119 scoped_ptr<api::experimental_serial::Write::Params> params_; 133 scoped_ptr<api::experimental_serial::Write::Params> params_;
120 scoped_refptr<net::IOBuffer> io_buffer_; 134 scoped_refptr<net::IOBuffer> io_buffer_;
121 size_t io_buffer_size_; 135 size_t io_buffer_size_;
122 }; 136 };
123 137
124 class SerialFlushFunction : public AsyncAPIFunction { 138 class SerialFlushFunction : public SerialAsyncApiFunction {
125 public: 139 public:
126 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.flush") 140 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.flush")
127 141
128 SerialFlushFunction(); 142 SerialFlushFunction();
129 143
130 protected: 144 protected:
131 virtual ~SerialFlushFunction(); 145 virtual ~SerialFlushFunction();
132 146
133 // AsyncAPIFunction: 147 // AsyncApiFunction:
134 virtual bool Prepare() OVERRIDE; 148 virtual bool Prepare() OVERRIDE;
135 virtual void Work() OVERRIDE; 149 virtual void Work() OVERRIDE;
136 virtual bool Respond() OVERRIDE; 150 virtual bool Respond() OVERRIDE;
137 151
138 private: 152 private:
139 scoped_ptr<api::experimental_serial::Flush::Params> params_; 153 scoped_ptr<api::experimental_serial::Flush::Params> params_;
140 }; 154 };
141 155
142 class SerialGetControlSignalsFunction : public AsyncAPIFunction { 156 class SerialGetControlSignalsFunction : public SerialAsyncApiFunction {
143 public: 157 public:
144 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.getControlSignals") 158 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.getControlSignals")
145 159
146 SerialGetControlSignalsFunction(); 160 SerialGetControlSignalsFunction();
147 161
148 protected: 162 protected:
149 virtual ~SerialGetControlSignalsFunction(); 163 virtual ~SerialGetControlSignalsFunction();
150 164
151 // AsyncAPIFunction: 165 // AsyncApiFunction:
152 virtual bool Prepare() OVERRIDE; 166 virtual bool Prepare() OVERRIDE;
153 virtual void Work() OVERRIDE; 167 virtual void Work() OVERRIDE;
154 virtual bool Respond() OVERRIDE; 168 virtual bool Respond() OVERRIDE;
155 169
156 private: 170 private:
157 scoped_ptr<api::experimental_serial::GetControlSignals::Params> params_; 171 scoped_ptr<api::experimental_serial::GetControlSignals::Params> params_;
158 bool api_response_; 172 bool api_response_;
159 }; 173 };
160 174
161 class SerialSetControlSignalsFunction : public AsyncAPIFunction { 175 class SerialSetControlSignalsFunction : public SerialAsyncApiFunction {
162 public: 176 public:
163 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.setControlSignals") 177 DECLARE_EXTENSION_FUNCTION_NAME("experimental.serial.setControlSignals")
164 178
165 SerialSetControlSignalsFunction(); 179 SerialSetControlSignalsFunction();
166 180
167 protected: 181 protected:
168 virtual ~SerialSetControlSignalsFunction(); 182 virtual ~SerialSetControlSignalsFunction();
169 183
170 // AsyncAPIFunction: 184 // AsyncApiFunction:
171 virtual bool Prepare() OVERRIDE; 185 virtual bool Prepare() OVERRIDE;
172 virtual void Work() OVERRIDE; 186 virtual void Work() OVERRIDE;
173 virtual bool Respond() OVERRIDE; 187 virtual bool Respond() OVERRIDE;
174 188
175 private: 189 private:
176 scoped_ptr<api::experimental_serial::SetControlSignals::Params> params_; 190 scoped_ptr<api::experimental_serial::SetControlSignals::Params> params_;
177 }; 191 };
178 192
179 } // namespace extensions 193 } // namespace extensions
180 194
181 #endif // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_API_H_ 195 #endif // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_API_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/bluetooth/bluetooth_api.h ('k') | chrome/browser/extensions/api/serial/serial_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698