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

Side by Side Diff: base/time_mac.cc

Issue 3855001: Move scoped_cftyperef from base to base/mac, use the new namespace, and name ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/sys_string_conversions_mac.mm ('k') | chrome/app/breakpad_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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/time.h" 5 #include "base/time.h"
6 6
7 #include <CoreFoundation/CFDate.h> 7 #include <CoreFoundation/CFDate.h>
8 #include <CoreFoundation/CFTimeZone.h> 8 #include <CoreFoundation/CFTimeZone.h>
9 #include <mach/mach_time.h> 9 #include <mach/mach_time.h>
10 #include <sys/time.h> 10 #include <sys/time.h>
11 #include <time.h> 11 #include <time.h>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/scoped_cftyperef.h" 15 #include "base/mac/scoped_cftyperef.h"
16 16
17 namespace base { 17 namespace base {
18 18
19 // The Time routines in this file use Mach and CoreFoundation APIs, since the 19 // The Time routines in this file use Mach and CoreFoundation APIs, since the
20 // POSIX definition of time_t in Mac OS X wraps around after 2038--and 20 // POSIX definition of time_t in Mac OS X wraps around after 2038--and
21 // there are already cookie expiration dates, etc., past that time out in 21 // there are already cookie expiration dates, etc., past that time out in
22 // the field. Using CFDate prevents that problem, and using mach_absolute_time 22 // the field. Using CFDate prevents that problem, and using mach_absolute_time
23 // for TimeTicks gives us nice high-resolution interval timing. 23 // for TimeTicks gives us nice high-resolution interval timing.
24 24
25 // Time ----------------------------------------------------------------------- 25 // Time -----------------------------------------------------------------------
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 Time Time::FromExploded(bool is_local, const Exploded& exploded) { 63 Time Time::FromExploded(bool is_local, const Exploded& exploded) {
64 CFGregorianDate date; 64 CFGregorianDate date;
65 date.second = exploded.second + 65 date.second = exploded.second +
66 exploded.millisecond / static_cast<double>(kMillisecondsPerSecond); 66 exploded.millisecond / static_cast<double>(kMillisecondsPerSecond);
67 date.minute = exploded.minute; 67 date.minute = exploded.minute;
68 date.hour = exploded.hour; 68 date.hour = exploded.hour;
69 date.day = exploded.day_of_month; 69 date.day = exploded.day_of_month;
70 date.month = exploded.month; 70 date.month = exploded.month;
71 date.year = exploded.year; 71 date.year = exploded.year;
72 72
73 scoped_cftyperef<CFTimeZoneRef> 73 base::mac::ScopedCFTypeRef<CFTimeZoneRef>
74 time_zone(is_local ? CFTimeZoneCopySystem() : NULL); 74 time_zone(is_local ? CFTimeZoneCopySystem() : NULL);
75 CFAbsoluteTime seconds = CFGregorianDateGetAbsoluteTime(date, time_zone) + 75 CFAbsoluteTime seconds = CFGregorianDateGetAbsoluteTime(date, time_zone) +
76 kCFAbsoluteTimeIntervalSince1970; 76 kCFAbsoluteTimeIntervalSince1970;
77 return Time(static_cast<int64>(seconds * kMicrosecondsPerSecond) + 77 return Time(static_cast<int64>(seconds * kMicrosecondsPerSecond) +
78 kWindowsEpochDeltaMicroseconds); 78 kWindowsEpochDeltaMicroseconds);
79 } 79 }
80 80
81 void Time::Explode(bool is_local, Exploded* exploded) const { 81 void Time::Explode(bool is_local, Exploded* exploded) const {
82 CFAbsoluteTime seconds = 82 CFAbsoluteTime seconds =
83 (static_cast<double>((us_ - kWindowsEpochDeltaMicroseconds) / 83 (static_cast<double>((us_ - kWindowsEpochDeltaMicroseconds) /
84 kMicrosecondsPerSecond) - kCFAbsoluteTimeIntervalSince1970); 84 kMicrosecondsPerSecond) - kCFAbsoluteTimeIntervalSince1970);
85 85
86 scoped_cftyperef<CFTimeZoneRef> 86 base::mac::ScopedCFTypeRef<CFTimeZoneRef>
87 time_zone(is_local ? CFTimeZoneCopySystem() : NULL); 87 time_zone(is_local ? CFTimeZoneCopySystem() : NULL);
88 CFGregorianDate date = CFAbsoluteTimeGetGregorianDate(seconds, time_zone); 88 CFGregorianDate date = CFAbsoluteTimeGetGregorianDate(seconds, time_zone);
89 89
90 exploded->year = date.year; 90 exploded->year = date.year;
91 exploded->month = date.month; 91 exploded->month = date.month;
92 exploded->day_of_month = date.day; 92 exploded->day_of_month = date.day;
93 exploded->hour = date.hour; 93 exploded->hour = date.hour;
94 exploded->minute = date.minute; 94 exploded->minute = date.minute;
95 exploded->second = date.second; 95 exploded->second = date.second;
96 exploded->millisecond = 96 exploded->millisecond =
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 return TimeTicks(absolute_micro); 131 return TimeTicks(absolute_micro);
132 } 132 }
133 133
134 // static 134 // static
135 TimeTicks TimeTicks::HighResNow() { 135 TimeTicks TimeTicks::HighResNow() {
136 return Now(); 136 return Now();
137 } 137 }
138 138
139 } // namespace base 139 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_string_conversions_mac.mm ('k') | chrome/app/breakpad_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698