Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/common/service_process_util.h

Issue 5634005: Add a new GetInstance() method for singleton classes under chrome/service and /net. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 is another service process is already running.
willchan no longer on Chromium 2010/12/08 00:58:46 'is' should be 'if'.
Satish 2010/12/08 12:58:22 Done.
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();
72 private: 73 private:
willchan no longer on Chromium 2010/12/08 00:58:46 Add a newline. This is recommended in http://goog
Satish 2010/12/08 12:58:22 Done.
74 ServiceProcessState();
75 ~ServiceProcessState();
73 76
74 // Create the shared memory data for the service process. 77 // Create the shared memory data for the service process.
75 bool CreateSharedData(); 78 bool CreateSharedData();
76 79
77 // If an older version of the service process running, it should be shutdown. 80 // If an older version of the service process running, it should be shutdown.
78 // Returns false if this process needs to exit. 81 // Returns false if this process needs to exit.
79 bool HandleOtherVersion(); 82 bool HandleOtherVersion();
80 83
81 // Acquires a singleton lock for the service process. A return value of false 84 // Acquires a singleton lock for the service process. A return value of false
82 // means that a service process instance is already running. 85 // means that a service process instance is already running.
83 bool TakeSingletonLock(); 86 bool TakeSingletonLock();
84 87
85 // Key used to register the service process to auto-run. 88 // Key used to register the service process to auto-run.
86 std::string GetAutoRunKey(); 89 std::string GetAutoRunKey();
87 90
88 // Tear down the platform specific state. 91 // Tear down the platform specific state.
89 void TearDownState(); 92 void TearDownState();
90 93
91 // Allows each platform to specify whether it supports killing older versions. 94 // Allows each platform to specify whether it supports killing older versions.
92 bool ShouldHandleOtherVersion(); 95 bool ShouldHandleOtherVersion();
93 // An opaque object that maintains state. The actual definition of this is 96 // An opaque object that maintains state. The actual definition of this is
94 // platform dependent. 97 // platform dependent.
95 struct StateData; 98 struct StateData;
96 StateData* state_; 99 StateData* state_;
97 scoped_ptr<base::SharedMemory> shared_mem_service_data_; 100 scoped_ptr<base::SharedMemory> shared_mem_service_data_;
101
102 friend struct DefaultSingletonTraits<ServiceProcessState>;
98 }; 103 };
99 104
100 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_H_ 105 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/common/service_process_util.cc » ('j') | chrome/common/service_process_util_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698