OLD | NEW |
1 // Copyright (c) 2010 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_COMMON_SERVICE_PROCESS_UTIL_H_ | 5 #ifndef CHROME_COMMON_SERVICE_PROCESS_UTIL_H_ |
6 #define CHROME_COMMON_SERVICE_PROCESS_UTIL_H_ | 6 #define CHROME_COMMON_SERVICE_PROCESS_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/process.h" | 11 #include "base/process.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
14 #include "ipc/ipc_channel_handle.h" | 14 #include "ipc/ipc_channel_handle.h" |
15 | 15 |
16 class Task; | 16 class Task; |
17 class CommandLine; | 17 class CommandLine; |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class MessageLoopProxy; | 20 class MessageLoopProxy; |
21 } | 21 } |
22 | 22 |
23 template <typename T> struct DefaultSingletonTraits; | |
24 | |
25 // Return the IPC channel to connect to the service process. | 23 // Return the IPC channel to connect to the service process. |
26 IPC::ChannelHandle GetServiceProcessChannel(); | 24 IPC::ChannelHandle GetServiceProcessChannel(); |
27 | 25 |
28 #if !defined(OS_MACOSX) | 26 #if !defined(OS_MACOSX) |
29 // Return a name that is scoped to this instance of the service process. We | 27 // Return a name that is scoped to this instance of the service process. We |
30 // use the user-data-dir as a scoping prefix. | 28 // use the user-data-dir as a scoping prefix. |
31 std::string GetServiceProcessScopedName(const std::string& append_str); | 29 std::string GetServiceProcessScopedName(const std::string& append_str); |
32 | 30 |
33 // Return a name that is scoped to this instance of the service process. We | 31 // Return a name that is scoped to this instance of the service process. We |
34 // use the user-data-dir and the version as a scoping prefix. | 32 // use the user-data-dir and the version as a scoping prefix. |
(...skipping 18 matching lines...) Expand all Loading... |
53 // Forces a service process matching the specified version to shut down. | 51 // Forces a service process matching the specified version to shut down. |
54 bool ForceServiceProcessShutdown(const std::string& version, | 52 bool ForceServiceProcessShutdown(const std::string& version, |
55 base::ProcessId process_id); | 53 base::ProcessId process_id); |
56 | 54 |
57 // This is a class that is used by the service process to signal events and | 55 // This is a class that is used by the service process to signal events and |
58 // share data with external clients. This class lives in this file because the | 56 // share data with external clients. This class lives in this file because the |
59 // internal data structures and mechanisms used by the utility methods above | 57 // internal data structures and mechanisms used by the utility methods above |
60 // and this class are shared. | 58 // and this class are shared. |
61 class ServiceProcessState { | 59 class ServiceProcessState { |
62 public: | 60 public: |
63 // Returns the singleton instance. | 61 ServiceProcessState(); |
64 static ServiceProcessState* GetInstance(); | 62 ~ServiceProcessState(); |
65 | 63 |
66 // Tries to become the sole service process for the current user data dir. | 64 // Tries to become the sole service process for the current user data dir. |
67 // Returns false if another service process is already running. | 65 // Returns false if another service process is already running. |
68 bool Initialize(); | 66 bool Initialize(); |
69 | 67 |
70 // Signal that the service process is ready. | 68 // Signal that the service process is ready. |
71 // This method is called when the service process is running and initialized. | 69 // This method is called when the service process is running and initialized. |
72 // |shutdown_task| is invoked when we get a shutdown request from another | 70 // |shutdown_task| is invoked when we get a shutdown request from another |
73 // process (in the same thread that called SignalReady). It can be NULL. | 71 // process (in the same thread that called SignalReady). It can be NULL. |
74 // |message_loop_proxy| must be of type IO and is the loop that POSIX uses | 72 // |message_loop_proxy| must be of type IO and is the loop that POSIX uses |
75 // to monitor the service process. | 73 // to monitor the service process. |
76 bool SignalReady( | 74 bool SignalReady( |
77 base::MessageLoopProxy* message_loop_proxy, Task* shutdown_task); | 75 base::MessageLoopProxy* message_loop_proxy, Task* shutdown_task); |
78 | 76 |
79 // Signal that the service process is stopped. | 77 // Signal that the service process is stopped. |
80 void SignalStopped(); | 78 void SignalStopped(); |
81 | 79 |
82 // Register the service process to run on startup. | 80 // Register the service process to run on startup. |
83 bool AddToAutoRun(); | 81 bool AddToAutoRun(); |
84 | 82 |
85 // Unregister the service process to run on startup. | 83 // Unregister the service process to run on startup. |
86 bool RemoveFromAutoRun(); | 84 bool RemoveFromAutoRun(); |
87 | 85 |
88 // Return the channel handle used for communicating with the service. | 86 // Return the channel handle used for communicating with the service. |
89 IPC::ChannelHandle GetServiceProcessChannel(); | 87 IPC::ChannelHandle GetServiceProcessChannel(); |
90 | 88 |
91 private: | 89 private: |
92 ServiceProcessState(); | |
93 ~ServiceProcessState(); | |
94 | 90 |
95 #if !defined(OS_MACOSX) | 91 #if !defined(OS_MACOSX) |
96 // Create the shared memory data for the service process. | 92 // Create the shared memory data for the service process. |
97 bool CreateSharedData(); | 93 bool CreateSharedData(); |
98 | 94 |
99 // If an older version of the service process running, it should be shutdown. | 95 // If an older version of the service process running, it should be shutdown. |
100 // Returns false if this process needs to exit. | 96 // Returns false if this process needs to exit. |
101 bool HandleOtherVersion(); | 97 bool HandleOtherVersion(); |
102 | 98 |
103 // Acquires a singleton lock for the service process. A return value of false | 99 // Acquires a singleton lock for the service process. A return value of false |
(...skipping 10 matching lines...) Expand all Loading... |
114 // Initializes the command-line that can be used to autorun the service | 110 // Initializes the command-line that can be used to autorun the service |
115 // process. | 111 // process. |
116 void CreateAutoRunCommandLine(); | 112 void CreateAutoRunCommandLine(); |
117 | 113 |
118 // An opaque object that maintains state. The actual definition of this is | 114 // An opaque object that maintains state. The actual definition of this is |
119 // platform dependent. | 115 // platform dependent. |
120 struct StateData; | 116 struct StateData; |
121 StateData* state_; | 117 StateData* state_; |
122 scoped_ptr<base::SharedMemory> shared_mem_service_data_; | 118 scoped_ptr<base::SharedMemory> shared_mem_service_data_; |
123 scoped_ptr<CommandLine> autorun_command_line_; | 119 scoped_ptr<CommandLine> autorun_command_line_; |
124 | |
125 friend struct DefaultSingletonTraits<ServiceProcessState>; | |
126 }; | 120 }; |
127 | 121 |
128 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_H_ | 122 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_H_ |
OLD | NEW |