OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 9 |
10 #include "base/id_map.h" | 10 #include "base/id_map.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 // Return the user profile associated with this service process. | 48 // Return the user profile associated with this service process. |
49 Profile* profile() const { return profile_; } | 49 Profile* profile() const { return profile_; } |
50 | 50 |
51 // Return the type of this object. | 51 // Return the type of this object. |
52 ServiceProcessType type() const { return type_; } | 52 ServiceProcessType type() const { return type_; } |
53 | 53 |
54 // Return true if this object is connected to the service. | 54 // Return true if this object is connected to the service. |
55 bool is_connected() const { return channel_.get() != NULL; } | 55 bool is_connected() const { return channel_.get() != NULL; } |
56 | 56 |
57 // Initialize the connection to the service process. | |
58 // |connect_done_task| is invoked if the connection has succeeded or failed. | |
59 // User should call is_connected() to check the connection status. | |
60 void Connect(Task* connect_done_task); | |
61 | |
62 // Create a new service process and connects to it. | 57 // Create a new service process and connects to it. |
63 // |launch_done_task| is called if launching the service process has failed | 58 // |launch_done_task| is called if launching the service process has failed |
64 // or we have successfully launched the process and connected to it. | 59 // or we have successfully launched the process and connected to it. |
| 60 // If the service process is already running this method will try to connect |
| 61 // to the service process. |
65 void Launch(Task* launch_done_task); | 62 void Launch(Task* launch_done_task); |
66 | 63 |
67 // IPC::Channel::Listener implementation. | 64 // IPC::Channel::Listener implementation. |
68 virtual void OnMessageReceived(const IPC::Message& message); | 65 virtual void OnMessageReceived(const IPC::Message& message); |
69 virtual void OnChannelConnected(int32 peer_pid); | 66 virtual void OnChannelConnected(int32 peer_pid); |
70 virtual void OnChannelError(); | 67 virtual void OnChannelError(); |
71 | 68 |
72 // IPC::Channel::Sender implementation | 69 // IPC::Channel::Sender implementation |
73 virtual bool Send(IPC::Message* message); | 70 virtual bool Send(IPC::Message* message); |
74 | 71 |
(...skipping 17 matching lines...) Expand all Loading... |
92 void SetMessageHandler(MessageHandler* message_handler) { | 89 void SetMessageHandler(MessageHandler* message_handler) { |
93 message_handler_ = message_handler; | 90 message_handler_ = message_handler; |
94 } | 91 } |
95 | 92 |
96 private: | 93 private: |
97 class Launcher; | 94 class Launcher; |
98 | 95 |
99 // Method called by Launcher when the service process is launched. | 96 // Method called by Launcher when the service process is launched. |
100 void OnProcessLaunched(Task* launch_done_task); | 97 void OnProcessLaunched(Task* launch_done_task); |
101 | 98 |
102 // Used internally to connect to the service process. | 99 // Used internally to connect to the service process. |task| is executed |
103 void ConnectInternal(); | 100 // when the connection is made or an error occurred. |
| 101 void ConnectInternal(Task* task); |
104 | 102 |
105 Profile* profile_; | 103 Profile* profile_; |
106 ServiceProcessType type_; | 104 ServiceProcessType type_; |
107 | 105 |
108 // IPC channel to the service process. | 106 // IPC channel to the service process. |
109 scoped_ptr<IPC::SyncChannel> channel_; | 107 scoped_ptr<IPC::SyncChannel> channel_; |
110 | 108 |
111 // Service process launcher. | 109 // Service process launcher. |
112 scoped_refptr<Launcher> launcher_; | 110 scoped_refptr<Launcher> launcher_; |
113 | 111 |
114 // Callback that gets invoked when the channel is connected or failed to | 112 // Callback that gets invoked when the channel is connected or failed to |
115 // connect. | 113 // connect. |
116 scoped_ptr<Task> connect_done_task_; | 114 scoped_ptr<Task> connect_done_task_; |
117 | 115 |
118 // Handler for messages from service process. | 116 // Handler for messages from service process. |
119 MessageHandler* message_handler_; | 117 MessageHandler* message_handler_; |
120 }; | 118 }; |
121 | 119 |
122 #endif // CHROME_BROWSER_SERVICE_SERVICE_PROCESS_H_ | 120 #endif // CHROME_BROWSER_SERVICE_SERVICE_PROCESS_H_ |
OLD | NEW |