| OLD | NEW |
| 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 "components/html_viewer/blink_platform_impl.h" | 5 #include "components/html_viewer/blink_platform_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 scoped_ptr<base::WaitableEvent> impl_; | 55 scoped_ptr<base::WaitableEvent> impl_; |
| 56 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); | 56 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 | 60 |
| 61 BlinkPlatformImpl::BlinkPlatformImpl( | 61 BlinkPlatformImpl::BlinkPlatformImpl( |
| 62 mojo::ApplicationImpl* app, | 62 mojo::ApplicationImpl* app, |
| 63 scheduler::RendererScheduler* renderer_scheduler) | 63 scheduler::RendererScheduler* renderer_scheduler) |
| 64 : main_thread_task_runner_(renderer_scheduler->DefaultTaskRunner()), | 64 : main_thread_task_runner_(renderer_scheduler->DefaultTaskRunner()), |
| 65 main_thread_( | 65 main_thread_(new scheduler::WebThreadImplForRendererScheduler( |
| 66 new scheduler::WebThreadImplForRendererScheduler(renderer_scheduler)), | 66 renderer_scheduler)) { |
| 67 shared_timer_func_(NULL), | |
| 68 shared_timer_fire_time_(0.0), | |
| 69 shared_timer_fire_time_was_set_while_suspended_(false), | |
| 70 shared_timer_suspended_(0) { | |
| 71 if (app) { | 67 if (app) { |
| 72 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 68 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 73 request->url = mojo::String::From("mojo:network_service"); | 69 request->url = mojo::String::From("mojo:network_service"); |
| 74 mojo::ApplicationConnection* connection = | 70 mojo::ApplicationConnection* connection = |
| 75 app->ConnectToApplication(request.Pass()); | 71 app->ConnectToApplication(request.Pass()); |
| 76 connection->ConnectToService(&network_service_); | 72 connection->ConnectToService(&network_service_); |
| 77 connection->ConnectToService(&url_loader_factory_); | 73 connection->ConnectToService(&url_loader_factory_); |
| 78 | 74 |
| 79 mojo::CookieStorePtr cookie_store; | 75 mojo::CookieStorePtr cookie_store; |
| 80 network_service_->GetCookieStore(GetProxy(&cookie_store)); | 76 network_service_->GetCookieStore(GetProxy(&cookie_store)); |
| 81 cookie_jar_.reset(new WebCookieJarImpl(cookie_store.Pass())); | 77 cookie_jar_.reset(new WebCookieJarImpl(cookie_store.Pass())); |
| 82 | 78 |
| 83 mojo::ClipboardPtr clipboard; | 79 mojo::ClipboardPtr clipboard; |
| 84 mojo::URLRequestPtr request2(mojo::URLRequest::New()); | 80 mojo::URLRequestPtr request2(mojo::URLRequest::New()); |
| 85 request2->url = mojo::String::From("mojo:clipboard"); | 81 request2->url = mojo::String::From("mojo:clipboard"); |
| 86 app->ConnectToService(request2.Pass(), &clipboard); | 82 app->ConnectToService(request2.Pass(), &clipboard); |
| 87 clipboard_.reset(new WebClipboardImpl(clipboard.Pass())); | 83 clipboard_.reset(new WebClipboardImpl(clipboard.Pass())); |
| 88 } | 84 } |
| 89 shared_timer_.SetTaskRunner(main_thread_task_runner_); | |
| 90 } | 85 } |
| 91 | 86 |
| 92 BlinkPlatformImpl::~BlinkPlatformImpl() { | 87 BlinkPlatformImpl::~BlinkPlatformImpl() { |
| 93 } | 88 } |
| 94 | 89 |
| 95 blink::WebCookieJar* BlinkPlatformImpl::cookieJar() { | 90 blink::WebCookieJar* BlinkPlatformImpl::cookieJar() { |
| 96 return cookie_jar_.get(); | 91 return cookie_jar_.get(); |
| 97 } | 92 } |
| 98 | 93 |
| 99 blink::WebClipboard* BlinkPlatformImpl::clipboard() { | 94 blink::WebClipboard* BlinkPlatformImpl::clipboard() { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 123 double BlinkPlatformImpl::monotonicallyIncreasingTime() { | 118 double BlinkPlatformImpl::monotonicallyIncreasingTime() { |
| 124 return base::TimeTicks::Now().ToInternalValue() / | 119 return base::TimeTicks::Now().ToInternalValue() / |
| 125 static_cast<double>(base::Time::kMicrosecondsPerSecond); | 120 static_cast<double>(base::Time::kMicrosecondsPerSecond); |
| 126 } | 121 } |
| 127 | 122 |
| 128 void BlinkPlatformImpl::cryptographicallyRandomValues(unsigned char* buffer, | 123 void BlinkPlatformImpl::cryptographicallyRandomValues(unsigned char* buffer, |
| 129 size_t length) { | 124 size_t length) { |
| 130 base::RandBytes(buffer, length); | 125 base::RandBytes(buffer, length); |
| 131 } | 126 } |
| 132 | 127 |
| 133 void BlinkPlatformImpl::setSharedTimerFiredFunction(void (*func)()) { | |
| 134 shared_timer_func_ = func; | |
| 135 } | |
| 136 | |
| 137 void BlinkPlatformImpl::setSharedTimerFireInterval( | |
| 138 double interval_seconds) { | |
| 139 shared_timer_fire_time_ = interval_seconds + monotonicallyIncreasingTime(); | |
| 140 if (shared_timer_suspended_) { | |
| 141 shared_timer_fire_time_was_set_while_suspended_ = true; | |
| 142 return; | |
| 143 } | |
| 144 | |
| 145 // By converting between double and int64 representation, we run the risk | |
| 146 // of losing precision due to rounding errors. Performing computations in | |
| 147 // microseconds reduces this risk somewhat. But there still is the potential | |
| 148 // of us computing a fire time for the timer that is shorter than what we | |
| 149 // need. | |
| 150 // As the event loop will check event deadlines prior to actually firing | |
| 151 // them, there is a risk of needlessly rescheduling events and of | |
| 152 // needlessly looping if sleep times are too short even by small amounts. | |
| 153 // This results in measurable performance degradation unless we use ceil() to | |
| 154 // always round up the sleep times. | |
| 155 int64 interval = static_cast<int64>( | |
| 156 ceil(interval_seconds * base::Time::kMillisecondsPerSecond) | |
| 157 * base::Time::kMicrosecondsPerMillisecond); | |
| 158 | |
| 159 if (interval < 0) | |
| 160 interval = 0; | |
| 161 | |
| 162 shared_timer_.Stop(); | |
| 163 shared_timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds(interval), | |
| 164 this, &BlinkPlatformImpl::DoTimeout); | |
| 165 } | |
| 166 | |
| 167 void BlinkPlatformImpl::stopSharedTimer() { | |
| 168 shared_timer_.Stop(); | |
| 169 } | |
| 170 | |
| 171 bool BlinkPlatformImpl::isThreadedCompositingEnabled() { | 128 bool BlinkPlatformImpl::isThreadedCompositingEnabled() { |
| 172 return true; | 129 return true; |
| 173 } | 130 } |
| 174 | 131 |
| 175 blink::WebCompositorSupport* BlinkPlatformImpl::compositorSupport() { | 132 blink::WebCompositorSupport* BlinkPlatformImpl::compositorSupport() { |
| 176 return &compositor_support_; | 133 return &compositor_support_; |
| 177 } | 134 } |
| 178 | 135 |
| 179 void BlinkPlatformImpl::createMessageChannel( | 136 void BlinkPlatformImpl::createMessageChannel( |
| 180 blink::WebMessagePortChannel** channel1, | 137 blink::WebMessagePortChannel** channel1, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 BlinkPlatformImpl::notificationManager() { | 266 BlinkPlatformImpl::notificationManager() { |
| 310 return &web_notification_manager_; | 267 return &web_notification_manager_; |
| 311 } | 268 } |
| 312 | 269 |
| 313 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread) { | 270 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread) { |
| 314 DCHECK(!current_thread_slot_.Get()); | 271 DCHECK(!current_thread_slot_.Get()); |
| 315 current_thread_slot_.Set(thread); | 272 current_thread_slot_.Set(thread); |
| 316 } | 273 } |
| 317 | 274 |
| 318 } // namespace html_viewer | 275 } // namespace html_viewer |
| OLD | NEW |