OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #import "ios/chrome/browser/web/dom_altering_lock.h" | |
6 | |
7 DEFINE_WEB_STATE_USER_DATA_KEY(DOMAlteringLock); | |
8 | |
9 DOMAlteringLock::DOMAlteringLock(web::WebState* web_state) { | |
10 } | |
11 | |
12 DOMAlteringLock::~DOMAlteringLock() { | |
13 } | |
14 | |
15 void DOMAlteringLock::Acquire(id<DOMAltering> feature, | |
16 ProceduralBlockWithBool lockAction) { | |
17 DCHECK([NSThread isMainThread]); | |
sdefresne
2015/02/17 13:20:55
Can you use web::WebThread? And everywhere else.
| |
18 if (current_dom_altering_feature_.get() == feature) { | |
19 lockAction(YES); | |
20 return; | |
21 } | |
22 if (current_dom_altering_feature_) { | |
23 if (![current_dom_altering_feature_ canReleaseDOMLock]) { | |
24 lockAction(NO); | |
25 return; | |
26 } | |
27 [current_dom_altering_feature_ releaseDOMLockWithCompletionHandler:^() { | |
28 DCHECK([NSThread isMainThread]); | |
29 DCHECK(current_dom_altering_feature_.get() == nil) | |
30 << "The lock must be released before calling the completion handler."; | |
31 current_dom_altering_feature_.reset(feature); | |
32 lockAction(YES); | |
33 }]; | |
34 return; | |
35 } | |
36 current_dom_altering_feature_.reset(feature); | |
37 lockAction(YES); | |
38 } | |
39 | |
40 // Release the lock on the DOM tree. | |
41 void DOMAlteringLock::Release(id<DOMAltering> feature) { | |
42 DCHECK([NSThread isMainThread]); | |
43 if (current_dom_altering_feature_.get() == feature) | |
44 current_dom_altering_feature_.reset(); | |
45 } | |
OLD | NEW |