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