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

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

Issue 673033002: Remove WebThread (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 2 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
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 #include "sky/engine/public/platform/WebWaitableEvent.h" 16 #include "sky/engine/public/platform/WebWaitableEvent.h"
17 #include "sky/engine/testing/platform/webthread_impl.h"
18 17
19 namespace sky { 18 namespace sky {
20 namespace { 19 namespace {
21 20
22 class WebWaitableEventImpl : public blink::WebWaitableEvent { 21 class WebWaitableEventImpl : public blink::WebWaitableEvent {
23 public: 22 public:
24 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {} 23 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {}
25 virtual ~WebWaitableEventImpl() {} 24 virtual ~WebWaitableEventImpl() {}
26 25
27 virtual void wait() { impl_->Wait(); } 26 virtual void wait() { impl_->Wait(); }
28 virtual void signal() { impl_->Signal(); } 27 virtual void signal() { impl_->Signal(); }
29 28
30 base::WaitableEvent* impl() { 29 base::WaitableEvent* impl() {
31 return impl_.get(); 30 return impl_.get();
32 } 31 }
33 32
34 private: 33 private:
35 scoped_ptr<base::WaitableEvent> impl_; 34 scoped_ptr<base::WaitableEvent> impl_;
36 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); 35 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl);
37 }; 36 };
38 37
39 } // namespace 38 } // namespace
40 39
41 PlatformImpl::PlatformImpl() 40 PlatformImpl::PlatformImpl()
42 : main_loop_(base::MessageLoop::current()), 41 : main_loop_(base::MessageLoop::current()),
43 shared_timer_func_(NULL), 42 shared_timer_func_(NULL),
44 shared_timer_fire_time_(0.0), 43 shared_timer_fire_time_(0.0),
45 shared_timer_fire_time_was_set_while_suspended_(false), 44 shared_timer_fire_time_was_set_while_suspended_(false),
46 shared_timer_suspended_(0), 45 shared_timer_suspended_(0) {
47 current_thread_slot_(&DestroyCurrentThread) {
48 } 46 }
49 47
50 PlatformImpl::~PlatformImpl() { 48 PlatformImpl::~PlatformImpl() {
51 } 49 }
52 50
53 blink::WebMimeRegistry* PlatformImpl::mimeRegistry() { 51 blink::WebMimeRegistry* PlatformImpl::mimeRegistry() {
54 return &mime_registry_; 52 return &mime_registry_;
55 } 53 }
56 54
57 blink::WebThemeEngine* PlatformImpl::themeEngine() { 55 blink::WebThemeEngine* PlatformImpl::themeEngine() {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 std::string mimetype, charset, data; 138 std::string mimetype, charset, data;
141 if (net::DataURL::Parse(url, &mimetype, &charset, &data) 139 if (net::DataURL::Parse(url, &mimetype, &charset, &data)
142 && net::IsSupportedMimeType(mimetype)) { 140 && net::IsSupportedMimeType(mimetype)) {
143 mimetype_out = blink::WebString::fromUTF8(mimetype); 141 mimetype_out = blink::WebString::fromUTF8(mimetype);
144 charset_out = blink::WebString::fromUTF8(charset); 142 charset_out = blink::WebString::fromUTF8(charset);
145 return data; 143 return data;
146 } 144 }
147 return blink::WebData(); 145 return blink::WebData();
148 } 146 }
149 147
150 blink::WebThread* PlatformImpl::currentThread() {
151 WebThreadImplForMessageLoop* thread =
152 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get());
153 if (thread)
154 return (thread);
155
156 scoped_refptr<base::MessageLoopProxy> message_loop =
157 base::MessageLoopProxy::current();
158 if (!message_loop.get())
159 return NULL;
160
161 thread = new WebThreadImplForMessageLoop(message_loop.get());
162 current_thread_slot_.Set(thread);
163 return thread;
164 }
165
166 blink::WebWaitableEvent* PlatformImpl::createWaitableEvent() { 148 blink::WebWaitableEvent* PlatformImpl::createWaitableEvent() {
167 return new WebWaitableEventImpl(); 149 return new WebWaitableEventImpl();
168 } 150 }
169 151
170 blink::WebWaitableEvent* PlatformImpl::waitMultipleEvents( 152 blink::WebWaitableEvent* PlatformImpl::waitMultipleEvents(
171 const blink::WebVector<blink::WebWaitableEvent*>& web_events) { 153 const blink::WebVector<blink::WebWaitableEvent*>& web_events) {
172 std::vector<base::WaitableEvent*> events; 154 std::vector<base::WaitableEvent*> events;
173 for (size_t i = 0; i < web_events.size(); ++i) 155 for (size_t i = 0; i < web_events.size(); ++i)
174 events.push_back(static_cast<WebWaitableEventImpl*>(web_events[i])->impl()); 156 events.push_back(static_cast<WebWaitableEventImpl*>(web_events[i])->impl());
175 size_t idx = base::WaitableEvent::WaitMany( 157 size_t idx = base::WaitableEvent::WaitMany(
176 vector_as_array(&events), events.size()); 158 vector_as_array(&events), events.size());
177 DCHECK_LT(idx, web_events.size()); 159 DCHECK_LT(idx, web_events.size());
178 return web_events[idx]; 160 return web_events[idx];
179 } 161 }
180 162
181 // static
182 void PlatformImpl::DestroyCurrentThread(void* thread) {
183 WebThreadImplForMessageLoop* impl =
184 static_cast<WebThreadImplForMessageLoop*>(thread);
185 delete impl;
186 }
187
188 } // namespace sky 163 } // namespace sky
OLDNEW
« no previous file with comments | « sky/engine/testing/platform/platform_impl.h ('k') | sky/engine/testing/platform/webthread_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698