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

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

Issue 1502093002: Improve ScriptForbiddenScope handling in cross-threaded code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased up past r363426 Created 5 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 // 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 "config.h" 5 #include "config.h"
6 #include "platform/ScriptForbiddenScope.h" 6 #include "platform/ScriptForbiddenScope.h"
7 7
8 #include "wtf/Assertions.h" 8 #include "wtf/Assertions.h"
9 #include "wtf/MainThread.h" 9 #include "wtf/MainThread.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 static unsigned s_scriptForbiddenCount = 0; 13 static unsigned s_scriptForbiddenCount = 0;
14 14
15 ScriptForbiddenScope::ScriptForbiddenScope() 15 ScriptForbiddenScope::ScriptForbiddenScope()
16 { 16 {
17 ASSERT(isMainThread()); 17 enter();
18 ++s_scriptForbiddenCount;
19 } 18 }
20 19
21 ScriptForbiddenScope::~ScriptForbiddenScope() 20 ScriptForbiddenScope::~ScriptForbiddenScope()
22 { 21 {
23 ASSERT(isMainThread()); 22 exit();
24 ASSERT(s_scriptForbiddenCount);
25 --s_scriptForbiddenCount;
26 } 23 }
27 24
28 void ScriptForbiddenScope::enter() 25 void ScriptForbiddenScope::enter()
29 { 26 {
30 ASSERT(isMainThread()); 27 ASSERT(isMainThread());
31 ++s_scriptForbiddenCount; 28 ++s_scriptForbiddenCount;
32 } 29 }
33 30
34 void ScriptForbiddenScope::exit() 31 void ScriptForbiddenScope::exit()
35 { 32 {
(...skipping 11 matching lines...) Expand all
47 { 44 {
48 if (isMainThread()) 45 if (isMainThread())
49 m_change.emplace(s_scriptForbiddenCount, 0); 46 m_change.emplace(s_scriptForbiddenCount, 0);
50 } 47 }
51 48
52 ScriptForbiddenScope::AllowUserAgentScript::~AllowUserAgentScript() 49 ScriptForbiddenScope::AllowUserAgentScript::~AllowUserAgentScript()
53 { 50 {
54 ASSERT(!isMainThread() || !s_scriptForbiddenCount); 51 ASSERT(!isMainThread() || !s_scriptForbiddenCount);
55 } 52 }
56 53
54 ScriptForbiddenIfMainThreadScope::ScriptForbiddenIfMainThreadScope()
55 {
56 if (isMainThread())
57 ScriptForbiddenScope::enter();
58 }
59
60 ScriptForbiddenIfMainThreadScope::~ScriptForbiddenIfMainThreadScope()
61 {
62 if (isMainThread())
63 ScriptForbiddenScope::exit();
64 }
57 } // namespace blink 65 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/ScriptForbiddenScope.h ('k') | third_party/WebKit/Source/platform/heap/Heap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698