OLD | NEW |
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_SERVICE_SERVICE_PROCESS_CONTROL_H_ | 5 #ifndef CHROME_BROWSER_SERVICE_SERVICE_PROCESS_CONTROL_H_ |
6 #define CHROME_BROWSER_SERVICE_SERVICE_PROCESS_CONTROL_H_ | 6 #define CHROME_BROWSER_SERVICE_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 30 matching lines...) Expand all Loading... |
41 public IPC::Channel::Listener, | 41 public IPC::Channel::Listener, |
42 public content::NotificationObserver { | 42 public content::NotificationObserver { |
43 public: | 43 public: |
44 typedef IDMap<ServiceProcessControl>::iterator iterator; | 44 typedef IDMap<ServiceProcessControl>::iterator iterator; |
45 typedef std::queue<IPC::Message> MessageQueue; | 45 typedef std::queue<IPC::Message> MessageQueue; |
46 typedef base::Callback<void(const cloud_print::CloudPrintProxyInfo&)> | 46 typedef base::Callback<void(const cloud_print::CloudPrintProxyInfo&)> |
47 CloudPrintProxyInfoHandler; | 47 CloudPrintProxyInfoHandler; |
48 | 48 |
49 // Returns the singleton instance of this class. | 49 // Returns the singleton instance of this class. |
50 static ServiceProcessControl* GetInstance(); | 50 static ServiceProcessControl* GetInstance(); |
| 51 |
51 // Return true if this object is connected to the service. | 52 // Return true if this object is connected to the service. |
52 bool is_connected() const { return channel_.get() != NULL; } | 53 // Virtual for testing. |
| 54 virtual bool is_connected() const; |
53 | 55 |
54 // If no service process is currently running, creates a new service process | 56 // If no service process is currently running, creates a new service process |
55 // and connects to it. If a service process is already running this method | 57 // and connects to it. If a service process is already running this method |
56 // will try to connect to it. | 58 // will try to connect to it. |
57 // |success_task| is called when we have successfully launched the process | 59 // |success_task| is called when we have successfully launched the process |
58 // and connected to it. | 60 // and connected to it. |
59 // |failure_task| is called when we failed to connect to the service process. | 61 // |failure_task| is called when we failed to connect to the service process. |
60 // It is OK to pass the same value for |success_task| and |failure_task|. In | 62 // It is OK to pass the same value for |success_task| and |failure_task|. In |
61 // this case, the task is invoked on success or failure. | 63 // this case, the task is invoked on success or failure. |
62 // Note that if we are already connected to service process then | 64 // Note that if we are already connected to service process then |
63 // |success_task| can be invoked in the context of the Launch call. | 65 // |success_task| can be invoked in the context of the Launch call. |
64 void Launch(const base::Closure& success_task, | 66 // Virtual for testing. |
65 const base::Closure& failure_task); | 67 virtual void Launch(const base::Closure& success_task, |
| 68 const base::Closure& failure_task); |
66 | 69 |
67 // Disconnect the IPC channel from the service process. | 70 // Disconnect the IPC channel from the service process. |
68 void Disconnect(); | 71 // Virtual for testing. |
| 72 virtual void Disconnect(); |
69 | 73 |
70 // IPC::Channel::Listener implementation. | 74 // IPC::Channel::Listener implementation. |
71 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 75 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
72 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 76 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
73 virtual void OnChannelError() OVERRIDE; | 77 virtual void OnChannelError() OVERRIDE; |
74 | 78 |
75 // IPC::Channel::Sender implementation | 79 // IPC::Channel::Sender implementation |
76 virtual bool Send(IPC::Message* message); | 80 virtual bool Send(IPC::Message* message); |
77 | 81 |
78 // content::NotificationObserver implementation. | 82 // content::NotificationObserver implementation. |
79 virtual void Observe(int type, | 83 virtual void Observe(int type, |
80 const content::NotificationSource& source, | 84 const content::NotificationSource& source, |
81 const content::NotificationDetails& details); | 85 const content::NotificationDetails& details); |
82 | 86 |
83 // Message handlers | 87 // Message handlers |
84 void OnCloudPrintProxyInfo( | 88 void OnCloudPrintProxyInfo( |
85 const cloud_print::CloudPrintProxyInfo& proxy_info); | 89 const cloud_print::CloudPrintProxyInfo& proxy_info); |
86 | 90 |
87 // Send a shutdown message to the service process. IPC channel will be | 91 // Send a shutdown message to the service process. IPC channel will be |
88 // destroyed after calling this method. | 92 // destroyed after calling this method. |
89 // Return true if the message was sent. | 93 // Return true if the message was sent. |
90 bool Shutdown(); | 94 // Virtual for testing. |
| 95 virtual bool Shutdown(); |
91 | 96 |
92 // Send request for cloud print proxy info (enabled state, email, proxy id). | 97 // Send request for cloud print proxy info (enabled state, email, proxy id). |
93 // The callback gets the information when received. | 98 // The callback gets the information when received. |
94 bool GetCloudPrintProxyInfo( | 99 bool GetCloudPrintProxyInfo( |
95 const CloudPrintProxyInfoHandler& cloud_print_status_callback); | 100 const CloudPrintProxyInfoHandler& cloud_print_status_callback); |
96 | 101 |
97 private: | 102 private: |
98 // This class is responsible for launching the service process on the | 103 // This class is responsible for launching the service process on the |
99 // PROCESS_LAUNCHER thread. | 104 // PROCESS_LAUNCHER thread. |
100 class Launcher | 105 class Launcher |
(...skipping 17 matching lines...) Expand all Loading... |
118 | 123 |
119 void DoRun(); | 124 void DoRun(); |
120 void Notify(); | 125 void Notify(); |
121 ServiceProcessControl* process_; | 126 ServiceProcessControl* process_; |
122 scoped_ptr<CommandLine> cmd_line_; | 127 scoped_ptr<CommandLine> cmd_line_; |
123 base::Closure notify_task_; | 128 base::Closure notify_task_; |
124 bool launched_; | 129 bool launched_; |
125 uint32 retry_count_; | 130 uint32 retry_count_; |
126 }; | 131 }; |
127 | 132 |
| 133 friend class MockServiceProcessControl; |
128 ServiceProcessControl(); | 134 ServiceProcessControl(); |
129 virtual ~ServiceProcessControl(); | 135 virtual ~ServiceProcessControl(); |
130 | 136 |
131 friend struct DefaultSingletonTraits<ServiceProcessControl>; | 137 friend struct DefaultSingletonTraits<ServiceProcessControl>; |
132 | 138 |
133 typedef std::vector<base::Closure> TaskList; | 139 typedef std::vector<base::Closure> TaskList; |
134 | 140 |
135 // Helper method to invoke all the callbacks based on success or failure. | 141 // Helper method to invoke all the callbacks based on success or failure. |
136 void RunConnectDoneTasks(); | 142 void RunConnectDoneTasks(); |
137 | 143 |
(...skipping 17 matching lines...) Expand all Loading... |
155 TaskList connect_failure_tasks_; | 161 TaskList connect_failure_tasks_; |
156 | 162 |
157 // Callback that gets invoked when a status message is received from | 163 // Callback that gets invoked when a status message is received from |
158 // the cloud print proxy. | 164 // the cloud print proxy. |
159 CloudPrintProxyInfoHandler cloud_print_info_callback_; | 165 CloudPrintProxyInfoHandler cloud_print_info_callback_; |
160 | 166 |
161 content::NotificationRegistrar registrar_; | 167 content::NotificationRegistrar registrar_; |
162 }; | 168 }; |
163 | 169 |
164 #endif // CHROME_BROWSER_SERVICE_SERVICE_PROCESS_CONTROL_H_ | 170 #endif // CHROME_BROWSER_SERVICE_SERVICE_PROCESS_CONTROL_H_ |
OLD | NEW |