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

Side by Side Diff: sky/engine/testing/platform/platform_impl.cc

Issue 886263002: Move SharedTimer implementation into sky/engine (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: style Created 5 years, 10 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
« no previous file with comments | « sky/engine/testing/platform/platform_impl.h ('k') | sky/viewer/platform/platform_impl.h » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "sky/engine/testing/platform/platform_impl.h" 5 #include "sky/engine/testing/platform/platform_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "net/base/data_url.h" 13 #include "net/base/data_url.h"
14 #include "net/base/mime_util.h" 14 #include "net/base/mime_util.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 16
17 namespace sky { 17 namespace sky {
18 18
19 PlatformImpl::PlatformImpl() 19 PlatformImpl::PlatformImpl() {
20 : main_loop_(base::MessageLoop::current()),
21 shared_timer_func_(NULL),
22 shared_timer_fire_time_(0.0),
23 shared_timer_fire_time_was_set_while_suspended_(false),
24 shared_timer_suspended_(0) {
25 } 20 }
26 21
27 PlatformImpl::~PlatformImpl() { 22 PlatformImpl::~PlatformImpl() {
28 } 23 }
29 24
30 blink::WebString PlatformImpl::defaultLocale() { 25 blink::WebString PlatformImpl::defaultLocale() {
31 return blink::WebString::fromUTF8("en-US"); 26 return blink::WebString::fromUTF8("en-US");
32 } 27 }
33 28
34 double PlatformImpl::currentTime() {
35 return base::Time::Now().ToDoubleT();
36 }
37
38 double PlatformImpl::monotonicallyIncreasingTime() {
39 return base::TimeTicks::Now().ToInternalValue() /
40 static_cast<double>(base::Time::kMicrosecondsPerSecond);
41 }
42
43 void PlatformImpl::setSharedTimerFiredFunction(void (*func)()) {
44 shared_timer_func_ = func;
45 }
46
47 void PlatformImpl::setSharedTimerFireInterval(
48 double interval_seconds) {
49 shared_timer_fire_time_ = interval_seconds + monotonicallyIncreasingTime();
50 if (shared_timer_suspended_) {
51 shared_timer_fire_time_was_set_while_suspended_ = true;
52 return;
53 }
54
55 // By converting between double and int64 representation, we run the risk
56 // of losing precision due to rounding errors. Performing computations in
57 // microseconds reduces this risk somewhat. But there still is the potential
58 // of us computing a fire time for the timer that is shorter than what we
59 // need.
60 // As the event loop will check event deadlines prior to actually firing
61 // them, there is a risk of needlessly rescheduling events and of
62 // needlessly looping if sleep times are too short even by small amounts.
63 // This results in measurable performance degradation unless we use ceil() to
64 // always round up the sleep times.
65 int64 interval = static_cast<int64>(
66 ceil(interval_seconds * base::Time::kMillisecondsPerSecond)
67 * base::Time::kMicrosecondsPerMillisecond);
68
69 if (interval < 0)
70 interval = 0;
71
72 shared_timer_.Stop();
73 shared_timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds(interval),
74 this, &PlatformImpl::DoTimeout);
75 }
76
77 void PlatformImpl::stopSharedTimer() {
78 shared_timer_.Stop();
79 }
80
81 blink::WebUnitTestSupport* PlatformImpl::unitTestSupport() { 29 blink::WebUnitTestSupport* PlatformImpl::unitTestSupport() {
82 return &unit_test_support_; 30 return &unit_test_support_;
83 } 31 }
84 32
85 } // namespace sky 33 } // namespace sky
OLDNEW
« no previous file with comments | « sky/engine/testing/platform/platform_impl.h ('k') | sky/viewer/platform/platform_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698