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

Side by Side Diff: components/html_viewer/blink_platform_impl.cc

Issue 1112573003: Hook up the scheduler component to html_viewer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 | « components/html_viewer/blink_platform_impl.h ('k') | components/html_viewer/html_viewer.cc » ('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 "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"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "components/html_viewer/blink_resource_constants.h" 15 #include "components/html_viewer/blink_resource_constants.h"
16 #include "components/html_viewer/web_clipboard_impl.h" 16 #include "components/html_viewer/web_clipboard_impl.h"
17 #include "components/html_viewer/web_cookie_jar_impl.h" 17 #include "components/html_viewer/web_cookie_jar_impl.h"
18 #include "components/html_viewer/web_message_port_channel_impl.h" 18 #include "components/html_viewer/web_message_port_channel_impl.h"
19 #include "components/html_viewer/web_socket_handle_impl.h" 19 #include "components/html_viewer/web_socket_handle_impl.h"
20 #include "components/html_viewer/web_thread_impl.h"
21 #include "components/html_viewer/web_url_loader_impl.h" 20 #include "components/html_viewer/web_url_loader_impl.h"
21 #include "components/scheduler/child/webthread_impl_for_worker_scheduler.h"
22 #include "components/scheduler/renderer/renderer_scheduler.h"
23 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h"
22 #include "net/base/data_url.h" 24 #include "net/base/data_url.h"
23 #include "net/base/mime_util.h" 25 #include "net/base/mime_util.h"
24 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
25 #include "net/base/net_util.h" 27 #include "net/base/net_util.h"
26 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" 28 #include "third_party/WebKit/public/platform/WebWaitableEvent.h"
27 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" 29 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h"
28 #include "third_party/mojo/src/mojo/public/cpp/application/connect.h" 30 #include "third_party/mojo/src/mojo/public/cpp/application/connect.h"
29 #include "ui/events/gestures/blink/web_gesture_curve_impl.h" 31 #include "ui/events/gestures/blink/web_gesture_curve_impl.h"
30 32
31 namespace html_viewer { 33 namespace html_viewer {
(...skipping 19 matching lines...) Expand all
51 return impl_.get(); 53 return impl_.get();
52 } 54 }
53 55
54 private: 56 private:
55 scoped_ptr<base::WaitableEvent> impl_; 57 scoped_ptr<base::WaitableEvent> impl_;
56 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); 58 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl);
57 }; 59 };
58 60
59 } // namespace 61 } // namespace
60 62
61 BlinkPlatformImpl::BlinkPlatformImpl(mojo::ApplicationImpl* app) 63 BlinkPlatformImpl::BlinkPlatformImpl(
62 : main_loop_(base::MessageLoop::current()), 64 mojo::ApplicationImpl* app,
65 scheduler::RendererScheduler* renderer_scheduler)
66 : main_thread_task_runner_(renderer_scheduler->DefaultTaskRunner()),
67 main_thread_(
68 new scheduler::WebThreadImplForRendererScheduler(renderer_scheduler)),
63 shared_timer_func_(NULL), 69 shared_timer_func_(NULL),
64 shared_timer_fire_time_(0.0), 70 shared_timer_fire_time_(0.0),
65 shared_timer_fire_time_was_set_while_suspended_(false), 71 shared_timer_fire_time_was_set_while_suspended_(false),
66 shared_timer_suspended_(0), 72 shared_timer_suspended_(0) {
67 current_thread_slot_(&DestroyCurrentThread),
68 scheduler_(main_loop_->message_loop_proxy()) {
69 if (app) { 73 if (app) {
70 app->ConnectToService("mojo:network_service", &network_service_); 74 app->ConnectToService("mojo:network_service", &network_service_);
71 75
72 mojo::CookieStorePtr cookie_store; 76 mojo::CookieStorePtr cookie_store;
73 network_service_->GetCookieStore(GetProxy(&cookie_store)); 77 network_service_->GetCookieStore(GetProxy(&cookie_store));
74 cookie_jar_.reset(new WebCookieJarImpl(cookie_store.Pass())); 78 cookie_jar_.reset(new WebCookieJarImpl(cookie_store.Pass()));
75 79
76 mojo::ServiceProviderPtr service_provider; 80 mojo::ServiceProviderPtr service_provider;
77 app->ConnectToService("mojo:core_services", &service_provider); 81 app->ConnectToService("mojo:core_services", &service_provider);
78 mojo::ClipboardPtr clipboard; 82 mojo::ClipboardPtr clipboard;
79 mojo::ConnectToService(service_provider.get(), &clipboard); 83 mojo::ConnectToService(service_provider.get(), &clipboard);
80 clipboard_.reset(new WebClipboardImpl(clipboard.Pass())); 84 clipboard_.reset(new WebClipboardImpl(clipboard.Pass()));
81 } 85 }
86 if (main_thread_task_runner_.get())
Sami 2015/04/28 15:20:21 This should never be null.
87 shared_timer_.SetTaskRunner(main_thread_task_runner_);
82 } 88 }
83 89
84 BlinkPlatformImpl::~BlinkPlatformImpl() { 90 BlinkPlatformImpl::~BlinkPlatformImpl() {
85 } 91 }
86 92
87 blink::WebCookieJar* BlinkPlatformImpl::cookieJar() { 93 blink::WebCookieJar* BlinkPlatformImpl::cookieJar() {
88 return cookie_jar_.get(); 94 return cookie_jar_.get();
89 } 95 }
90 96
91 blink::WebClipboard* BlinkPlatformImpl::clipboard() { 97 blink::WebClipboard* BlinkPlatformImpl::clipboard() {
92 return clipboard_.get(); 98 return clipboard_.get();
93 } 99 }
94 100
95 blink::WebMimeRegistry* BlinkPlatformImpl::mimeRegistry() { 101 blink::WebMimeRegistry* BlinkPlatformImpl::mimeRegistry() {
96 return &mime_registry_; 102 return &mime_registry_;
97 } 103 }
98 104
99 blink::WebThemeEngine* BlinkPlatformImpl::themeEngine() { 105 blink::WebThemeEngine* BlinkPlatformImpl::themeEngine() {
100 return &theme_engine_; 106 return &theme_engine_;
101 } 107 }
102 108
103 blink::WebScheduler* BlinkPlatformImpl::scheduler() {
104 return &scheduler_;
105 }
106
107 blink::WebString BlinkPlatformImpl::defaultLocale() { 109 blink::WebString BlinkPlatformImpl::defaultLocale() {
108 return blink::WebString::fromUTF8("en-US"); 110 return blink::WebString::fromUTF8("en-US");
109 } 111 }
110 112
111 blink::WebBlobRegistry* BlinkPlatformImpl::blobRegistry() { 113 blink::WebBlobRegistry* BlinkPlatformImpl::blobRegistry() {
112 return &blob_registry_; 114 return &blob_registry_;
113 } 115 }
114 116
115 double BlinkPlatformImpl::currentTime() { 117 double BlinkPlatformImpl::currentTime() {
116 return base::Time::Now().ToDoubleT(); 118 return base::Time::Now().ToDoubleT();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 shared_timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds(interval), 161 shared_timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds(interval),
160 this, &BlinkPlatformImpl::DoTimeout); 162 this, &BlinkPlatformImpl::DoTimeout);
161 } 163 }
162 164
163 void BlinkPlatformImpl::stopSharedTimer() { 165 void BlinkPlatformImpl::stopSharedTimer() {
164 shared_timer_.Stop(); 166 shared_timer_.Stop();
165 } 167 }
166 168
167 void BlinkPlatformImpl::callOnMainThread( 169 void BlinkPlatformImpl::callOnMainThread(
168 void (*func)(void*), void* context) { 170 void (*func)(void*), void* context) {
169 main_loop_->PostTask(FROM_HERE, base::Bind(func, context)); 171 main_thread_task_runner_->PostTask(FROM_HERE, base::Bind(func, context));
170 } 172 }
171 173
172 bool BlinkPlatformImpl::isThreadedCompositingEnabled() { 174 bool BlinkPlatformImpl::isThreadedCompositingEnabled() {
173 return true; 175 return true;
174 } 176 }
175 177
176 blink::WebCompositorSupport* BlinkPlatformImpl::compositorSupport() { 178 blink::WebCompositorSupport* BlinkPlatformImpl::compositorSupport() {
177 return &compositor_support_; 179 return &compositor_support_;
178 } 180 }
179 181
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 253
252 bool BlinkPlatformImpl::isReservedIPAddress( 254 bool BlinkPlatformImpl::isReservedIPAddress(
253 const blink::WebString& host) const { 255 const blink::WebString& host) const {
254 net::IPAddressNumber address; 256 net::IPAddressNumber address;
255 if (!net::ParseURLHostnameToNumber(host.utf8(), &address)) 257 if (!net::ParseURLHostnameToNumber(host.utf8(), &address))
256 return false; 258 return false;
257 return net::IsIPAddressReserved(address); 259 return net::IsIPAddressReserved(address);
258 } 260 }
259 261
260 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) { 262 blink::WebThread* BlinkPlatformImpl::createThread(const char* name) {
261 return new WebThreadImpl(name); 263 scheduler::WebThreadImplForWorkerScheduler* thread =
264 new scheduler::WebThreadImplForWorkerScheduler(name);
265 thread->TaskRunner()->PostTask(
266 FROM_HERE, base::Bind(&BlinkPlatformImpl::UpdateWebThreadTLS,
267 base::Unretained(this), thread));
268 return thread;
262 } 269 }
263 270
264 blink::WebThread* BlinkPlatformImpl::currentThread() { 271 blink::WebThread* BlinkPlatformImpl::currentThread() {
265 WebThreadImplForMessageLoop* thread = 272 if (main_thread_->isCurrentThread())
266 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get()); 273 return main_thread_.get();
267 if (thread) 274 return static_cast<blink::WebThread*>(current_thread_slot_.Get());
268 return (thread);
269
270 scoped_refptr<base::MessageLoopProxy> message_loop =
271 base::MessageLoopProxy::current();
272 if (!message_loop.get())
273 return NULL;
274
275 thread = new WebThreadImplForMessageLoop(message_loop.get());
276 current_thread_slot_.Set(thread);
277 return thread;
278 } 275 }
279 276
280 void BlinkPlatformImpl::yieldCurrentThread() { 277 void BlinkPlatformImpl::yieldCurrentThread() {
281 base::PlatformThread::YieldCurrentThread(); 278 base::PlatformThread::YieldCurrentThread();
282 } 279 }
283 280
284 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent() { 281 blink::WebWaitableEvent* BlinkPlatformImpl::createWaitableEvent() {
285 return new WebWaitableEventImpl(); 282 return new WebWaitableEventImpl();
286 } 283 }
287 284
(...skipping 21 matching lines...) Expand all
309 306
310 blink::WebCrypto* BlinkPlatformImpl::crypto() { 307 blink::WebCrypto* BlinkPlatformImpl::crypto() {
311 return &web_crypto_; 308 return &web_crypto_;
312 } 309 }
313 310
314 blink::WebNotificationManager* 311 blink::WebNotificationManager*
315 BlinkPlatformImpl::notificationManager() { 312 BlinkPlatformImpl::notificationManager() {
316 return &web_notification_manager_; 313 return &web_notification_manager_;
317 } 314 }
318 315
319 // static 316 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread* thread) {
320 void BlinkPlatformImpl::DestroyCurrentThread(void* thread) { 317 DCHECK(!current_thread_slot_.Get());
321 WebThreadImplForMessageLoop* impl = 318 current_thread_slot_.Set(thread);
322 static_cast<WebThreadImplForMessageLoop*>(thread);
323 delete impl;
324 } 319 }
325 320
326 } // namespace html_viewer 321 } // namespace html_viewer
OLDNEW
« no previous file with comments | « components/html_viewer/blink_platform_impl.h ('k') | components/html_viewer/html_viewer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698