Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "base/process/process_info.h" | 5 #include "base/process/process_info.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <sys/stat.h> |
| 8 #include <sys/types.h> | |
| 9 #include <unistd.h> | |
| 8 | 10 |
| 9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/logging.h" | |
| 10 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 11 | 14 |
| 12 namespace { | 15 namespace { |
| 13 | 16 |
| 14 using base::Time; | 17 using base::Time; |
| 15 | 18 |
| 16 // Returns the process creation time, or NULL if an error occurred. | |
| 17 Time* ProcessCreationTimeInternal() { | 19 Time* ProcessCreationTimeInternal() { |
| 18 FILETIME creation_time = {}; | 20 struct stat result; |
| 19 FILETIME ignore = {}; | 21 int rv = stat("/proc/self", &result); |
| 20 if (::GetProcessTimes(::GetCurrentProcess(), &creation_time, &ignore, | 22 DCHECK(!rv); |
| 21 &ignore, &ignore) == false) | 23 if (rv) |
| 22 return NULL; | 24 return NULL; |
| 23 | 25 return new Time(Time::FromTimeT(result.st_ctime)); |
|
willchan no longer on Chromium
2013/07/31 05:01:07
Uh, what's freeing this memory?
James Simonsen
2013/08/02 01:31:40
Nobody. It's a singleton.
Are you implying I chan
willchan no longer on Chromium
2013/08/02 05:51:53
No, I screwed up. I thought ProcessCreationTimeInt
| |
| 24 return new Time(Time::FromFileTime(creation_time)); | |
| 25 } | 26 } |
| 26 | 27 |
| 27 } // namespace | 28 } // namespace |
| 28 | 29 |
| 29 namespace base { | 30 namespace base { |
| 30 | 31 |
| 31 //static | 32 //static |
| 32 const Time* CurrentProcessInfo::CreationTime() { | 33 const Time* CurrentProcessInfo::CreationTime() { |
| 33 static Time* process_creation_time = ProcessCreationTimeInternal(); | 34 static Time* process_creation_time = ProcessCreationTimeInternal(); |
| 34 return process_creation_time; | 35 return process_creation_time; |
| 35 } | 36 } |
| 36 | 37 |
| 37 } // namespace base | 38 } // namespace base |
| OLD | NEW |