OLD | NEW |
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_SERVICE_PROCESS_SERVICE_PROCESS_CONTROL_H_ | 5 #ifndef CHROME_BROWSER_SERVICE_PROCESS_SERVICE_PROCESS_CONTROL_H_ |
6 #define CHROME_BROWSER_SERVICE_PROCESS_SERVICE_PROCESS_CONTROL_H_ | 6 #define CHROME_BROWSER_SERVICE_PROCESS_SERVICE_PROCESS_CONTROL_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 SERVICE_EVENT_DISABLE_BY_POLICY, | 53 SERVICE_EVENT_DISABLE_BY_POLICY, |
54 SERVICE_EVENT_LAUNCH, | 54 SERVICE_EVENT_LAUNCH, |
55 SERVICE_EVENT_LAUNCHED, | 55 SERVICE_EVENT_LAUNCHED, |
56 SERVICE_EVENT_LAUNCH_FAILED, | 56 SERVICE_EVENT_LAUNCH_FAILED, |
57 SERVICE_EVENT_CHANNEL_CONNECTED, | 57 SERVICE_EVENT_CHANNEL_CONNECTED, |
58 SERVICE_EVENT_CHANNEL_ERROR, | 58 SERVICE_EVENT_CHANNEL_ERROR, |
59 SERVICE_EVENT_INFO_REQUEST, | 59 SERVICE_EVENT_INFO_REQUEST, |
60 SERVICE_EVENT_INFO_REPLY, | 60 SERVICE_EVENT_INFO_REPLY, |
61 SERVICE_EVENT_HISTOGRAMS_REQUEST, | 61 SERVICE_EVENT_HISTOGRAMS_REQUEST, |
62 SERVICE_EVENT_HISTOGRAMS_REPLY, | 62 SERVICE_EVENT_HISTOGRAMS_REPLY, |
| 63 SERVICE_PRINTERS_REQUEST, |
| 64 SERVICE_PRINTERS_REPLY, |
63 SERVICE_EVENT_MAX, | 65 SERVICE_EVENT_MAX, |
64 }; | 66 }; |
65 | 67 |
66 typedef IDMap<ServiceProcessControl>::iterator iterator; | 68 typedef IDMap<ServiceProcessControl>::iterator iterator; |
67 typedef std::queue<IPC::Message> MessageQueue; | 69 typedef std::queue<IPC::Message> MessageQueue; |
68 typedef base::Callback<void(const cloud_print::CloudPrintProxyInfo&)> | 70 typedef base::Callback<void(const cloud_print::CloudPrintProxyInfo&)> |
69 CloudPrintProxyInfoHandler; | 71 CloudPrintProxyInfoCallback; |
| 72 typedef base::Callback<void(const std::vector<std::string>&)> |
| 73 PrintersCallback; |
70 | 74 |
71 // Returns the singleton instance of this class. | 75 // Returns the singleton instance of this class. |
72 static ServiceProcessControl* GetInstance(); | 76 static ServiceProcessControl* GetInstance(); |
73 | 77 |
74 // Return true if this object is connected to the service. | 78 // Return true if this object is connected to the service. |
75 // Virtual for testing. | 79 // Virtual for testing. |
76 virtual bool IsConnected() const; | 80 virtual bool IsConnected() const; |
77 | 81 |
78 // If no service process is currently running, creates a new service process | 82 // If no service process is currently running, creates a new service process |
79 // and connects to it. If a service process is already running this method | 83 // and connects to it. If a service process is already running this method |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Return true if the message was sent. | 115 // Return true if the message was sent. |
112 // Virtual for testing. | 116 // Virtual for testing. |
113 virtual bool Shutdown(); | 117 virtual bool Shutdown(); |
114 | 118 |
115 // Send request for cloud print proxy info (enabled state, email, proxy id). | 119 // Send request for cloud print proxy info (enabled state, email, proxy id). |
116 // The callback gets the information when received. | 120 // The callback gets the information when received. |
117 // Returns true if request was sent. Callback will be called only in case of | 121 // Returns true if request was sent. Callback will be called only in case of |
118 // reply from service. The method resets any previous callback. | 122 // reply from service. The method resets any previous callback. |
119 // This call starts service if needed. | 123 // This call starts service if needed. |
120 bool GetCloudPrintProxyInfo( | 124 bool GetCloudPrintProxyInfo( |
121 const CloudPrintProxyInfoHandler& cloud_print_status_callback); | 125 const CloudPrintProxyInfoCallback& cloud_print_status_callback); |
122 | 126 |
123 // Send request for histograms collected in service process. | 127 // Send request for histograms collected in service process. |
124 // Returns true if request was sent, and callback will be called in case of | 128 // Returns true if request was sent, and callback will be called in case of |
125 // success or timeout. The method resets any previous callback. | 129 // success or timeout. The method resets any previous callback. |
126 // Returns false if service is not running or other failure, callback will not | 130 // Returns false if service is not running or other failure, callback will not |
127 // be called in this case. | 131 // be called in this case. |
128 bool GetHistograms(const base::Closure& cloud_print_status_callback, | 132 bool GetHistograms(const base::Closure& cloud_print_status_callback, |
129 const base::TimeDelta& timeout); | 133 const base::TimeDelta& timeout); |
130 | 134 |
| 135 // Send request for printers available for cloud print proxy. |
| 136 // The callback gets the information when received. |
| 137 // Returns true if request was sent. Callback will be called only in case of |
| 138 // reply from service. The method resets any previous callback. |
| 139 // This call starts service if needed. |
| 140 bool GetPrinters(const PrintersCallback& enumerate_printers_callback); |
| 141 |
131 private: | 142 private: |
132 // This class is responsible for launching the service process on the | 143 // This class is responsible for launching the service process on the |
133 // PROCESS_LAUNCHER thread. | 144 // PROCESS_LAUNCHER thread. |
134 class Launcher | 145 class Launcher |
135 : public base::RefCountedThreadSafe<ServiceProcessControl::Launcher> { | 146 : public base::RefCountedThreadSafe<ServiceProcessControl::Launcher> { |
136 public: | 147 public: |
137 Launcher(ServiceProcessControl* process, base::CommandLine* cmd_line); | 148 Launcher(ServiceProcessControl* process, base::CommandLine* cmd_line); |
138 // Execute the command line to start the process asynchronously. After the | 149 // Execute the command line to start the process asynchronously. After the |
139 // command is executed |task| is called with the process handle on the UI | 150 // command is executed |task| is called with the process handle on the UI |
140 // thread. | 151 // thread. |
(...skipping 27 matching lines...) Expand all Loading... |
168 virtual ~ServiceProcessControl(); | 179 virtual ~ServiceProcessControl(); |
169 | 180 |
170 friend struct DefaultSingletonTraits<ServiceProcessControl>; | 181 friend struct DefaultSingletonTraits<ServiceProcessControl>; |
171 | 182 |
172 typedef std::vector<base::Closure> TaskList; | 183 typedef std::vector<base::Closure> TaskList; |
173 | 184 |
174 // Message handlers | 185 // Message handlers |
175 void OnCloudPrintProxyInfo( | 186 void OnCloudPrintProxyInfo( |
176 const cloud_print::CloudPrintProxyInfo& proxy_info); | 187 const cloud_print::CloudPrintProxyInfo& proxy_info); |
177 void OnHistograms(const std::vector<std::string>& pickled_histograms); | 188 void OnHistograms(const std::vector<std::string>& pickled_histograms); |
| 189 void OnPrinters(const std::vector<std::string>& printers); |
178 | 190 |
179 // Runs callback provided in |GetHistograms()|. | 191 // Runs callback provided in |GetHistograms()|. |
180 void RunHistogramsCallback(); | 192 void RunHistogramsCallback(); |
181 | 193 |
182 // Helper method to invoke all the callbacks based on success or failure. | 194 // Helper method to invoke all the callbacks based on success or failure. |
183 void RunConnectDoneTasks(); | 195 void RunConnectDoneTasks(); |
184 | 196 |
185 // Method called by Launcher when the service process is launched. | 197 // Method called by Launcher when the service process is launched. |
186 void OnProcessLaunched(); | 198 void OnProcessLaunched(); |
187 | 199 |
188 // Used internally to connect to the service process. | 200 // Used internally to connect to the service process. |
189 void ConnectInternal(); | 201 void ConnectInternal(); |
190 | 202 |
191 // Takes ownership of the pointer. Split out for testing. | 203 // Takes ownership of the pointer. Split out for testing. |
192 void SetChannel(IPC::ChannelProxy* channel); | 204 void SetChannel(IPC::ChannelProxy* channel); |
193 | 205 |
194 static void RunAllTasksHelper(TaskList* task_list); | 206 static void RunAllTasksHelper(TaskList* task_list); |
195 | 207 |
196 // IPC channel to the service process. | 208 // IPC channel to the service process. |
197 scoped_ptr<IPC::ChannelProxy> channel_; | 209 scoped_ptr<IPC::ChannelProxy> channel_; |
198 | 210 |
199 // Service process launcher. | 211 // Service process launcher. |
200 scoped_refptr<Launcher> launcher_; | 212 scoped_refptr<Launcher> launcher_; |
201 | 213 |
202 // Callbacks that get invoked when the channel is successfully connected. | 214 // Callbacks that get invoked when the channel is successfully connected. |
203 TaskList connect_success_tasks_; | 215 TaskList connect_success_tasks_; |
204 // Callbacks that get invoked when there was a connection failure. | 216 // Callbacks that get invoked when there was a connection failure. |
205 TaskList connect_failure_tasks_; | 217 TaskList connect_failure_tasks_; |
206 | 218 |
| 219 // Callback that gets invoked when a printers is received from |
| 220 // the cloud print proxy. |
| 221 PrintersCallback printers_callback_; |
| 222 |
207 // Callback that gets invoked when a status message is received from | 223 // Callback that gets invoked when a status message is received from |
208 // the cloud print proxy. | 224 // the cloud print proxy. |
209 CloudPrintProxyInfoHandler cloud_print_info_callback_; | 225 CloudPrintProxyInfoCallback cloud_print_info_callback_; |
210 | 226 |
211 // Callback that gets invoked when a message with histograms is received from | 227 // Callback that gets invoked when a message with histograms is received from |
212 // the service process. | 228 // the service process. |
213 base::Closure histograms_callback_; | 229 base::Closure histograms_callback_; |
214 | 230 |
215 content::NotificationRegistrar registrar_; | 231 content::NotificationRegistrar registrar_; |
216 | 232 |
217 // Callback that gets invoked if service didn't reply in time. | 233 // Callback that gets invoked if service didn't reply in time. |
218 base::CancelableClosure histograms_timeout_callback_; | 234 base::CancelableClosure histograms_timeout_callback_; |
219 }; | 235 }; |
220 | 236 |
221 #endif // CHROME_BROWSER_SERVICE_PROCESS_SERVICE_PROCESS_CONTROL_H_ | 237 #endif // CHROME_BROWSER_SERVICE_PROCESS_SERVICE_PROCESS_CONTROL_H_ |
OLD | NEW |