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

Unified Diff: third_party/WebKit/Source/platform/ScriptForbiddenScope.h

Issue 2213903002: Make ScriptForbiddenScope inlineable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moving count variable to private static member Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/ScriptForbiddenScope.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/ScriptForbiddenScope.h
diff --git a/third_party/WebKit/Source/platform/ScriptForbiddenScope.h b/third_party/WebKit/Source/platform/ScriptForbiddenScope.h
index 4a8e814454cab02ad9fdd6837175c59d9136d435..52b85d805c9abdebe110c3dd8a0a80d8d675bcbb 100644
--- a/third_party/WebKit/Source/platform/ScriptForbiddenScope.h
+++ b/third_party/WebKit/Source/platform/ScriptForbiddenScope.h
@@ -18,22 +18,44 @@ class PLATFORM_EXPORT ScriptForbiddenScope final {
STACK_ALLOCATED();
WTF_MAKE_NONCOPYABLE(ScriptForbiddenScope);
public:
- ScriptForbiddenScope();
- ~ScriptForbiddenScope();
+ ScriptForbiddenScope() { enter(); }
+ ~ScriptForbiddenScope() { exit(); }
class PLATFORM_EXPORT AllowUserAgentScript final {
STACK_ALLOCATED();
WTF_MAKE_NONCOPYABLE(AllowUserAgentScript);
public:
- AllowUserAgentScript();
- ~AllowUserAgentScript();
+ AllowUserAgentScript()
+ {
+ if (isMainThread())
+ m_change.emplace(&s_scriptForbiddenCount, 0);
+ }
+ ~AllowUserAgentScript()
+ {
+ DCHECK(!isMainThread() || !s_scriptForbiddenCount);
+ }
+
private:
Optional<AutoReset<unsigned>> m_change;
};
- static void enter();
- static void exit();
- static bool isScriptForbidden();
+ static void enter()
+ {
+ DCHECK(isMainThread());
+ ++s_scriptForbiddenCount;
+ }
+ static void exit()
+ {
+ DCHECK(s_scriptForbiddenCount);
+ --s_scriptForbiddenCount;
+ }
+ static bool isScriptForbidden()
+ {
+ return isMainThread() && s_scriptForbiddenCount;
+ }
+
+private:
+ static unsigned s_scriptForbiddenCount;
};
// Scoped disabling of script execution on the main thread,
@@ -47,8 +69,18 @@ class PLATFORM_EXPORT ScriptForbiddenIfMainThreadScope final {
STACK_ALLOCATED();
WTF_MAKE_NONCOPYABLE(ScriptForbiddenIfMainThreadScope);
public:
- ScriptForbiddenIfMainThreadScope();
- ~ScriptForbiddenIfMainThreadScope();
+ ScriptForbiddenIfMainThreadScope()
+ {
+ m_IsMainThread = isMainThread();
+ if (m_IsMainThread)
+ ScriptForbiddenScope::enter();
+ }
+ ~ScriptForbiddenIfMainThreadScope()
+ {
+ if (m_IsMainThread)
+ ScriptForbiddenScope::exit();
+ }
+ bool m_IsMainThread;
};
} // namespace blink
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/ScriptForbiddenScope.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698