| 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" | |
| 19 #include "sky/viewer/platform/weburlloader_impl.h" | 18 #include "sky/viewer/platform/weburlloader_impl.h" |
| 20 | 19 |
| 21 namespace sky { | 20 namespace sky { |
| 22 namespace { | |
| 23 | |
| 24 class ConvertableToTraceFormatWrapper | |
| 25 : public base::debug::ConvertableToTraceFormat { | |
| 26 public: | |
| 27 explicit ConvertableToTraceFormatWrapper( | |
| 28 const blink::WebConvertableToTraceFormat& convertable) | |
| 29 : convertable_(convertable) {} | |
| 30 virtual void AppendAsTraceFormat(std::string* out) const override { | |
| 31 *out += convertable_.asTraceFormat().utf8(); | |
| 32 } | |
| 33 | |
| 34 private: | |
| 35 virtual ~ConvertableToTraceFormatWrapper() {} | |
| 36 | |
| 37 blink::WebConvertableToTraceFormat convertable_; | |
| 38 }; | |
| 39 | |
| 40 } // namespace | |
| 41 | 21 |
| 42 PlatformImpl::PlatformImpl(mojo::ApplicationImpl* app) | 22 PlatformImpl::PlatformImpl(mojo::ApplicationImpl* app) |
| 43 : main_loop_(base::MessageLoop::current()), | 23 : main_loop_(base::MessageLoop::current()), |
| 44 main_thread_task_runner_(base::MessageLoop::current()->task_runner()), | 24 main_thread_task_runner_(base::MessageLoop::current()->task_runner()), |
| 45 shared_timer_func_(NULL), | 25 shared_timer_func_(NULL), |
| 46 shared_timer_fire_time_(0.0), | 26 shared_timer_fire_time_(0.0), |
| 47 shared_timer_fire_time_was_set_while_suspended_(false), | 27 shared_timer_fire_time_was_set_while_suspended_(false), |
| 48 shared_timer_suspended_(0) { | 28 shared_timer_suspended_(0) { |
| 49 app->ConnectToService("mojo:network_service", &network_service_); | 29 app->ConnectToService("mojo:network_service", &network_service_); |
| 50 | 30 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 const { | 96 const { |
| 117 blink::WebURLError error; | 97 blink::WebURLError error; |
| 118 error.domain = blink::WebString::fromUTF8(net::kErrorDomain); | 98 error.domain = blink::WebString::fromUTF8(net::kErrorDomain); |
| 119 error.reason = net::ERR_ABORTED; | 99 error.reason = net::ERR_ABORTED; |
| 120 error.unreachableURL = url; | 100 error.unreachableURL = url; |
| 121 error.staleCopyInCache = false; | 101 error.staleCopyInCache = false; |
| 122 error.isCancellation = true; | 102 error.isCancellation = true; |
| 123 return error; | 103 return error; |
| 124 } | 104 } |
| 125 | 105 |
| 126 const unsigned char* PlatformImpl::getTraceCategoryEnabledFlag( | |
| 127 const char* category_group) { | |
| 128 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); | |
| 129 } | |
| 130 | |
| 131 COMPILE_ASSERT( | |
| 132 sizeof(blink::Platform::TraceEventHandle) == | |
| 133 sizeof(base::debug::TraceEventHandle), | |
| 134 TraceEventHandle_types_must_be_same_size); | |
| 135 | |
| 136 blink::Platform::TraceEventHandle PlatformImpl::addTraceEvent( | |
| 137 char phase, | |
| 138 const unsigned char* category_group_enabled, | |
| 139 const char* name, | |
| 140 unsigned long long id, | |
| 141 int num_args, | |
| 142 const char** arg_names, | |
| 143 const unsigned char* arg_types, | |
| 144 const unsigned long long* arg_values, | |
| 145 unsigned char flags) { | |
| 146 base::debug::TraceEventHandle handle = TRACE_EVENT_API_ADD_TRACE_EVENT( | |
| 147 phase, category_group_enabled, name, id, | |
| 148 num_args, arg_names, arg_types, arg_values, NULL, flags); | |
| 149 blink::Platform::TraceEventHandle result; | |
| 150 memcpy(&result, &handle, sizeof(result)); | |
| 151 return result; | |
| 152 } | |
| 153 | |
| 154 blink::Platform::TraceEventHandle PlatformImpl::addTraceEvent( | |
| 155 char phase, | |
| 156 const unsigned char* category_group_enabled, | |
| 157 const char* name, | |
| 158 unsigned long long id, | |
| 159 int num_args, | |
| 160 const char** arg_names, | |
| 161 const unsigned char* arg_types, | |
| 162 const unsigned long long* arg_values, | |
| 163 const blink::WebConvertableToTraceFormat* convertable_values, | |
| 164 unsigned char flags) { | |
| 165 scoped_refptr<base::debug::ConvertableToTraceFormat> convertable_wrappers[2]; | |
| 166 if (convertable_values) { | |
| 167 size_t size = std::min(static_cast<size_t>(num_args), | |
| 168 arraysize(convertable_wrappers)); | |
| 169 for (size_t i = 0; i < size; ++i) { | |
| 170 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE) { | |
| 171 convertable_wrappers[i] = | |
| 172 new ConvertableToTraceFormatWrapper(convertable_values[i]); | |
| 173 } | |
| 174 } | |
| 175 } | |
| 176 base::debug::TraceEventHandle handle = | |
| 177 TRACE_EVENT_API_ADD_TRACE_EVENT(phase, | |
| 178 category_group_enabled, | |
| 179 name, | |
| 180 id, | |
| 181 num_args, | |
| 182 arg_names, | |
| 183 arg_types, | |
| 184 arg_values, | |
| 185 convertable_wrappers, | |
| 186 flags); | |
| 187 blink::Platform::TraceEventHandle result; | |
| 188 memcpy(&result, &handle, sizeof(result)); | |
| 189 return result; | |
| 190 } | |
| 191 | |
| 192 void PlatformImpl::updateTraceEventDuration( | |
| 193 const unsigned char* category_group_enabled, | |
| 194 const char* name, | |
| 195 TraceEventHandle handle) { | |
| 196 base::debug::TraceEventHandle traceEventHandle; | |
| 197 memcpy(&traceEventHandle, &handle, sizeof(handle)); | |
| 198 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( | |
| 199 category_group_enabled, name, traceEventHandle); | |
| 200 } | |
| 201 | |
| 202 } // namespace sky | 106 } // namespace sky |
| OLD | NEW |