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
3 // found in the LICENSE file.
5 #include "content/child/blink_platform_impl.h"
11 #include "base/allocator/allocator_extension.h"
12 #include "base/bind.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/singleton.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/metrics/histogram.h"
18 #include "base/metrics/sparse_histogram.h"
19 #include "base/metrics/stats_counters.h"
20 #include "base/platform_file.h"
21 #include "base/process/process_metrics.h"
22 #include "base/rand_util.h"
23 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_util.h"
25 #include "base/strings/utf_string_conversions.h"
26 #include "base/synchronization/lock.h"
27 #include "base/synchronization/waitable_event.h"
28 #include "base/sys_info.h"
29 #include "base/time/time.h"
30 #include "content/child/content_child_helpers.h"
31 #include "content/child/fling_curve_configuration.h"
32 #include "content/child/web_discardable_memory_impl.h"
33 #include "content/child/web_socket_stream_handle_impl.h"
34 #include "content/child/web_url_loader_impl.h"
35 #include "content/child/websocket_bridge.h"
36 #include "content/child/webthread_impl.h"
37 #include "content/child/worker_task_runner.h"
38 #include "content/public/common/content_client.h"
39 #include "grit/blink_resources.h"
40 #include "grit/webkit_resources.h"
41 #include "grit/webkit_strings.h"
42 #include "net/base/data_url.h"
43 #include "net/base/mime_util.h"
44 #include "net/base/net_errors.h"
45 #include "third_party/WebKit/public/platform/WebConvertableToTraceFormat.h"
46 #include "third_party/WebKit/public/platform/WebData.h"
47 #include "third_party/WebKit/public/platform/WebString.h"
48 #include "third_party/WebKit/public/platform/WebWaitableEvent.h"
49 #include "third_party/WebKit/public/web/WebInputEvent.h"
50 #include "ui/base/layout.h"
52 #if defined(OS_ANDROID)
53 #include "base/android/sys_utils.h"
54 #include "content/child/fling_animator_impl_android.h"
57 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN)
58 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
62 using blink::WebFallbackThemeEngine
;
63 using blink::WebLocalizedString
;
64 using blink::WebString
;
65 using blink::WebSocketStreamHandle
;
66 using blink::WebThemeEngine
;
68 using blink::WebURLError
;
69 using blink::WebURLLoader
;
75 class WebWaitableEventImpl
: public blink::WebWaitableEvent
{
77 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {}
78 virtual ~WebWaitableEventImpl() {}
80 virtual void wait() { impl_
->Wait(); }
81 virtual void signal() { impl_
->Signal(); }
83 base::WaitableEvent
* impl() {
88 scoped_ptr
<base::WaitableEvent
> impl_
;
89 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl
);
92 // A simple class to cache the memory usage for a given amount of time.
93 class MemoryUsageCache
{
95 // Retrieves the Singleton.
96 static MemoryUsageCache
* GetInstance() {
97 return Singleton
<MemoryUsageCache
>::get();
100 MemoryUsageCache() : memory_value_(0) { Init(); }
101 ~MemoryUsageCache() {}
104 const unsigned int kCacheSeconds
= 1;
105 cache_valid_time_
= base::TimeDelta::FromSeconds(kCacheSeconds
);
108 // Returns true if the cached value is fresh.
109 // Returns false if the cached value is stale, or if |cached_value| is NULL.
110 bool IsCachedValueValid(size_t* cached_value
) {
111 base::AutoLock
scoped_lock(lock_
);
114 if (base::Time::Now() - last_updated_time_
> cache_valid_time_
)
116 *cached_value
= memory_value_
;
120 // Setter for |memory_value_|, refreshes |last_updated_time_|.
121 void SetMemoryValue(const size_t value
) {
122 base::AutoLock
scoped_lock(lock_
);
123 memory_value_
= value
;
124 last_updated_time_
= base::Time::Now();
128 // The cached memory value.
129 size_t memory_value_
;
131 // How long the cached value should remain valid.
132 base::TimeDelta cache_valid_time_
;
134 // The last time the cached value was updated.
135 base::Time last_updated_time_
;
140 class ConvertableToTraceFormatWrapper
141 : public base::debug::ConvertableToTraceFormat
{
143 explicit ConvertableToTraceFormatWrapper(
144 const blink::WebConvertableToTraceFormat
& convertable
)
145 : convertable_(convertable
) {}
146 virtual void AppendAsTraceFormat(std::string
* out
) const OVERRIDE
{
147 *out
+= convertable_
.asTraceFormat().utf8();
151 virtual ~ConvertableToTraceFormatWrapper() {}
153 blink::WebConvertableToTraceFormat convertable_
;
158 static int ToMessageID(WebLocalizedString::Name name
) {
160 case WebLocalizedString::AXAMPMFieldText
:
161 return IDS_AX_AM_PM_FIELD_TEXT
;
162 case WebLocalizedString::AXButtonActionVerb
:
163 return IDS_AX_BUTTON_ACTION_VERB
;
164 case WebLocalizedString::AXCheckedCheckBoxActionVerb
:
165 return IDS_AX_CHECKED_CHECK_BOX_ACTION_VERB
;
166 case WebLocalizedString::AXDateTimeFieldEmptyValueText
:
167 return IDS_AX_DATE_TIME_FIELD_EMPTY_VALUE_TEXT
;
168 case WebLocalizedString::AXDayOfMonthFieldText
:
169 return IDS_AX_DAY_OF_MONTH_FIELD_TEXT
;
170 case WebLocalizedString::AXHeadingText
:
171 return IDS_AX_ROLE_HEADING
;
172 case WebLocalizedString::AXHourFieldText
:
173 return IDS_AX_HOUR_FIELD_TEXT
;
174 case WebLocalizedString::AXImageMapText
:
175 return IDS_AX_ROLE_IMAGE_MAP
;
176 case WebLocalizedString::AXLinkActionVerb
:
177 return IDS_AX_LINK_ACTION_VERB
;
178 case WebLocalizedString::AXLinkText
:
179 return IDS_AX_ROLE_LINK
;
180 case WebLocalizedString::AXListMarkerText
:
181 return IDS_AX_ROLE_LIST_MARKER
;
182 case WebLocalizedString::AXMediaDefault
:
183 return IDS_AX_MEDIA_DEFAULT
;
184 case WebLocalizedString::AXMediaAudioElement
:
185 return IDS_AX_MEDIA_AUDIO_ELEMENT
;
186 case WebLocalizedString::AXMediaVideoElement
:
187 return IDS_AX_MEDIA_VIDEO_ELEMENT
;
188 case WebLocalizedString::AXMediaMuteButton
:
189 return IDS_AX_MEDIA_MUTE_BUTTON
;
190 case WebLocalizedString::AXMediaUnMuteButton
:
191 return IDS_AX_MEDIA_UNMUTE_BUTTON
;
192 case WebLocalizedString::AXMediaPlayButton
:
193 return IDS_AX_MEDIA_PLAY_BUTTON
;
194 case WebLocalizedString::AXMediaPauseButton
:
195 return IDS_AX_MEDIA_PAUSE_BUTTON
;
196 case WebLocalizedString::AXMediaSlider
:
197 return IDS_AX_MEDIA_SLIDER
;
198 case WebLocalizedString::AXMediaSliderThumb
:
199 return IDS_AX_MEDIA_SLIDER_THUMB
;
200 case WebLocalizedString::AXMediaCurrentTimeDisplay
:
201 return IDS_AX_MEDIA_CURRENT_TIME_DISPLAY
;
202 case WebLocalizedString::AXMediaTimeRemainingDisplay
:
203 return IDS_AX_MEDIA_TIME_REMAINING_DISPLAY
;
204 case WebLocalizedString::AXMediaStatusDisplay
:
205 return IDS_AX_MEDIA_STATUS_DISPLAY
;
206 case WebLocalizedString::AXMediaEnterFullscreenButton
:
207 return IDS_AX_MEDIA_ENTER_FULL_SCREEN_BUTTON
;
208 case WebLocalizedString::AXMediaExitFullscreenButton
:
209 return IDS_AX_MEDIA_EXIT_FULL_SCREEN_BUTTON
;
210 case WebLocalizedString::AXMediaShowClosedCaptionsButton
:
211 return IDS_AX_MEDIA_SHOW_CLOSED_CAPTIONS_BUTTON
;
212 case WebLocalizedString::AXMediaHideClosedCaptionsButton
:
213 return IDS_AX_MEDIA_HIDE_CLOSED_CAPTIONS_BUTTON
;
214 case WebLocalizedString::AXMediaAudioElementHelp
:
215 return IDS_AX_MEDIA_AUDIO_ELEMENT_HELP
;
216 case WebLocalizedString::AXMediaVideoElementHelp
:
217 return IDS_AX_MEDIA_VIDEO_ELEMENT_HELP
;
218 case WebLocalizedString::AXMediaMuteButtonHelp
:
219 return IDS_AX_MEDIA_MUTE_BUTTON_HELP
;
220 case WebLocalizedString::AXMediaUnMuteButtonHelp
:
221 return IDS_AX_MEDIA_UNMUTE_BUTTON_HELP
;
222 case WebLocalizedString::AXMediaPlayButtonHelp
:
223 return IDS_AX_MEDIA_PLAY_BUTTON_HELP
;
224 case WebLocalizedString::AXMediaPauseButtonHelp
:
225 return IDS_AX_MEDIA_PAUSE_BUTTON_HELP
;
226 case WebLocalizedString::AXMediaSliderHelp
:
227 return IDS_AX_MEDIA_SLIDER_HELP
;
228 case WebLocalizedString::AXMediaSliderThumbHelp
:
229 return IDS_AX_MEDIA_SLIDER_THUMB_HELP
;
230 case WebLocalizedString::AXMediaCurrentTimeDisplayHelp
:
231 return IDS_AX_MEDIA_CURRENT_TIME_DISPLAY_HELP
;
232 case WebLocalizedString::AXMediaTimeRemainingDisplayHelp
:
233 return IDS_AX_MEDIA_TIME_REMAINING_DISPLAY_HELP
;
234 case WebLocalizedString::AXMediaStatusDisplayHelp
:
235 return IDS_AX_MEDIA_STATUS_DISPLAY_HELP
;
236 case WebLocalizedString::AXMediaEnterFullscreenButtonHelp
:
237 return IDS_AX_MEDIA_ENTER_FULL_SCREEN_BUTTON_HELP
;
238 case WebLocalizedString::AXMediaExitFullscreenButtonHelp
:
239 return IDS_AX_MEDIA_EXIT_FULL_SCREEN_BUTTON_HELP
;
240 case WebLocalizedString::AXMediaShowClosedCaptionsButtonHelp
:
241 return IDS_AX_MEDIA_SHOW_CLOSED_CAPTIONS_BUTTON_HELP
;
242 case WebLocalizedString::AXMediaHideClosedCaptionsButtonHelp
:
243 return IDS_AX_MEDIA_HIDE_CLOSED_CAPTIONS_BUTTON_HELP
;
244 case WebLocalizedString::AXMillisecondFieldText
:
245 return IDS_AX_MILLISECOND_FIELD_TEXT
;
246 case WebLocalizedString::AXMinuteFieldText
:
247 return IDS_AX_MINUTE_FIELD_TEXT
;
248 case WebLocalizedString::AXMonthFieldText
:
249 return IDS_AX_MONTH_FIELD_TEXT
;
250 case WebLocalizedString::AXRadioButtonActionVerb
:
251 return IDS_AX_RADIO_BUTTON_ACTION_VERB
;
252 case WebLocalizedString::AXSecondFieldText
:
253 return IDS_AX_SECOND_FIELD_TEXT
;
254 case WebLocalizedString::AXTextFieldActionVerb
:
255 return IDS_AX_TEXT_FIELD_ACTION_VERB
;
256 case WebLocalizedString::AXUncheckedCheckBoxActionVerb
:
257 return IDS_AX_UNCHECKED_CHECK_BOX_ACTION_VERB
;
258 case WebLocalizedString::AXWebAreaText
:
259 return IDS_AX_ROLE_WEB_AREA
;
260 case WebLocalizedString::AXWeekOfYearFieldText
:
261 return IDS_AX_WEEK_OF_YEAR_FIELD_TEXT
;
262 case WebLocalizedString::AXYearFieldText
:
263 return IDS_AX_YEAR_FIELD_TEXT
;
264 case WebLocalizedString::CalendarClear
:
265 return IDS_FORM_CALENDAR_CLEAR
;
266 case WebLocalizedString::CalendarToday
:
267 return IDS_FORM_CALENDAR_TODAY
;
268 case WebLocalizedString::DateFormatDayInMonthLabel
:
269 return IDS_FORM_DATE_FORMAT_DAY_IN_MONTH
;
270 case WebLocalizedString::DateFormatMonthLabel
:
271 return IDS_FORM_DATE_FORMAT_MONTH
;
272 case WebLocalizedString::DateFormatYearLabel
:
273 return IDS_FORM_DATE_FORMAT_YEAR
;
274 case WebLocalizedString::DetailsLabel
:
275 return IDS_DETAILS_WITHOUT_SUMMARY_LABEL
;
276 case WebLocalizedString::FileButtonChooseFileLabel
:
277 return IDS_FORM_FILE_BUTTON_LABEL
;
278 case WebLocalizedString::FileButtonChooseMultipleFilesLabel
:
279 return IDS_FORM_MULTIPLE_FILES_BUTTON_LABEL
;
280 case WebLocalizedString::FileButtonNoFileSelectedLabel
:
281 return IDS_FORM_FILE_NO_FILE_LABEL
;
282 case WebLocalizedString::InputElementAltText
:
283 return IDS_FORM_INPUT_ALT
;
284 case WebLocalizedString::KeygenMenuHighGradeKeySize
:
285 return IDS_KEYGEN_HIGH_GRADE_KEY
;
286 case WebLocalizedString::KeygenMenuMediumGradeKeySize
:
287 return IDS_KEYGEN_MED_GRADE_KEY
;
288 case WebLocalizedString::MissingPluginText
:
289 return IDS_PLUGIN_INITIALIZATION_ERROR
;
290 case WebLocalizedString::MultipleFileUploadText
:
291 return IDS_FORM_FILE_MULTIPLE_UPLOAD
;
292 case WebLocalizedString::OtherColorLabel
:
293 return IDS_FORM_OTHER_COLOR_LABEL
;
294 case WebLocalizedString::OtherDateLabel
:
295 return IDS_FORM_OTHER_DATE_LABEL
;
296 case WebLocalizedString::OtherMonthLabel
:
297 return IDS_FORM_OTHER_MONTH_LABEL
;
298 case WebLocalizedString::OtherTimeLabel
:
299 return IDS_FORM_OTHER_TIME_LABEL
;
300 case WebLocalizedString::OtherWeekLabel
:
301 return IDS_FORM_OTHER_WEEK_LABEL
;
302 case WebLocalizedString::PlaceholderForDayOfMonthField
:
303 return IDS_FORM_PLACEHOLDER_FOR_DAY_OF_MONTH_FIELD
;
304 case WebLocalizedString::PlaceholderForMonthField
:
305 return IDS_FORM_PLACEHOLDER_FOR_MONTH_FIELD
;
306 case WebLocalizedString::PlaceholderForYearField
:
307 return IDS_FORM_PLACEHOLDER_FOR_YEAR_FIELD
;
308 case WebLocalizedString::ResetButtonDefaultLabel
:
309 return IDS_FORM_RESET_LABEL
;
310 case WebLocalizedString::SearchableIndexIntroduction
:
311 return IDS_SEARCHABLE_INDEX_INTRO
;
312 case WebLocalizedString::SearchMenuClearRecentSearchesText
:
313 return IDS_RECENT_SEARCHES_CLEAR
;
314 case WebLocalizedString::SearchMenuNoRecentSearchesText
:
315 return IDS_RECENT_SEARCHES_NONE
;
316 case WebLocalizedString::SearchMenuRecentSearchesText
:
317 return IDS_RECENT_SEARCHES
;
318 case WebLocalizedString::SelectMenuListText
:
319 return IDS_FORM_SELECT_MENU_LIST_TEXT
;
320 case WebLocalizedString::SubmitButtonDefaultLabel
:
321 return IDS_FORM_SUBMIT_LABEL
;
322 case WebLocalizedString::ThisMonthButtonLabel
:
323 return IDS_FORM_THIS_MONTH_LABEL
;
324 case WebLocalizedString::ThisWeekButtonLabel
:
325 return IDS_FORM_THIS_WEEK_LABEL
;
326 case WebLocalizedString::ValidationBadInputForDateTime
:
327 return IDS_FORM_VALIDATION_BAD_INPUT_DATETIME
;
328 case WebLocalizedString::ValidationBadInputForNumber
:
329 return IDS_FORM_VALIDATION_BAD_INPUT_NUMBER
;
330 case WebLocalizedString::ValidationPatternMismatch
:
331 return IDS_FORM_VALIDATION_PATTERN_MISMATCH
;
332 case WebLocalizedString::ValidationRangeOverflow
:
333 return IDS_FORM_VALIDATION_RANGE_OVERFLOW
;
334 case WebLocalizedString::ValidationRangeOverflowDateTime
:
335 return IDS_FORM_VALIDATION_RANGE_OVERFLOW_DATETIME
;
336 case WebLocalizedString::ValidationRangeUnderflow
:
337 return IDS_FORM_VALIDATION_RANGE_UNDERFLOW
;
338 case WebLocalizedString::ValidationRangeUnderflowDateTime
:
339 return IDS_FORM_VALIDATION_RANGE_UNDERFLOW_DATETIME
;
340 case WebLocalizedString::ValidationStepMismatch
:
341 return IDS_FORM_VALIDATION_STEP_MISMATCH
;
342 case WebLocalizedString::ValidationStepMismatchCloseToLimit
:
343 return IDS_FORM_VALIDATION_STEP_MISMATCH_CLOSE_TO_LIMIT
;
344 case WebLocalizedString::ValidationTooLong
:
345 return IDS_FORM_VALIDATION_TOO_LONG
;
346 case WebLocalizedString::ValidationTypeMismatch
:
347 return IDS_FORM_VALIDATION_TYPE_MISMATCH
;
348 case WebLocalizedString::ValidationTypeMismatchForEmail
:
349 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL
;
350 case WebLocalizedString::ValidationTypeMismatchForEmailEmpty
:
351 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_EMPTY
;
352 case WebLocalizedString::ValidationTypeMismatchForEmailEmptyDomain
:
353 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_EMPTY_DOMAIN
;
354 case WebLocalizedString::ValidationTypeMismatchForEmailEmptyLocal
:
355 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_EMPTY_LOCAL
;
356 case WebLocalizedString::ValidationTypeMismatchForEmailInvalidDomain
:
357 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_INVALID_DOMAIN
;
358 case WebLocalizedString::ValidationTypeMismatchForEmailInvalidDots
:
359 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_INVALID_DOTS
;
360 case WebLocalizedString::ValidationTypeMismatchForEmailInvalidLocal
:
361 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_INVALID_LOCAL
;
362 case WebLocalizedString::ValidationTypeMismatchForEmailNoAtSign
:
363 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_NO_AT_SIGN
;
364 case WebLocalizedString::ValidationTypeMismatchForMultipleEmail
:
365 return IDS_FORM_VALIDATION_TYPE_MISMATCH_MULTIPLE_EMAIL
;
366 case WebLocalizedString::ValidationTypeMismatchForURL
:
367 return IDS_FORM_VALIDATION_TYPE_MISMATCH_URL
;
368 case WebLocalizedString::ValidationValueMissing
:
369 return IDS_FORM_VALIDATION_VALUE_MISSING
;
370 case WebLocalizedString::ValidationValueMissingForCheckbox
:
371 return IDS_FORM_VALIDATION_VALUE_MISSING_CHECKBOX
;
372 case WebLocalizedString::ValidationValueMissingForFile
:
373 return IDS_FORM_VALIDATION_VALUE_MISSING_FILE
;
374 case WebLocalizedString::ValidationValueMissingForMultipleFile
:
375 return IDS_FORM_VALIDATION_VALUE_MISSING_MULTIPLE_FILE
;
376 case WebLocalizedString::ValidationValueMissingForRadio
:
377 return IDS_FORM_VALIDATION_VALUE_MISSING_RADIO
;
378 case WebLocalizedString::ValidationValueMissingForSelect
:
379 return IDS_FORM_VALIDATION_VALUE_MISSING_SELECT
;
380 case WebLocalizedString::WeekFormatTemplate
:
381 return IDS_FORM_INPUT_WEEK_TEMPLATE
;
382 case WebLocalizedString::WeekNumberLabel
:
383 return IDS_FORM_WEEK_NUMBER_LABEL
;
384 // This "default:" line exists to avoid compile warnings about enum
385 // coverage when we add a new symbol to WebLocalizedString.h in WebKit.
386 // After a planned WebKit patch is landed, we need to add a case statement
387 // for the added symbol here.
394 BlinkPlatformImpl::BlinkPlatformImpl()
395 : main_loop_(base::MessageLoop::current()),
396 shared_timer_func_(NULL
),
397 shared_timer_fire_time_(0.0),
398 shared_timer_fire_time_was_set_while_suspended_(false),
399 shared_timer_suspended_(0),
400 fling_curve_configuration_(new FlingCurveConfiguration
),
401 current_thread_slot_(&DestroyCurrentThread
) {}
403 BlinkPlatformImpl::~BlinkPlatformImpl() {
406 WebURLLoader
* BlinkPlatformImpl::createURLLoader() {
407 return new WebURLLoaderImpl
;
410 WebSocketStreamHandle
* BlinkPlatformImpl::createSocketStreamHandle() {
411 return new WebSocketStreamHandleImpl
;
414 blink::WebSocketHandle
* BlinkPlatformImpl::createWebSocketHandle() {
415 return new WebSocketBridge
;
418 WebString
BlinkPlatformImpl::userAgent() {
419 return WebString::fromUTF8(GetContentClient()->GetUserAgent());
422 WebData
BlinkPlatformImpl::parseDataURL(const WebURL
& url
,
423 WebString
& mimetype_out
,
424 WebString
& charset_out
) {
425 std::string mime_type
, char_set
, data
;
426 if (net::DataURL::Parse(url
, &mime_type
, &char_set
, &data
)
427 && net::IsSupportedMimeType(mime_type
)) {
428 mimetype_out
= WebString::fromUTF8(mime_type
);
429 charset_out
= WebString::fromUTF8(char_set
);
435 WebURLError
BlinkPlatformImpl::cancelledError(
436 const WebURL
& unreachableURL
) const {
437 return WebURLLoaderImpl::CreateError(unreachableURL
, false, net::ERR_ABORTED
);
440 blink::WebThread
* BlinkPlatformImpl::createThread(const char* name
) {
441 return new WebThreadImpl(name
);
444 blink::WebThread
* BlinkPlatformImpl::currentThread() {
445 WebThreadImplForMessageLoop
* thread
=
446 static_cast<WebThreadImplForMessageLoop
*>(current_thread_slot_
.Get());
450 scoped_refptr
<base::MessageLoopProxy
> message_loop
=
451 base::MessageLoopProxy::current();
452 if (!message_loop
.get())
455 thread
= new WebThreadImplForMessageLoop(message_loop
.get());
456 current_thread_slot_
.Set(thread
);
460 blink::WebWaitableEvent
* BlinkPlatformImpl::createWaitableEvent() {
461 return new WebWaitableEventImpl();
464 blink::WebWaitableEvent
* BlinkPlatformImpl::waitMultipleEvents(
465 const blink::WebVector
<blink::WebWaitableEvent
*>& web_events
) {
466 std::vector
<base::WaitableEvent
*> events
;
467 for (size_t i
= 0; i
< web_events
.size(); ++i
)
468 events
.push_back(static_cast<WebWaitableEventImpl
*>(web_events
[i
])->impl());
469 size_t idx
= base::WaitableEvent::WaitMany(
470 vector_as_array(&events
), events
.size());
471 DCHECK_LT(idx
, web_events
.size());
472 return web_events
[idx
];
475 void BlinkPlatformImpl::decrementStatsCounter(const char* name
) {
476 base::StatsCounter(name
).Decrement();
479 void BlinkPlatformImpl::incrementStatsCounter(const char* name
) {
480 base::StatsCounter(name
).Increment();
483 void BlinkPlatformImpl::histogramCustomCounts(
484 const char* name
, int sample
, int min
, int max
, int bucket_count
) {
485 // Copied from histogram macro, but without the static variable caching
486 // the histogram because name is dynamic.
487 base::HistogramBase
* counter
=
488 base::Histogram::FactoryGet(name
, min
, max
, bucket_count
,
489 base::HistogramBase::kUmaTargetedHistogramFlag
);
490 DCHECK_EQ(name
, counter
->histogram_name());
491 counter
->Add(sample
);
494 void BlinkPlatformImpl::histogramEnumeration(
495 const char* name
, int sample
, int boundary_value
) {
496 // Copied from histogram macro, but without the static variable caching
497 // the histogram because name is dynamic.
498 base::HistogramBase
* counter
=
499 base::LinearHistogram::FactoryGet(name
, 1, boundary_value
,
500 boundary_value
+ 1, base::HistogramBase::kUmaTargetedHistogramFlag
);
501 DCHECK_EQ(name
, counter
->histogram_name());
502 counter
->Add(sample
);
505 void BlinkPlatformImpl::histogramSparse(const char* name
, int sample
) {
506 // For sparse histograms, we can use the macro, as it does not incorporate a
508 UMA_HISTOGRAM_SPARSE_SLOWLY(name
, sample
);
511 const unsigned char* BlinkPlatformImpl::getTraceCategoryEnabledFlag(
512 const char* category_group
) {
513 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group
);
516 long* BlinkPlatformImpl::getTraceSamplingState(
517 const unsigned thread_bucket
) {
518 switch (thread_bucket
) {
520 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(0));
522 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(1));
524 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(2));
526 NOTREACHED() << "Unknown thread bucket type.";
532 sizeof(blink::Platform::TraceEventHandle
) ==
533 sizeof(base::debug::TraceEventHandle
),
534 TraceEventHandle_types_must_be_same_size
);
536 blink::Platform::TraceEventHandle
BlinkPlatformImpl::addTraceEvent(
538 const unsigned char* category_group_enabled
,
540 unsigned long long id
,
542 const char** arg_names
,
543 const unsigned char* arg_types
,
544 const unsigned long long* arg_values
,
545 unsigned char flags
) {
546 base::debug::TraceEventHandle handle
= TRACE_EVENT_API_ADD_TRACE_EVENT(
547 phase
, category_group_enabled
, name
, id
,
548 num_args
, arg_names
, arg_types
, arg_values
, NULL
, flags
);
549 blink::Platform::TraceEventHandle result
;
550 memcpy(&result
, &handle
, sizeof(result
));
554 blink::Platform::TraceEventHandle
BlinkPlatformImpl::addTraceEvent(
556 const unsigned char* category_group_enabled
,
558 unsigned long long id
,
560 const char** arg_names
,
561 const unsigned char* arg_types
,
562 const unsigned long long* arg_values
,
563 const blink::WebConvertableToTraceFormat
* convertable_values
,
564 unsigned char flags
) {
565 scoped_refptr
<base::debug::ConvertableToTraceFormat
> convertable_wrappers
[2];
566 if (convertable_values
) {
567 size_t size
= std::min(static_cast<size_t>(num_args
),
568 arraysize(convertable_wrappers
));
569 for (size_t i
= 0; i
< size
; ++i
) {
570 if (arg_types
[i
] == TRACE_VALUE_TYPE_CONVERTABLE
) {
571 convertable_wrappers
[i
] =
572 new ConvertableToTraceFormatWrapper(convertable_values
[i
]);
576 base::debug::TraceEventHandle handle
=
577 TRACE_EVENT_API_ADD_TRACE_EVENT(phase
,
578 category_group_enabled
,
585 convertable_wrappers
,
587 blink::Platform::TraceEventHandle result
;
588 memcpy(&result
, &handle
, sizeof(result
));
592 void BlinkPlatformImpl::updateTraceEventDuration(
593 const unsigned char* category_group_enabled
,
595 TraceEventHandle handle
) {
596 base::debug::TraceEventHandle traceEventHandle
;
597 memcpy(&traceEventHandle
, &handle
, sizeof(handle
));
598 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
599 category_group_enabled
, name
, traceEventHandle
);
604 WebData
loadAudioSpatializationResource(const char* name
) {
605 #ifdef IDR_AUDIO_SPATIALIZATION_COMPOSITE
606 if (!strcmp(name
, "Composite")) {
607 base::StringPiece resource
= GetContentClient()->GetDataResource(
608 IDR_AUDIO_SPATIALIZATION_COMPOSITE
, ui::SCALE_FACTOR_NONE
);
609 return WebData(resource
.data(), resource
.size());
613 #ifdef IDR_AUDIO_SPATIALIZATION_T000_P000
614 const size_t kExpectedSpatializationNameLength
= 31;
615 if (strlen(name
) != kExpectedSpatializationNameLength
) {
619 // Extract the azimuth and elevation from the resource name.
623 sscanf(name
, "IRC_Composite_C_R0195_T%3d_P%3d", &azimuth
, &elevation
);
624 if (values_parsed
!= 2) {
628 // The resource index values go through the elevations first, then azimuths.
629 const int kAngleSpacing
= 15;
631 // 0 <= elevation <= 90 (or 315 <= elevation <= 345)
632 // in increments of 15 degrees.
633 int elevation_index
=
634 elevation
<= 90 ? elevation
/ kAngleSpacing
:
635 7 + (elevation
- 315) / kAngleSpacing
;
636 bool is_elevation_index_good
= 0 <= elevation_index
&& elevation_index
< 10;
638 // 0 <= azimuth < 360 in increments of 15 degrees.
639 int azimuth_index
= azimuth
/ kAngleSpacing
;
640 bool is_azimuth_index_good
= 0 <= azimuth_index
&& azimuth_index
< 24;
642 const int kNumberOfElevations
= 10;
643 const int kNumberOfAudioResources
= 240;
644 int resource_index
= kNumberOfElevations
* azimuth_index
+ elevation_index
;
645 bool is_resource_index_good
= 0 <= resource_index
&&
646 resource_index
< kNumberOfAudioResources
;
648 if (is_azimuth_index_good
&& is_elevation_index_good
&&
649 is_resource_index_good
) {
650 const int kFirstAudioResourceIndex
= IDR_AUDIO_SPATIALIZATION_T000_P000
;
651 base::StringPiece resource
= GetContentClient()->GetDataResource(
652 kFirstAudioResourceIndex
+ resource_index
, ui::SCALE_FACTOR_NONE
);
653 return WebData(resource
.data(), resource
.size());
655 #endif // IDR_AUDIO_SPATIALIZATION_T000_P000
661 struct DataResource
{
664 ui::ScaleFactor scale_factor
;
667 const DataResource kDataResources
[] = {
668 { "missingImage", IDR_BROKENIMAGE
, ui::SCALE_FACTOR_100P
},
669 { "missingImage@2x", IDR_BROKENIMAGE
, ui::SCALE_FACTOR_200P
},
670 { "mediaplayerPause", IDR_MEDIAPLAYER_PAUSE_BUTTON
, ui::SCALE_FACTOR_100P
},
671 { "mediaplayerPauseHover",
672 IDR_MEDIAPLAYER_PAUSE_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
673 { "mediaplayerPauseDown",
674 IDR_MEDIAPLAYER_PAUSE_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
675 { "mediaplayerPlay", IDR_MEDIAPLAYER_PLAY_BUTTON
, ui::SCALE_FACTOR_100P
},
676 { "mediaplayerPlayHover",
677 IDR_MEDIAPLAYER_PLAY_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
678 { "mediaplayerPlayDown",
679 IDR_MEDIAPLAYER_PLAY_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
680 { "mediaplayerPlayDisabled",
681 IDR_MEDIAPLAYER_PLAY_BUTTON_DISABLED
, ui::SCALE_FACTOR_100P
},
682 { "mediaplayerSoundLevel3",
683 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON
, ui::SCALE_FACTOR_100P
},
684 { "mediaplayerSoundLevel3Hover",
685 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
686 { "mediaplayerSoundLevel3Down",
687 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
688 { "mediaplayerSoundLevel2",
689 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON
, ui::SCALE_FACTOR_100P
},
690 { "mediaplayerSoundLevel2Hover",
691 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
692 { "mediaplayerSoundLevel2Down",
693 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
694 { "mediaplayerSoundLevel1",
695 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON
, ui::SCALE_FACTOR_100P
},
696 { "mediaplayerSoundLevel1Hover",
697 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
698 { "mediaplayerSoundLevel1Down",
699 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
700 { "mediaplayerSoundLevel0",
701 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON
, ui::SCALE_FACTOR_100P
},
702 { "mediaplayerSoundLevel0Hover",
703 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
704 { "mediaplayerSoundLevel0Down",
705 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
706 { "mediaplayerSoundDisabled",
707 IDR_MEDIAPLAYER_SOUND_DISABLED
, ui::SCALE_FACTOR_100P
},
708 { "mediaplayerSliderThumb",
709 IDR_MEDIAPLAYER_SLIDER_THUMB
, ui::SCALE_FACTOR_100P
},
710 { "mediaplayerSliderThumbHover",
711 IDR_MEDIAPLAYER_SLIDER_THUMB_HOVER
, ui::SCALE_FACTOR_100P
},
712 { "mediaplayerSliderThumbDown",
713 IDR_MEDIAPLAYER_SLIDER_THUMB_DOWN
, ui::SCALE_FACTOR_100P
},
714 { "mediaplayerVolumeSliderThumb",
715 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB
, ui::SCALE_FACTOR_100P
},
716 { "mediaplayerVolumeSliderThumbHover",
717 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_HOVER
, ui::SCALE_FACTOR_100P
},
718 { "mediaplayerVolumeSliderThumbDown",
719 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_DOWN
, ui::SCALE_FACTOR_100P
},
720 { "mediaplayerVolumeSliderThumbDisabled",
721 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_DISABLED
, ui::SCALE_FACTOR_100P
},
722 { "mediaplayerClosedCaption",
723 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON
, ui::SCALE_FACTOR_100P
},
724 { "mediaplayerClosedCaptionHover",
725 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
726 { "mediaplayerClosedCaptionDown",
727 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
728 { "mediaplayerClosedCaptionDisabled",
729 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_DISABLED
, ui::SCALE_FACTOR_100P
},
730 { "mediaplayerFullscreen",
731 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON
, ui::SCALE_FACTOR_100P
},
732 { "mediaplayerFullscreenHover",
733 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
734 { "mediaplayerFullscreenDown",
735 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
736 { "mediaplayerFullscreenDisabled",
737 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_DISABLED
, ui::SCALE_FACTOR_100P
},
738 { "mediaplayerOverlayPlay",
739 IDR_MEDIAPLAYER_OVERLAY_PLAY_BUTTON
, ui::SCALE_FACTOR_100P
},
740 #if defined(OS_MACOSX)
741 { "overhangPattern", IDR_OVERHANG_PATTERN
, ui::SCALE_FACTOR_100P
},
742 { "overhangShadow", IDR_OVERHANG_SHADOW
, ui::SCALE_FACTOR_100P
},
744 { "panIcon", IDR_PAN_SCROLL_ICON
, ui::SCALE_FACTOR_100P
},
745 { "searchCancel", IDR_SEARCH_CANCEL
, ui::SCALE_FACTOR_100P
},
746 { "searchCancelPressed", IDR_SEARCH_CANCEL_PRESSED
, ui::SCALE_FACTOR_100P
},
747 { "searchMagnifier", IDR_SEARCH_MAGNIFIER
, ui::SCALE_FACTOR_100P
},
748 { "searchMagnifierResults",
749 IDR_SEARCH_MAGNIFIER_RESULTS
, ui::SCALE_FACTOR_100P
},
750 { "textAreaResizeCorner", IDR_TEXTAREA_RESIZER
, ui::SCALE_FACTOR_100P
},
751 { "textAreaResizeCorner@2x", IDR_TEXTAREA_RESIZER
, ui::SCALE_FACTOR_200P
},
752 { "generatePassword", IDR_PASSWORD_GENERATION_ICON
, ui::SCALE_FACTOR_100P
},
753 { "generatePasswordHover",
754 IDR_PASSWORD_GENERATION_ICON_HOVER
, ui::SCALE_FACTOR_100P
},
759 WebData
BlinkPlatformImpl::loadResource(const char* name
) {
760 // Some clients will call into this method with an empty |name| when they have
761 // optional resources. For example, the PopupMenuChromium code can have icons
762 // for some Autofill items but not for others.
766 // Check the name prefix to see if it's an audio resource.
767 if (StartsWithASCII(name
, "IRC_Composite", true) ||
768 StartsWithASCII(name
, "Composite", true))
769 return loadAudioSpatializationResource(name
);
771 // TODO(flackr): We should use a better than linear search here, a trie would
773 for (size_t i
= 0; i
< arraysize(kDataResources
); ++i
) {
774 if (!strcmp(name
, kDataResources
[i
].name
)) {
775 base::StringPiece resource
= GetContentClient()->GetDataResource(
776 kDataResources
[i
].id
, kDataResources
[i
].scale_factor
);
777 return WebData(resource
.data(), resource
.size());
781 NOTREACHED() << "Unknown image resource " << name
;
785 WebString
BlinkPlatformImpl::queryLocalizedString(
786 WebLocalizedString::Name name
) {
787 int message_id
= ToMessageID(name
);
790 return GetContentClient()->GetLocalizedString(message_id
);
793 WebString
BlinkPlatformImpl::queryLocalizedString(
794 WebLocalizedString::Name name
, int numeric_value
) {
795 return queryLocalizedString(name
, base::IntToString16(numeric_value
));
798 WebString
BlinkPlatformImpl::queryLocalizedString(
799 WebLocalizedString::Name name
, const WebString
& value
) {
800 int message_id
= ToMessageID(name
);
803 return ReplaceStringPlaceholders(GetContentClient()->GetLocalizedString(
804 message_id
), value
, NULL
);
807 WebString
BlinkPlatformImpl::queryLocalizedString(
808 WebLocalizedString::Name name
,
809 const WebString
& value1
,
810 const WebString
& value2
) {
811 int message_id
= ToMessageID(name
);
814 std::vector
<base::string16
> values
;
816 values
.push_back(value1
);
817 values
.push_back(value2
);
818 return ReplaceStringPlaceholders(
819 GetContentClient()->GetLocalizedString(message_id
), values
, NULL
);
822 double BlinkPlatformImpl::currentTime() {
823 return base::Time::Now().ToDoubleT();
826 double BlinkPlatformImpl::monotonicallyIncreasingTime() {
827 return base::TimeTicks::Now().ToInternalValue() /
828 static_cast<double>(base::Time::kMicrosecondsPerSecond
);
831 void BlinkPlatformImpl::cryptographicallyRandomValues(
832 unsigned char* buffer
, size_t length
) {
833 base::RandBytes(buffer
, length
);
836 void BlinkPlatformImpl::setSharedTimerFiredFunction(void (*func
)()) {
837 shared_timer_func_
= func
;
840 void BlinkPlatformImpl::setSharedTimerFireInterval(
841 double interval_seconds
) {
842 shared_timer_fire_time_
= interval_seconds
+ monotonicallyIncreasingTime();
843 if (shared_timer_suspended_
) {
844 shared_timer_fire_time_was_set_while_suspended_
= true;
848 // By converting between double and int64 representation, we run the risk
849 // of losing precision due to rounding errors. Performing computations in
850 // microseconds reduces this risk somewhat. But there still is the potential
851 // of us computing a fire time for the timer that is shorter than what we
853 // As the event loop will check event deadlines prior to actually firing
854 // them, there is a risk of needlessly rescheduling events and of
855 // needlessly looping if sleep times are too short even by small amounts.
856 // This results in measurable performance degradation unless we use ceil() to
857 // always round up the sleep times.
858 int64 interval
= static_cast<int64
>(
859 ceil(interval_seconds
* base::Time::kMillisecondsPerSecond
)
860 * base::Time::kMicrosecondsPerMillisecond
);
865 shared_timer_
.Stop();
866 shared_timer_
.Start(FROM_HERE
, base::TimeDelta::FromMicroseconds(interval
),
867 this, &BlinkPlatformImpl::DoTimeout
);
868 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval
));
871 void BlinkPlatformImpl::stopSharedTimer() {
872 shared_timer_
.Stop();
875 void BlinkPlatformImpl::callOnMainThread(
876 void (*func
)(void*), void* context
) {
877 main_loop_
->PostTask(FROM_HERE
, base::Bind(func
, context
));
880 blink::WebGestureCurve
* BlinkPlatformImpl::createFlingAnimationCurve(
882 const blink::WebFloatPoint
& velocity
,
883 const blink::WebSize
& cumulative_scroll
) {
884 #if defined(OS_ANDROID)
885 return FlingAnimatorImpl::CreateAndroidGestureCurve(
890 if (device_source
== blink::WebGestureEvent::Touchscreen
)
891 return fling_curve_configuration_
->CreateForTouchScreen(velocity
,
894 return fling_curve_configuration_
->CreateForTouchPad(velocity
,
898 void BlinkPlatformImpl::didStartWorkerRunLoop(
899 const blink::WebWorkerRunLoop
& runLoop
) {
900 WorkerTaskRunner
* worker_task_runner
= WorkerTaskRunner::Instance();
901 worker_task_runner
->OnWorkerRunLoopStarted(runLoop
);
904 void BlinkPlatformImpl::didStopWorkerRunLoop(
905 const blink::WebWorkerRunLoop
& runLoop
) {
906 WorkerTaskRunner
* worker_task_runner
= WorkerTaskRunner::Instance();
907 worker_task_runner
->OnWorkerRunLoopStopped(runLoop
);
910 blink::WebCrypto
* BlinkPlatformImpl::crypto() {
911 WebCryptoImpl::EnsureInit();
916 WebThemeEngine
* BlinkPlatformImpl::themeEngine() {
917 return &native_theme_engine_
;
920 WebFallbackThemeEngine
* BlinkPlatformImpl::fallbackThemeEngine() {
921 return &fallback_theme_engine_
;
924 base::PlatformFile
BlinkPlatformImpl::databaseOpenFile(
925 const blink::WebString
& vfs_file_name
, int desired_flags
) {
926 return base::kInvalidPlatformFileValue
;
929 int BlinkPlatformImpl::databaseDeleteFile(
930 const blink::WebString
& vfs_file_name
, bool sync_dir
) {
934 long BlinkPlatformImpl::databaseGetFileAttributes(
935 const blink::WebString
& vfs_file_name
) {
939 long long BlinkPlatformImpl::databaseGetFileSize(
940 const blink::WebString
& vfs_file_name
) {
944 long long BlinkPlatformImpl::databaseGetSpaceAvailableForOrigin(
945 const blink::WebString
& origin_identifier
) {
949 blink::WebString
BlinkPlatformImpl::signedPublicKeyAndChallengeString(
950 unsigned key_size_index
,
951 const blink::WebString
& challenge
,
952 const blink::WebURL
& url
) {
953 return blink::WebString("");
956 static scoped_ptr
<base::ProcessMetrics
> CurrentProcessMetrics() {
957 using base::ProcessMetrics
;
958 #if defined(OS_MACOSX)
959 return scoped_ptr
<ProcessMetrics
>(
960 // The default port provider is sufficient to get data for the current
962 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(),
965 return scoped_ptr
<ProcessMetrics
>(
966 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle()));
970 static size_t getMemoryUsageMB(bool bypass_cache
) {
971 size_t current_mem_usage
= 0;
972 MemoryUsageCache
* mem_usage_cache_singleton
= MemoryUsageCache::GetInstance();
974 mem_usage_cache_singleton
->IsCachedValueValid(¤t_mem_usage
))
975 return current_mem_usage
;
977 current_mem_usage
= GetMemoryUsageKB() >> 10;
978 mem_usage_cache_singleton
->SetMemoryValue(current_mem_usage
);
979 return current_mem_usage
;
982 size_t BlinkPlatformImpl::memoryUsageMB() {
983 return getMemoryUsageMB(false);
986 size_t BlinkPlatformImpl::actualMemoryUsageMB() {
987 return getMemoryUsageMB(true);
990 size_t BlinkPlatformImpl::physicalMemoryMB() {
991 return static_cast<size_t>(base::SysInfo::AmountOfPhysicalMemoryMB());
994 size_t BlinkPlatformImpl::virtualMemoryLimitMB() {
995 return static_cast<size_t>(base::SysInfo::AmountOfVirtualMemoryMB());
998 size_t BlinkPlatformImpl::numberOfProcessors() {
999 return static_cast<size_t>(base::SysInfo::NumberOfProcessors());
1002 void BlinkPlatformImpl::startHeapProfiling(
1003 const blink::WebString
& prefix
) {
1004 // FIXME(morrita): Make this built on windows.
1005 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN)
1006 HeapProfilerStart(prefix
.utf8().data());
1010 void BlinkPlatformImpl::stopHeapProfiling() {
1011 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN)
1016 void BlinkPlatformImpl::dumpHeapProfiling(
1017 const blink::WebString
& reason
) {
1018 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN)
1019 HeapProfilerDump(reason
.utf8().data());
1023 WebString
BlinkPlatformImpl::getHeapProfile() {
1024 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN)
1025 char* data
= GetHeapProfile();
1026 WebString result
= WebString::fromUTF8(std::string(data
));
1034 bool BlinkPlatformImpl::processMemorySizesInBytes(
1035 size_t* private_bytes
,
1036 size_t* shared_bytes
) {
1037 return CurrentProcessMetrics()->GetMemoryBytes(private_bytes
, shared_bytes
);
1040 bool BlinkPlatformImpl::memoryAllocatorWasteInBytes(size_t* size
) {
1041 return base::allocator::GetAllocatorWasteSize(size
);
1044 blink::WebDiscardableMemory
*
1045 BlinkPlatformImpl::allocateAndLockDiscardableMemory(size_t bytes
) {
1046 base::DiscardableMemoryType type
=
1047 base::DiscardableMemory::GetPreferredType();
1048 if (type
== base::DISCARDABLE_MEMORY_TYPE_EMULATED
)
1050 return content::WebDiscardableMemoryImpl::CreateLockedMemory(bytes
).release();
1053 size_t BlinkPlatformImpl::maxDecodedImageBytes() {
1054 #if defined(OS_ANDROID)
1055 if (base::android::SysUtils::IsLowEndDevice()) {
1056 // Limit image decoded size to 3M pixels on low end devices.
1057 // 4 is maximum number of bytes per pixel.
1058 return 3 * 1024 * 1024 * 4;
1060 // For other devices, limit decoded image size based on the amount of physical
1062 // In some cases all physical memory is not accessible by Chromium, as it can
1063 // be reserved for direct use by certain hardware. Thus, we set the limit so
1064 // that 1.6GB of reported physical memory on a 2GB device is enough to set the
1065 // limit at 16M pixels, which is a desirable value since 4K*4K is a relatively
1066 // common texture size.
1067 return base::SysInfo::AmountOfPhysicalMemory() / 25;
1069 return noDecodedImageByteLimit
;
1073 void BlinkPlatformImpl::SetFlingCurveParameters(
1074 const std::vector
<float>& new_touchpad
,
1075 const std::vector
<float>& new_touchscreen
) {
1076 fling_curve_configuration_
->SetCurveParameters(new_touchpad
, new_touchscreen
);
1079 void BlinkPlatformImpl::SuspendSharedTimer() {
1080 ++shared_timer_suspended_
;
1083 void BlinkPlatformImpl::ResumeSharedTimer() {
1084 DCHECK_GT(shared_timer_suspended_
, 0);
1086 // The shared timer may have fired or been adjusted while we were suspended.
1087 if (--shared_timer_suspended_
== 0 &&
1088 (!shared_timer_
.IsRunning() ||
1089 shared_timer_fire_time_was_set_while_suspended_
)) {
1090 shared_timer_fire_time_was_set_while_suspended_
= false;
1091 setSharedTimerFireInterval(
1092 shared_timer_fire_time_
- monotonicallyIncreasingTime());
1097 void BlinkPlatformImpl::DestroyCurrentThread(void* thread
) {
1098 WebThreadImplForMessageLoop
* impl
=
1099 static_cast<WebThreadImplForMessageLoop
*>(thread
);
1103 } // namespace content