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

Unified Diff: base/memory/shared_memory_mac.cc

Issue 1406123010: reland 2: Switch back to field trial. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't use Mach on 10.6. Created 5 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/memory/shared_memory_handle.h ('k') | content/browser/loader/resource_buffer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/shared_memory_mac.cc
diff --git a/base/memory/shared_memory_mac.cc b/base/memory/shared_memory_mac.cc
index 799b8e3dfcda0acb8006e119d980bc411a17d6af..8f198dcbf75aaeab13c7ffcad774b0ec7e3ffbb7 100644
--- a/base/memory/shared_memory_mac.cc
+++ b/base/memory/shared_memory_mac.cc
@@ -13,7 +13,10 @@
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/logging.h"
+#include "base/mac/mac_util.h"
#include "base/mac/scoped_mach_vm.h"
+#include "base/metrics/field_trial.h"
+#include "base/metrics/histogram_macros.h"
#include "base/posix/eintr_wrapper.h"
#include "base/posix/safe_strerror.h"
#include "base/process/process_metrics.h"
@@ -29,6 +32,38 @@ namespace base {
namespace {
+const char kTrialName[] = "MacMemoryMechanism";
+const char kTrialMach[] = "Mach";
+const char kTrialPosix[] = "Posix";
+
+SharedMemoryHandle::Type GetABTestMechanism() {
+ static bool found_group = false;
+ static SharedMemoryHandle::Type group = SharedMemoryHandle::MACH;
+
+ if (found_group)
+ return group;
+
+ const std::string group_name =
+ base::FieldTrialList::FindFullName(kTrialName);
+ if (group_name == kTrialMach) {
+ group = SharedMemoryHandle::MACH;
+ found_group = true;
+ } else if (group_name == kTrialPosix) {
+ group = SharedMemoryHandle::POSIX;
+ found_group = true;
+ } else {
+ group = SharedMemoryHandle::MACH;
+ }
+
+ return group;
+}
+
+// Emits a histogram entry indicating which type of SharedMemory was created.
+void EmitMechanism(SharedMemoryHandle::Type type) {
+ UMA_HISTOGRAM_ENUMERATION("OSX.SharedMemory.Mechanism", type,
+ SharedMemoryHandle::TypeMax);
+}
+
// Returns whether the operation succeeded.
// |new_handle| is an output variable, populated on success. The caller takes
// ownership of the underlying memory object.
@@ -227,6 +262,22 @@ bool SharedMemory::CreateAnonymousPosix(size_t size) {
return Create(options);
}
+bool SharedMemory::CreateAndMapAnonymousMach(size_t size) {
+ SharedMemoryCreateOptions options;
+
+ if (mac::IsOSLionOrLater()) {
+ // A/B test the mechanism. Once the experiment is over, this will always be
+ // set to SharedMemoryHandle::MACH.
+ // http://crbug.com/547261
+ options.type = GetABTestMechanism();
+ } else {
+ // Mach shared memory isn't supported on OSX 10.6 or older.
+ options.type = SharedMemoryHandle::POSIX;
+ }
+ options.size = size;
+ return Create(options) && Map(size);
+}
+
// static
bool SharedMemory::GetSizeFromSharedMemoryHandle(
const SharedMemoryHandle& handle,
@@ -248,6 +299,8 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) {
if (options.size > static_cast<size_t>(std::numeric_limits<int>::max()))
return false;
+ EmitMechanism(options.type);
+
if (options.type == SharedMemoryHandle::MACH) {
shm_ = SharedMemoryHandle(options.size);
requested_size_ = options.size;
« no previous file with comments | « base/memory/shared_memory_handle.h ('k') | content/browser/loader/resource_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698