| 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 "sky/viewer/platform/platform_impl.h" | 5 #include "sky/viewer/platform/platform_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.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/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "mojo/public/cpp/application/application_impl.h" | 14 #include "mojo/public/cpp/application/application_impl.h" |
| 15 #include "net/base/data_url.h" | 15 #include "net/base/data_url.h" |
| 16 #include "net/base/mime_util.h" | 16 #include "net/base/mime_util.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "sky/engine/public/platform/WebConvertableToTraceFormat.h" | 18 #include "sky/engine/public/platform/WebConvertableToTraceFormat.h" |
| 19 #include "sky/engine/public/platform/WebWaitableEvent.h" | |
| 20 #include "sky/viewer/platform/weburlloader_impl.h" | 19 #include "sky/viewer/platform/weburlloader_impl.h" |
| 21 | 20 |
| 22 namespace sky { | 21 namespace sky { |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 class WebWaitableEventImpl : public blink::WebWaitableEvent { | |
| 26 public: | |
| 27 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {} | |
| 28 virtual ~WebWaitableEventImpl() {} | |
| 29 | |
| 30 virtual void wait() { impl_->Wait(); } | |
| 31 virtual void signal() { impl_->Signal(); } | |
| 32 | |
| 33 base::WaitableEvent* impl() { | |
| 34 return impl_.get(); | |
| 35 } | |
| 36 | |
| 37 private: | |
| 38 scoped_ptr<base::WaitableEvent> impl_; | |
| 39 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); | |
| 40 }; | |
| 41 | |
| 42 class ConvertableToTraceFormatWrapper | 24 class ConvertableToTraceFormatWrapper |
| 43 : public base::debug::ConvertableToTraceFormat { | 25 : public base::debug::ConvertableToTraceFormat { |
| 44 public: | 26 public: |
| 45 explicit ConvertableToTraceFormatWrapper( | 27 explicit ConvertableToTraceFormatWrapper( |
| 46 const blink::WebConvertableToTraceFormat& convertable) | 28 const blink::WebConvertableToTraceFormat& convertable) |
| 47 : convertable_(convertable) {} | 29 : convertable_(convertable) {} |
| 48 virtual void AppendAsTraceFormat(std::string* out) const override { | 30 virtual void AppendAsTraceFormat(std::string* out) const override { |
| 49 *out += convertable_.asTraceFormat().utf8(); | 31 *out += convertable_.asTraceFormat().utf8(); |
| 50 } | 32 } |
| 51 | 33 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 const { | 161 const { |
| 180 blink::WebURLError error; | 162 blink::WebURLError error; |
| 181 error.domain = blink::WebString::fromUTF8(net::kErrorDomain); | 163 error.domain = blink::WebString::fromUTF8(net::kErrorDomain); |
| 182 error.reason = net::ERR_ABORTED; | 164 error.reason = net::ERR_ABORTED; |
| 183 error.unreachableURL = url; | 165 error.unreachableURL = url; |
| 184 error.staleCopyInCache = false; | 166 error.staleCopyInCache = false; |
| 185 error.isCancellation = true; | 167 error.isCancellation = true; |
| 186 return error; | 168 return error; |
| 187 } | 169 } |
| 188 | 170 |
| 189 blink::WebWaitableEvent* PlatformImpl::createWaitableEvent() { | |
| 190 return new WebWaitableEventImpl(); | |
| 191 } | |
| 192 | |
| 193 blink::WebWaitableEvent* PlatformImpl::waitMultipleEvents( | |
| 194 const blink::WebVector<blink::WebWaitableEvent*>& web_events) { | |
| 195 std::vector<base::WaitableEvent*> events; | |
| 196 for (size_t i = 0; i < web_events.size(); ++i) | |
| 197 events.push_back(static_cast<WebWaitableEventImpl*>(web_events[i])->impl()); | |
| 198 size_t idx = base::WaitableEvent::WaitMany( | |
| 199 vector_as_array(&events), events.size()); | |
| 200 DCHECK_LT(idx, web_events.size()); | |
| 201 return web_events[idx]; | |
| 202 } | |
| 203 | |
| 204 const unsigned char* PlatformImpl::getTraceCategoryEnabledFlag( | 171 const unsigned char* PlatformImpl::getTraceCategoryEnabledFlag( |
| 205 const char* category_group) { | 172 const char* category_group) { |
| 206 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); | 173 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); |
| 207 } | 174 } |
| 208 | 175 |
| 209 long* PlatformImpl::getTraceSamplingState(const unsigned thread_bucket) { | 176 long* PlatformImpl::getTraceSamplingState(const unsigned thread_bucket) { |
| 210 switch (thread_bucket) { | 177 switch (thread_bucket) { |
| 211 case 0: | 178 case 0: |
| 212 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(0)); | 179 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(0)); |
| 213 case 1: | 180 case 1: |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 const unsigned char* category_group_enabled, | 252 const unsigned char* category_group_enabled, |
| 286 const char* name, | 253 const char* name, |
| 287 TraceEventHandle handle) { | 254 TraceEventHandle handle) { |
| 288 base::debug::TraceEventHandle traceEventHandle; | 255 base::debug::TraceEventHandle traceEventHandle; |
| 289 memcpy(&traceEventHandle, &handle, sizeof(handle)); | 256 memcpy(&traceEventHandle, &handle, sizeof(handle)); |
| 290 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( | 257 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( |
| 291 category_group_enabled, name, traceEventHandle); | 258 category_group_enabled, name, traceEventHandle); |
| 292 } | 259 } |
| 293 | 260 |
| 294 } // namespace sky | 261 } // namespace sky |
| OLD | NEW |