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 #import "ios/chrome/browser/web/dom_altering_lock.h"
7 #include "base/logging.h"
8 #include "ios/web/public/web_thread.h"
10 DEFINE_WEB_STATE_USER_DATA_KEY(DOMAlteringLock);
12 DOMAlteringLock::DOMAlteringLock(web::WebState* web_state) {
15 DOMAlteringLock::~DOMAlteringLock() {
18 void DOMAlteringLock::Acquire(id<DOMAltering> feature,
19 ProceduralBlockWithBool lockAction) {
20 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
21 if (current_dom_altering_feature_.get() == feature) {
25 if (current_dom_altering_feature_) {
26 if (![current_dom_altering_feature_ canReleaseDOMLock]) {
30 [current_dom_altering_feature_ releaseDOMLockWithCompletionHandler:^() {
31 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
32 DCHECK(current_dom_altering_feature_.get() == nil)
33 << "The lock must be released before calling the completion handler.";
34 current_dom_altering_feature_.reset(feature);
39 current_dom_altering_feature_.reset(feature);
43 // Release the lock on the DOM tree.
44 void DOMAlteringLock::Release(id<DOMAltering> feature) {
45 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
46 if (current_dom_altering_feature_.get() == feature)
47 current_dom_altering_feature_.reset();