| 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 #include "base/task.h" |
| 14 | 14 |
| 15 template <typename T> struct DefaultSingletonTraits; |
| 16 |
| 15 // Return the IPC channel to connect to the service process. | 17 // Return the IPC channel to connect to the service process. |
| 16 // | 18 // |
| 17 std::string GetServiceProcessChannelName(); | 19 std::string GetServiceProcessChannelName(); |
| 18 | 20 |
| 19 // Return a name that is scoped to this instance of the service process. We | 21 // Return a name that is scoped to this instance of the service process. We |
| 20 // use the user-data-dir as a scoping prefix. | 22 // use the user-data-dir as a scoping prefix. |
| 21 std::string GetServiceProcessScopedName(const std::string& append_str); | 23 std::string GetServiceProcessScopedName(const std::string& append_str); |
| 22 | 24 |
| 23 // Return a name that is scoped to this instance of the service process. We | 25 // Return a name that is scoped to this instance of the service process. We |
| 24 // use the user-data-dir and the version as a scoping prefix. | 26 // use the user-data-dir and the version as a scoping prefix. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 41 | 43 |
| 42 // Forces a service process matching the specified version to shut down. | 44 // Forces a service process matching the specified version to shut down. |
| 43 bool ForceServiceProcessShutdown(const std::string& version); | 45 bool ForceServiceProcessShutdown(const std::string& version); |
| 44 | 46 |
| 45 // This is a class that is used by the service process to signal events and | 47 // This is a class that is used by the service process to signal events and |
| 46 // share data with external clients. This class lives in this file because the | 48 // share data with external clients. This class lives in this file because the |
| 47 // internal data structures and mechanisms used by the utility methods above | 49 // internal data structures and mechanisms used by the utility methods above |
| 48 // and this class are shared. | 50 // and this class are shared. |
| 49 class ServiceProcessState { | 51 class ServiceProcessState { |
| 50 public: | 52 public: |
| 51 ServiceProcessState(); | 53 // Returns the singleton instance. |
| 52 ~ServiceProcessState(); | 54 static ServiceProcessState* GetInstance(); |
| 53 | 55 |
| 54 // Tries to become the sole service process for the current user data dir. | 56 // Tries to become the sole service process for the current user data dir. |
| 55 // Returns false is another service process is already running. | 57 // Returns false if another service process is already running. |
| 56 bool Initialize(); | 58 bool Initialize(); |
| 57 | 59 |
| 58 // Signal that the service process is ready. | 60 // Signal that the service process is ready. |
| 59 // This method is called when the service process is running and initialized. | 61 // This method is called when the service process is running and initialized. |
| 60 // |shutdown_task| is invoked when we get a shutdown request from another | 62 // |shutdown_task| is invoked when we get a shutdown request from another |
| 61 // process (in the same thread that called SignalReady). It can be NULL. | 63 // process (in the same thread that called SignalReady). It can be NULL. |
| 62 void SignalReady(Task* shutdown_task); | 64 void SignalReady(Task* shutdown_task); |
| 63 | 65 |
| 64 // Signal that the service process is stopped. | 66 // Signal that the service process is stopped. |
| 65 void SignalStopped(); | 67 void SignalStopped(); |
| 66 | 68 |
| 67 // Register the service process to run on startup. | 69 // Register the service process to run on startup. |
| 68 bool AddToAutoRun(); | 70 bool AddToAutoRun(); |
| 69 | 71 |
| 70 // Unregister the service process to run on startup. | 72 // Unregister the service process to run on startup. |
| 71 bool RemoveFromAutoRun(); | 73 bool RemoveFromAutoRun(); |
| 74 |
| 72 private: | 75 private: |
| 76 ServiceProcessState(); |
| 77 ~ServiceProcessState(); |
| 73 | 78 |
| 74 // Create the shared memory data for the service process. | 79 // Create the shared memory data for the service process. |
| 75 bool CreateSharedData(); | 80 bool CreateSharedData(); |
| 76 | 81 |
| 77 // If an older version of the service process running, it should be shutdown. | 82 // If an older version of the service process running, it should be shutdown. |
| 78 // Returns false if this process needs to exit. | 83 // Returns false if this process needs to exit. |
| 79 bool HandleOtherVersion(); | 84 bool HandleOtherVersion(); |
| 80 | 85 |
| 81 // Acquires a singleton lock for the service process. A return value of false | 86 // Acquires a singleton lock for the service process. A return value of false |
| 82 // means that a service process instance is already running. | 87 // means that a service process instance is already running. |
| 83 bool TakeSingletonLock(); | 88 bool TakeSingletonLock(); |
| 84 | 89 |
| 85 // Key used to register the service process to auto-run. | 90 // Key used to register the service process to auto-run. |
| 86 std::string GetAutoRunKey(); | 91 std::string GetAutoRunKey(); |
| 87 | 92 |
| 88 // Tear down the platform specific state. | 93 // Tear down the platform specific state. |
| 89 void TearDownState(); | 94 void TearDownState(); |
| 90 | 95 |
| 91 // Allows each platform to specify whether it supports killing older versions. | 96 // Allows each platform to specify whether it supports killing older versions. |
| 92 bool ShouldHandleOtherVersion(); | 97 bool ShouldHandleOtherVersion(); |
| 93 // An opaque object that maintains state. The actual definition of this is | 98 // An opaque object that maintains state. The actual definition of this is |
| 94 // platform dependent. | 99 // platform dependent. |
| 95 struct StateData; | 100 struct StateData; |
| 96 StateData* state_; | 101 StateData* state_; |
| 97 scoped_ptr<base::SharedMemory> shared_mem_service_data_; | 102 scoped_ptr<base::SharedMemory> shared_mem_service_data_; |
| 103 |
| 104 friend struct DefaultSingletonTraits<ServiceProcessState>; |
| 98 }; | 105 }; |
| 99 | 106 |
| 100 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_H_ | 107 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_H_ |
| OLD | NEW |