summaryrefslogtreecommitdiffstats
path: root/ipc/ipc_channel_posix.cc
diff options
context:
space:
mode:
authorsatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-04 23:00:10 +0000
committersatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-04 23:00:10 +0000
commit864b558217c75dbdebea9db3568056292d4cd274 (patch)
tree06bd9f240065ed47fab9ff415ae4cd49f21facf1 /ipc/ipc_channel_posix.cc
parent8c9e61a02aad4d8baa0f75ae7ac2f2f1963fffd6 (diff)
downloadchromium_src-864b558217c75dbdebea9db3568056292d4cd274.zip
chromium_src-864b558217c75dbdebea9db3568056292d4cd274.tar.gz
chromium_src-864b558217c75dbdebea9db3568056292d4cd274.tar.bz2
This CL add a GetInstance() method to singleton classes instead of relying on the callers to use Singleton<T>.
In some cases I have used the LazyInstance<T> pattern as that was simpler. This is a small step towards making all singleton classes use the Singleton<T> pattern within their code and not expect the callers to know about it. I have selected all files under src/app and src/base which use Singleton<T> in this CL. Once this CL goes in I'll work on the rest of the files. BUG=65298 TEST=all existing tests should continue to pass. Review URL: http://codereview.chromium.org/5527004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68300 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_channel_posix.cc')
-rw-r--r--ipc/ipc_channel_posix.cc18
1 files changed, 12 insertions, 6 deletions
diff --git a/ipc/ipc_channel_posix.cc b/ipc/ipc_channel_posix.cc
index 65a04e1..bbf13743 100644
--- a/ipc/ipc_channel_posix.cc
+++ b/ipc/ipc_channel_posix.cc
@@ -75,6 +75,10 @@ namespace {
class PipeMap {
public:
+ static PipeMap* GetInstance() {
+ return Singleton<PipeMap>::get();
+ }
+
// Lookup a given channel id. Return -1 if not found.
int Lookup(const std::string& channel_id) {
AutoLock locked(lock_);
@@ -115,13 +119,15 @@ class PipeMap {
Lock lock_;
typedef std::map<std::string, int> ChannelToFDMap;
ChannelToFDMap map_;
+
+ friend struct DefaultSingletonTraits<PipeMap>;
};
// Used to map a channel name to the equivalent FD # in the current process.
// Returns -1 if the channel is unknown.
int ChannelNameToFD(const std::string& channel_id) {
// See the large block comment above PipeMap for the reasoning here.
- const int fd = Singleton<PipeMap>()->Lookup(channel_id);
+ const int fd = PipeMap::GetInstance()->Lookup(channel_id);
if (fd != -1) {
int dup_fd = dup(fd);
@@ -305,17 +311,17 @@ Channel::ChannelImpl::~ChannelImpl() {
// static
void AddChannelSocket(const std::string& name, int socket) {
- Singleton<PipeMap>()->Insert(name, socket);
+ PipeMap::GetInstance()->Insert(name, socket);
}
// static
void RemoveAndCloseChannelSocket(const std::string& name) {
- Singleton<PipeMap>()->RemoveAndClose(name);
+ PipeMap::GetInstance()->RemoveAndClose(name);
}
// static
bool ChannelSocketExists(const std::string& name) {
- return Singleton<PipeMap>()->Lookup(name) != -1;
+ return PipeMap::GetInstance()->Lookup(name) != -1;
}
// static
@@ -512,7 +518,7 @@ bool Channel::ChannelImpl::ProcessIncomingMessages() {
DCHECK(bytes_read);
if (client_pipe_ != -1) {
- Singleton<PipeMap>()->RemoveAndClose(pipe_name_);
+ PipeMap::GetInstance()->RemoveAndClose(pipe_name_);
client_pipe_ = -1;
}
@@ -1021,7 +1027,7 @@ void Channel::ChannelImpl::Close() {
pipe_ = -1;
}
if (client_pipe_ != -1) {
- Singleton<PipeMap>()->RemoveAndClose(pipe_name_);
+ PipeMap::GetInstance()->RemoveAndClose(pipe_name_);
client_pipe_ = -1;
}
#if !defined(OS_MACOSX)