OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "webkit/child/webkitplatformsupport_child_impl.h" | 5 #include "webkit/child/webkitplatformsupport_child_impl.h" |
6 | 6 |
7 #include "base/memory/discardable_memory.h" | 7 #include "base/memory/discardable_memory.h" |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" |
8 #include "third_party/WebKit/public/web/WebInputEvent.h" | 11 #include "third_party/WebKit/public/web/WebInputEvent.h" |
9 #include "webkit/child/fling_curve_configuration.h" | 12 #include "webkit/child/fling_curve_configuration.h" |
10 #include "webkit/child/web_discardable_memory_impl.h" | 13 #include "webkit/child/web_discardable_memory_impl.h" |
11 #include "webkit/child/webthread_impl.h" | 14 #include "webkit/child/webthread_impl.h" |
12 #include "webkit/child/worker_task_runner.h" | 15 #include "webkit/child/worker_task_runner.h" |
13 | 16 |
14 #if defined(OS_ANDROID) | 17 #if defined(OS_ANDROID) |
15 #include "webkit/child/fling_animator_impl_android.h" | 18 #include "webkit/child/fling_animator_impl_android.h" |
16 #endif | 19 #endif |
17 | 20 |
18 using blink::WebFallbackThemeEngine; | 21 using blink::WebFallbackThemeEngine; |
19 using blink::WebThemeEngine; | 22 using blink::WebThemeEngine; |
20 | 23 |
21 namespace webkit_glue { | 24 namespace webkit_glue { |
22 | 25 |
| 26 namespace { |
| 27 |
| 28 class WebWaitableEventImpl : public blink::WebWaitableEvent { |
| 29 public: |
| 30 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {} |
| 31 virtual ~WebWaitableEventImpl() {} |
| 32 |
| 33 virtual void wait() { impl_->Wait(); } |
| 34 virtual void signal() { impl_->Signal(); } |
| 35 |
| 36 base::WaitableEvent* impl() { |
| 37 return impl_.get(); |
| 38 } |
| 39 |
| 40 private: |
| 41 scoped_ptr<base::WaitableEvent> impl_; |
| 42 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); |
| 43 }; |
| 44 |
| 45 } // namespace |
| 46 |
23 WebKitPlatformSupportChildImpl::WebKitPlatformSupportChildImpl() | 47 WebKitPlatformSupportChildImpl::WebKitPlatformSupportChildImpl() |
24 : current_thread_slot_(&DestroyCurrentThread), | 48 : current_thread_slot_(&DestroyCurrentThread), |
25 fling_curve_configuration_(new FlingCurveConfiguration) {} | 49 fling_curve_configuration_(new FlingCurveConfiguration) {} |
26 | 50 |
27 WebKitPlatformSupportChildImpl::~WebKitPlatformSupportChildImpl() {} | 51 WebKitPlatformSupportChildImpl::~WebKitPlatformSupportChildImpl() {} |
28 | 52 |
29 WebThemeEngine* WebKitPlatformSupportChildImpl::themeEngine() { | 53 WebThemeEngine* WebKitPlatformSupportChildImpl::themeEngine() { |
30 return &native_theme_engine_; | 54 return &native_theme_engine_; |
31 } | 55 } |
32 | 56 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 scoped_refptr<base::MessageLoopProxy> message_loop = | 96 scoped_refptr<base::MessageLoopProxy> message_loop = |
73 base::MessageLoopProxy::current(); | 97 base::MessageLoopProxy::current(); |
74 if (!message_loop.get()) | 98 if (!message_loop.get()) |
75 return NULL; | 99 return NULL; |
76 | 100 |
77 thread = new WebThreadImplForMessageLoop(message_loop.get()); | 101 thread = new WebThreadImplForMessageLoop(message_loop.get()); |
78 current_thread_slot_.Set(thread); | 102 current_thread_slot_.Set(thread); |
79 return thread; | 103 return thread; |
80 } | 104 } |
81 | 105 |
| 106 blink::WebWaitableEvent* WebKitPlatformSupportChildImpl::createWaitableEvent() { |
| 107 return new WebWaitableEventImpl(); |
| 108 } |
| 109 |
| 110 blink::WebWaitableEvent* WebKitPlatformSupportChildImpl::waitMultipleEvents( |
| 111 const blink::WebVector<blink::WebWaitableEvent*>& web_events) { |
| 112 base::WaitableEvent** events = new base::WaitableEvent*[web_events.size()]; |
| 113 for (size_t i = 0; i < web_events.size(); ++i) |
| 114 events[i] = static_cast<WebWaitableEventImpl*>(web_events[i])->impl(); |
| 115 size_t idx = base::WaitableEvent::WaitMany(events, web_events.size()); |
| 116 DCHECK_LT(idx, web_events.size()); |
| 117 return web_events[idx]; |
| 118 } |
| 119 |
82 void WebKitPlatformSupportChildImpl::didStartWorkerRunLoop( | 120 void WebKitPlatformSupportChildImpl::didStartWorkerRunLoop( |
83 const blink::WebWorkerRunLoop& runLoop) { | 121 const blink::WebWorkerRunLoop& runLoop) { |
84 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); | 122 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); |
85 worker_task_runner->OnWorkerRunLoopStarted(runLoop); | 123 worker_task_runner->OnWorkerRunLoopStarted(runLoop); |
86 } | 124 } |
87 | 125 |
88 void WebKitPlatformSupportChildImpl::didStopWorkerRunLoop( | 126 void WebKitPlatformSupportChildImpl::didStopWorkerRunLoop( |
89 const blink::WebWorkerRunLoop& runLoop) { | 127 const blink::WebWorkerRunLoop& runLoop) { |
90 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); | 128 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); |
91 worker_task_runner->OnWorkerRunLoopStopped(runLoop); | 129 worker_task_runner->OnWorkerRunLoopStopped(runLoop); |
92 } | 130 } |
93 | 131 |
94 blink::WebDiscardableMemory* | 132 blink::WebDiscardableMemory* |
95 WebKitPlatformSupportChildImpl::allocateAndLockDiscardableMemory(size_t bytes) { | 133 WebKitPlatformSupportChildImpl::allocateAndLockDiscardableMemory(size_t bytes) { |
96 base::DiscardableMemoryType type = | 134 base::DiscardableMemoryType type = |
97 base::DiscardableMemory::GetPreferredType(); | 135 base::DiscardableMemory::GetPreferredType(); |
98 if (type == base::DISCARDABLE_MEMORY_TYPE_EMULATED) | 136 if (type == base::DISCARDABLE_MEMORY_TYPE_EMULATED) |
99 return NULL; | 137 return NULL; |
100 return WebDiscardableMemoryImpl::CreateLockedMemory(bytes).release(); | 138 return WebDiscardableMemoryImpl::CreateLockedMemory(bytes).release(); |
101 } | 139 } |
102 | 140 |
103 // static | 141 // static |
104 void WebKitPlatformSupportChildImpl::DestroyCurrentThread(void* thread) { | 142 void WebKitPlatformSupportChildImpl::DestroyCurrentThread(void* thread) { |
105 WebThreadImplForMessageLoop* impl = | 143 WebThreadImplForMessageLoop* impl = |
106 static_cast<WebThreadImplForMessageLoop*>(thread); | 144 static_cast<WebThreadImplForMessageLoop*>(thread); |
107 delete impl; | 145 delete impl; |
108 } | 146 } |
109 | 147 |
110 } // namespace webkit_glue | 148 } // namespace webkit_glue |
OLD | NEW |