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

Unified Diff: base/process_info_mac.cc

Issue 10561009: Consolidate RecordBrowserStartupTime() into one location (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Make getter thread-safe Created 8 years, 6 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
Index: base/process_info_mac.cc
diff --git a/base/process_info_mac.cc b/base/process_info_mac.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6ee90be2c42148209736e82b805fcf4391da3de4
--- /dev/null
+++ b/base/process_info_mac.cc
@@ -0,0 +1,50 @@
+// Copyright (c) 2012 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.
+
+#include "base/process_info.h"
+
+#include <sys/sysctl.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time.h"
+
+namespace {
+
+using base::Time;
+
+// Retrieve the process creation time in |process_creation_time|, returns
+// true on success.
+bool ProcessCreationTimeInternal(Time* process_creation_time) {
+ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
+ size_t len = 0;
+ if (sysctl(mib, arraysize(mib), NULL, &len, NULL, 0) < 0)
+ return false;
+
+ scoped_ptr_malloc<struct kinfo_proc>
+ proc(static_cast<struct kinfo_proc*>(malloc(len)));
+ if (sysctl(mib, arraysize(mib), proc.get(), &len, NULL, 0) < 0)
+ return false;
+ *process_creation_time =
Mark Mentovai 2012/06/19 15:47:08 Can you clean this up and get rid of the second st
+ base::Time::FromTimeVal(proc->kp_proc.p_un.__p_starttime);
Mark Mentovai 2012/06/19 15:47:08 Is the base:: qualifier necessary, since you’re us
+ return true;
+}
+
+} // namespace
+
+namespace base {
+
+//static
+const Time* CurrentProcessInfo::CreationTime() {
+ static Time process_creation_time;
+ static bool success = ProcessCreationTimeInternal(&process_creation_time);
Mark Mentovai 2012/06/19 15:47:08 These are the two statics I’m talking about. You o
+
+ if (!success)
+ return NULL;
+ return &process_creation_time;
+}
+
+} // namespace base
« no previous file with comments | « base/process_info.h ('k') | base/process_info_win.cc » ('j') | base/process_info_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698