Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / ios / chrome / browser / web / dom_altering_lock.mm
blob2d5aa49698664ec69a1b8ed741b182d070ed443b
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) {
22     lockAction(YES);
23     return;
24   }
25   if (current_dom_altering_feature_) {
26     if (![current_dom_altering_feature_ canReleaseDOMLock]) {
27       lockAction(NO);
28       return;
29     }
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);
35       lockAction(YES);
36     }];
37     return;
38   }
39   current_dom_altering_feature_.reset(feature);
40   lockAction(YES);
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();