summaryrefslogtreecommitdiff
path: root/base/memory
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2017-12-21 23:52:25 +0000
committerMathieu Chartier <mathieuc@google.com>2017-12-21 23:54:27 +0000
commit8abac493f652a1835c61e538919820aa77658a39 (patch)
treea9d13e0b40d89d8960e80b71a7c21e639ea6c2d5 /base/memory
parent618a67a769e94d35a8944051400310c5710a7884 (diff)
downloadlibchrome-8abac493f652a1835c61e538919820aa77658a39.tar.gz
Revert "Uprev the library to r462023 from Chromium"
This reverts commit fe2f52931e8e50253d06329d7bf0a4164c7ba580. Reason for revert: Mac build broken Change-Id: I3abd2ba6874ec5bd283ba17c36ad0b35bcc3d374
Diffstat (limited to 'base/memory')
-rw-r--r--base/memory/shared_memory_mac_unittest.cc8
-rw-r--r--base/memory/shared_memory_unittest.cc8
-rw-r--r--base/memory/singleton_objc.h60
3 files changed, 68 insertions, 8 deletions
diff --git a/base/memory/shared_memory_mac_unittest.cc b/base/memory/shared_memory_mac_unittest.cc
index 4ccee89deb..c7d20ec049 100644
--- a/base/memory/shared_memory_mac_unittest.cc
+++ b/base/memory/shared_memory_mac_unittest.cc
@@ -204,7 +204,7 @@ class SharedMemoryMacMultiProcessTest : public MultiProcessTest {
// similar tests.
service_name_ = CreateRandomServiceName();
server_port_.reset(BecomeMachServer(service_name_.c_str()));
- spawn_child_ = SpawnChild(name);
+ child_process_ = SpawnChild(name);
client_port_.reset(ReceiveMachPort(server_port_.get()));
}
@@ -221,7 +221,7 @@ class SharedMemoryMacMultiProcessTest : public MultiProcessTest {
// process.
mac::ScopedMachSendRight client_port_;
- base::SpawnChildResult spawn_child_;
+ base::Process child_process_;
DISALLOW_COPY_AND_ASSIGN(SharedMemoryMacMultiProcessTest);
};
@@ -237,7 +237,7 @@ TEST_F(SharedMemoryMacMultiProcessTest, MachBasedSharedMemory) {
SendMachPort(client_port_.get(), shared_memory->handle().GetMemoryObject(),
MACH_MSG_TYPE_COPY_SEND);
int rv = -1;
- ASSERT_TRUE(spawn_child_.process.WaitForExitWithTimeout(
+ ASSERT_TRUE(child_process_.WaitForExitWithTimeout(
TestTimeouts::action_timeout(), &rv));
EXPECT_EQ(0, rv);
}
@@ -277,7 +277,7 @@ TEST_F(SharedMemoryMacMultiProcessTest, MachBasedSharedMemoryWithOffset) {
SendMachPort(
client_port_.get(), shm.GetMemoryObject(), MACH_MSG_TYPE_COPY_SEND);
int rv = -1;
- ASSERT_TRUE(spawn_child_.process.WaitForExitWithTimeout(
+ ASSERT_TRUE(child_process_.WaitForExitWithTimeout(
TestTimeouts::action_timeout(), &rv));
EXPECT_EQ(0, rv);
}
diff --git a/base/memory/shared_memory_unittest.cc b/base/memory/shared_memory_unittest.cc
index d87fad01d3..19dedccb47 100644
--- a/base/memory/shared_memory_unittest.cc
+++ b/base/memory/shared_memory_unittest.cc
@@ -682,16 +682,16 @@ TEST_F(SharedMemoryProcessTest, SharedMemoryAcrossProcesses) {
// Start |kNumTasks| processes, each of which atomically increments the first
// word by 1.
- SpawnChildResult children[kNumTasks];
+ Process processes[kNumTasks];
for (int index = 0; index < kNumTasks; ++index) {
- children[index] = SpawnChild("SharedMemoryTestMain");
- ASSERT_TRUE(children[index].process.IsValid());
+ processes[index] = SpawnChild("SharedMemoryTestMain");
+ ASSERT_TRUE(processes[index].IsValid());
}
// Check that each process exited correctly.
int exit_code = 0;
for (int index = 0; index < kNumTasks; ++index) {
- EXPECT_TRUE(children[index].process.WaitForExit(&exit_code));
+ EXPECT_TRUE(processes[index].WaitForExit(&exit_code));
EXPECT_EQ(0, exit_code);
}
diff --git a/base/memory/singleton_objc.h b/base/memory/singleton_objc.h
new file mode 100644
index 0000000000..6df3f7757e
--- /dev/null
+++ b/base/memory/singleton_objc.h
@@ -0,0 +1,60 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Support for using the Singleton<T> pattern with Objective-C objects. A
+// SingletonObjC is the same as a Singleton, except the default traits are
+// appropriate for Objective-C objects. A typical Objective-C object of type
+// NSExampleType can be maintained as a singleton and accessed with:
+//
+// NSExampleType* exampleSingleton = SingletonObjC<NSExampleType>::get();
+//
+// The first time this is used, it will create exampleSingleton as the result
+// of [[NSExampleType alloc] init]. Subsequent calls will return the same
+// NSExampleType* object. The object will be released by calling
+// -[NSExampleType release] when Singleton's atexit routines run
+// (see singleton.h).
+//
+// For Objective-C objects initialized through means other than the
+// no-parameter -init selector, DefaultSingletonObjCTraits may be extended
+// as needed:
+//
+// struct FooSingletonTraits : public DefaultSingletonObjCTraits<Foo> {
+// static Foo* New() {
+// return [[Foo alloc] initWithName:@"selecty"];
+// }
+// };
+// ...
+// Foo* widgetSingleton = SingletonObjC<Foo, FooSingletonTraits>::get();
+
+#ifndef BASE_MEMORY_SINGLETON_OBJC_H_
+#define BASE_MEMORY_SINGLETON_OBJC_H_
+
+#import <Foundation/Foundation.h>
+#include "base/memory/singleton.h"
+
+// Singleton traits usable to manage traditional Objective-C objects, which
+// are instantiated by sending |alloc| and |init| messages, and are deallocated
+// in a memory-managed environment when their retain counts drop to 0 by
+// sending |release| messages.
+template<typename Type>
+struct DefaultSingletonObjCTraits : public DefaultSingletonTraits<Type> {
+ static Type* New() {
+ return [[Type alloc] init];
+ }
+
+ static void Delete(Type* object) {
+ [object release];
+ }
+};
+
+// Exactly like Singleton, but without the DefaultSingletonObjCTraits as the
+// default trait class. This makes it straightforward for Objective-C++ code
+// to hold Objective-C objects as singletons.
+template<typename Type,
+ typename Traits = DefaultSingletonObjCTraits<Type>,
+ typename DifferentiatingType = Type>
+class SingletonObjC : public Singleton<Type, Traits, DifferentiatingType> {
+};
+
+#endif // BASE_MEMORY_SINGLETON_OBJC_H_