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

Side by Side Diff: content/child/webthread_impl.cc

Issue 416453002: Move the shared timer to be dynamically allocated. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | « content/child/webthread_impl.h ('k') | no next file » | 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 // An implementation of WebThread in terms of base::MessageLoop and 5 // An implementation of WebThread in terms of base::MessageLoop and
6 // base::Thread 6 // base::Thread
7 7
8 #include <math.h> 8 #include <math.h>
9 9
10 #include "content/child/webthread_impl.h" 10 #include "content/child/webthread_impl.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 thread_->message_loop()->Quit(); 86 thread_->message_loop()->Quit();
87 } 87 }
88 88
89 bool WebThreadImpl::isCurrentThread() const { 89 bool WebThreadImpl::isCurrentThread() const {
90 return thread_->thread_id() == base::PlatformThread::CurrentId(); 90 return thread_->thread_id() == base::PlatformThread::CurrentId();
91 } 91 }
92 92
93 void WebThreadImpl::setSharedTimerFiredFunction( 93 void WebThreadImpl::setSharedTimerFiredFunction(
94 SharedTimerFunction timerFunction) { 94 SharedTimerFunction timerFunction) {
95 shared_timer_function_ = timerFunction; 95 shared_timer_function_ = timerFunction;
96 if (shared_timer_function_ != NULL)
97 shared_timer_.reset(new base::OneShotTimer<WebThreadImpl>());
98 else
99 shared_timer_.reset(NULL);
96 } 100 }
97 101
98 void WebThreadImpl::setSharedTimerFireInterval(double interval_seconds) { 102 void WebThreadImpl::setSharedTimerFireInterval(double interval_seconds) {
103 DCHECK(shared_timer_function_);
104
99 // See BlinkPlatformImpl::setSharedTimerFireInterval for explanation of 105 // See BlinkPlatformImpl::setSharedTimerFireInterval for explanation of
100 // why ceil is used in the interval calculation. 106 // why ceil is used in the interval calculation.
101 int64 interval = static_cast<int64>( 107 int64 interval = static_cast<int64>(
102 ceil(interval_seconds * base::Time::kMillisecondsPerSecond) 108 ceil(interval_seconds * base::Time::kMillisecondsPerSecond)
103 * base::Time::kMicrosecondsPerMillisecond); 109 * base::Time::kMicrosecondsPerMillisecond);
104 110
105 if (interval < 0) 111 if (interval < 0)
106 interval = 0; 112 interval = 0;
107 113
108 shared_timer_.Stop(); 114 shared_timer_->Stop();
109 shared_timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds(interval), 115 shared_timer_->Start(FROM_HERE, base::TimeDelta::FromMicroseconds(interval),
110 this, &WebThreadImpl::OnTimeout); 116 this, &WebThreadImpl::OnTimeout);
111 } 117 }
112 118
113 void WebThreadImpl::stopSharedTimer() { 119 void WebThreadImpl::stopSharedTimer() {
114 shared_timer_.Stop(); 120 DCHECK(shared_timer_function_);
121 shared_timer_->Stop();
115 } 122 }
116 123
117 WebThreadImpl::~WebThreadImpl() { 124 WebThreadImpl::~WebThreadImpl() {
118 thread_->Stop(); 125 thread_->Stop();
119 } 126 }
120 127
121 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( 128 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop(
122 base::MessageLoopProxy* message_loop) 129 base::MessageLoopProxy* message_loop)
123 : message_loop_(message_loop) {} 130 : message_loop_(message_loop) {}
124 131
(...skipping 23 matching lines...) Expand all
148 base::MessageLoop::current()->Quit(); 155 base::MessageLoop::current()->Quit();
149 } 156 }
150 157
151 bool WebThreadImplForMessageLoop::isCurrentThread() const { 158 bool WebThreadImplForMessageLoop::isCurrentThread() const {
152 return message_loop_->BelongsToCurrentThread(); 159 return message_loop_->BelongsToCurrentThread();
153 } 160 }
154 161
155 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {} 162 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {}
156 163
157 } // namespace content 164 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webthread_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698