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_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/process.h" | 10 #include "base/process.h" |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "base/shared_memory.h" | 12 #include "base/shared_memory.h" |
13 #include "base/task.h" | 13 |
| 14 class Task; |
| 15 class MessageLoop; |
14 | 16 |
15 template <typename T> struct DefaultSingletonTraits; | 17 template <typename T> struct DefaultSingletonTraits; |
16 | 18 |
17 // Return the IPC channel to connect to the service process. | 19 // Return the IPC channel to connect to the service process. |
18 // | 20 // |
19 std::string GetServiceProcessChannelName(); | 21 std::string GetServiceProcessChannelName(); |
20 | 22 |
21 // Return a name that is scoped to this instance of the service process. We | 23 // Return a name that is scoped to this instance of the service process. We |
22 // use the user-data-dir as a scoping prefix. | 24 // use the user-data-dir as a scoping prefix. |
23 std::string GetServiceProcessScopedName(const std::string& append_str); | 25 std::string GetServiceProcessScopedName(const std::string& append_str); |
24 | 26 |
25 // 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 |
26 // use the user-data-dir and the version as a scoping prefix. | 28 // use the user-data-dir and the version as a scoping prefix. |
27 std::string GetServiceProcessScopedVersionedName(const std::string& append_str); | 29 std::string GetServiceProcessScopedVersionedName(const std::string& append_str); |
28 | 30 |
29 // The following methods are used in a process that acts as a client to the | 31 // The following methods are used in a process that acts as a client to the |
30 // service process (typically the browser process). | 32 // service process (typically the browser process). |
31 // -------------------------------------------------------------------------- | 33 // -------------------------------------------------------------------------- |
32 // This method checks that if the service process is ready to receive | 34 // This method checks that if the service process is ready to receive |
33 // IPC commands. | 35 // IPC commands. |
34 bool CheckServiceProcessReady(); | 36 bool CheckServiceProcessReady(); |
35 | 37 |
36 // Returns the process id of the currently running service process. Returns 0 | 38 // Returns the process id and version of the currently running service process. |
37 // if no service process is running. | |
38 // Note: DO NOT use this check whether the service process is ready because | 39 // Note: DO NOT use this check whether the service process is ready because |
39 // a non-zero return value only means that the process is running and not that | 40 // a true return value only means that some process shared data was available, |
40 // it is ready to receive IPC commands. This method is only exposed for testing. | 41 // and not that the process is ready to receive IPC commands, or even running. |
41 base::ProcessId GetServiceProcessPid(); | 42 // This method is only exposed for testing. |
| 43 bool GetServiceProcessSharedData(std::string* version, base::ProcessId* pid); |
42 // -------------------------------------------------------------------------- | 44 // -------------------------------------------------------------------------- |
43 | 45 |
44 // Forces a service process matching the specified version to shut down. | 46 // Forces a service process matching the specified version to shut down. |
45 bool ForceServiceProcessShutdown(const std::string& version); | 47 bool ForceServiceProcessShutdown(const std::string& version, |
| 48 base::ProcessId process_id); |
46 | 49 |
47 // This is a class that is used by the service process to signal events and | 50 // This is a class that is used by the service process to signal events and |
48 // share data with external clients. This class lives in this file because the | 51 // share data with external clients. This class lives in this file because the |
49 // internal data structures and mechanisms used by the utility methods above | 52 // internal data structures and mechanisms used by the utility methods above |
50 // and this class are shared. | 53 // and this class are shared. |
51 class ServiceProcessState { | 54 class ServiceProcessState { |
52 public: | 55 public: |
53 // Returns the singleton instance. | 56 // Returns the singleton instance. |
54 static ServiceProcessState* GetInstance(); | 57 static ServiceProcessState* GetInstance(); |
55 | 58 |
56 // Tries to become the sole service process for the current user data dir. | 59 // Tries to become the sole service process for the current user data dir. |
57 // Returns false if another service process is already running. | 60 // Returns false if another service process is already running. |
58 bool Initialize(); | 61 bool Initialize(); |
59 | 62 |
60 // Signal that the service process is ready. | 63 // Signal that the service process is ready. |
61 // This method is called when the service process is running and initialized. | 64 // This method is called when the service process is running and initialized. |
62 // |shutdown_task| is invoked when we get a shutdown request from another | 65 // |shutdown_task| is invoked when we get a shutdown request from another |
63 // process (in the same thread that called SignalReady). It can be NULL. | 66 // process (in the same thread that called SignalReady). It can be NULL. |
64 void SignalReady(Task* shutdown_task); | 67 // |message_loop| must be of type IO and is the loop that POSIX uses |
| 68 // to monitor the service process. |
| 69 bool SignalReady(MessageLoop *message_loop, Task* shutdown_task); |
65 | 70 |
66 // Signal that the service process is stopped. | 71 // Signal that the service process is stopped. |
67 void SignalStopped(); | 72 void SignalStopped(); |
68 | 73 |
69 // Register the service process to run on startup. | 74 // Register the service process to run on startup. |
70 bool AddToAutoRun(); | 75 bool AddToAutoRun(); |
71 | 76 |
72 // Unregister the service process to run on startup. | 77 // Unregister the service process to run on startup. |
73 bool RemoveFromAutoRun(); | 78 bool RemoveFromAutoRun(); |
74 | 79 |
(...skipping 11 matching lines...) Expand all Loading... |
86 // Acquires a singleton lock for the service process. A return value of false | 91 // Acquires a singleton lock for the service process. A return value of false |
87 // means that a service process instance is already running. | 92 // means that a service process instance is already running. |
88 bool TakeSingletonLock(); | 93 bool TakeSingletonLock(); |
89 | 94 |
90 // Key used to register the service process to auto-run. | 95 // Key used to register the service process to auto-run. |
91 std::string GetAutoRunKey(); | 96 std::string GetAutoRunKey(); |
92 | 97 |
93 // Tear down the platform specific state. | 98 // Tear down the platform specific state. |
94 void TearDownState(); | 99 void TearDownState(); |
95 | 100 |
96 // Allows each platform to specify whether it supports killing older versions. | |
97 bool ShouldHandleOtherVersion(); | |
98 // An opaque object that maintains state. The actual definition of this is | 101 // An opaque object that maintains state. The actual definition of this is |
99 // platform dependent. | 102 // platform dependent. |
100 struct StateData; | 103 struct StateData; |
101 StateData* state_; | 104 StateData* state_; |
102 scoped_ptr<base::SharedMemory> shared_mem_service_data_; | 105 scoped_ptr<base::SharedMemory> shared_mem_service_data_; |
103 | 106 |
104 friend struct DefaultSingletonTraits<ServiceProcessState>; | 107 friend struct DefaultSingletonTraits<ServiceProcessState>; |
105 }; | 108 }; |
106 | 109 |
107 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_H_ | 110 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_H_ |
OLD | NEW |