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

Side by Side Diff: third_party/WebKit/Source/platform/UserGestureIndicator.cpp

Issue 2555013004: UserGestureIndicator: remove many unnecessary calls to isMainThread (Closed)
Patch Set: [test] remove isMainThread() check in currentToken() Created 4 years 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 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 24 matching lines...) Expand all
35 const double userGestureTimeout = 1.0; 35 const double userGestureTimeout = 1.0;
36 36
37 // For out of process tokens we allow a 10 second delay. 37 // For out of process tokens we allow a 10 second delay.
38 const double userGestureOutOfProcessTimeout = 10.0; 38 const double userGestureOutOfProcessTimeout = 10.0;
39 39
40 UserGestureToken::UserGestureToken(Status status) 40 UserGestureToken::UserGestureToken(Status status)
41 : m_consumableGestures(0), 41 : m_consumableGestures(0),
42 m_timestamp(WTF::currentTime()), 42 m_timestamp(WTF::currentTime()),
43 m_timeoutPolicy(Default), 43 m_timeoutPolicy(Default),
44 m_usageCallback(nullptr) { 44 m_usageCallback(nullptr) {
45 if (status == NewGesture || !UserGestureIndicator::currentToken()) 45 if (status == NewGesture ||
46 !UserGestureIndicator::currentToken(
47 UserGestureIndicator::CheckThreadState)) {
46 m_consumableGestures++; 48 m_consumableGestures++;
49 }
47 } 50 }
48 51
49 bool UserGestureToken::hasGestures() const { 52 bool UserGestureToken::hasGestures() const {
50 return m_consumableGestures && !hasTimedOut(); 53 return m_consumableGestures && !hasTimedOut();
51 } 54 }
52 55
53 void UserGestureToken::transferGestureTo(UserGestureToken* other) { 56 void UserGestureToken::transferGestureTo(UserGestureToken* other) {
54 if (!hasGestures()) 57 if (!hasGestures())
55 return; 58 return;
56 m_consumableGestures--; 59 m_consumableGestures--;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 146
144 // static 147 // static
145 bool UserGestureIndicator::utilizeUserGesture() { 148 bool UserGestureIndicator::utilizeUserGesture() {
146 if (UserGestureIndicator::processingUserGesture()) { 149 if (UserGestureIndicator::processingUserGesture()) {
147 s_rootToken->userGestureUtilized(); 150 s_rootToken->userGestureUtilized();
148 return true; 151 return true;
149 } 152 }
150 return false; 153 return false;
151 } 154 }
152 155
153 bool UserGestureIndicator::processingUserGesture() { 156 bool UserGestureIndicator::processingUserGesture(ThreadCheck threadCheck) {
154 if (auto* token = currentToken()) { 157 if (auto* token = currentToken(threadCheck))
155 ASSERT(isMainThread());
156 return token->hasGestures(); 158 return token->hasGestures();
157 }
158
159 return false; 159 return false;
160 } 160 }
161 161
162 // static 162 // static
163 bool UserGestureIndicator::consumeUserGesture() { 163 bool UserGestureIndicator::consumeUserGesture(ThreadCheck threadCheck) {
164 if (auto* token = currentToken()) { 164 if (auto* token = currentToken(threadCheck)) {
165 ASSERT(isMainThread());
166 if (token->consumeGesture()) { 165 if (token->consumeGesture()) {
167 token->userGestureUtilized(); 166 token->userGestureUtilized();
168 return true; 167 return true;
169 } 168 }
170 } 169 }
171 return false; 170 return false;
172 } 171 }
173 172
174 // static 173 UserGestureToken* UserGestureIndicator::currentToken(ThreadCheck threadCheck) {
175 UserGestureToken* UserGestureIndicator::currentToken() { 174 if (threadCheck == CheckThreadState && !isMainThread())
176 if (!isMainThread() || !s_rootToken)
177 return nullptr; 175 return nullptr;
176 DCHECK(isMainThread());
178 return s_rootToken; 177 return s_rootToken;
179 } 178 }
180 179
181 } // namespace blink 180 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698