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

Unified Diff: ios/chrome/browser/web/dom_altering_lock.mm

Issue 927373002: [iOS] Upstream DomAlteringLock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor comment change Created 5 years, 10 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 | « ios/chrome/browser/web/dom_altering_lock.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/web/dom_altering_lock.mm
diff --git a/ios/chrome/browser/web/dom_altering_lock.mm b/ios/chrome/browser/web/dom_altering_lock.mm
new file mode 100644
index 0000000000000000000000000000000000000000..2d5aa49698664ec69a1b8ed741b182d070ed443b
--- /dev/null
+++ b/ios/chrome/browser/web/dom_altering_lock.mm
@@ -0,0 +1,48 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/web/dom_altering_lock.h"
+
+#include "base/logging.h"
+#include "ios/web/public/web_thread.h"
+
+DEFINE_WEB_STATE_USER_DATA_KEY(DOMAlteringLock);
+
+DOMAlteringLock::DOMAlteringLock(web::WebState* web_state) {
+}
+
+DOMAlteringLock::~DOMAlteringLock() {
+}
+
+void DOMAlteringLock::Acquire(id<DOMAltering> feature,
+ ProceduralBlockWithBool lockAction) {
+ DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
+ if (current_dom_altering_feature_.get() == feature) {
+ lockAction(YES);
+ return;
+ }
+ if (current_dom_altering_feature_) {
+ if (![current_dom_altering_feature_ canReleaseDOMLock]) {
+ lockAction(NO);
+ return;
+ }
+ [current_dom_altering_feature_ releaseDOMLockWithCompletionHandler:^() {
+ DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
+ DCHECK(current_dom_altering_feature_.get() == nil)
+ << "The lock must be released before calling the completion handler.";
+ current_dom_altering_feature_.reset(feature);
+ lockAction(YES);
+ }];
+ return;
+ }
+ current_dom_altering_feature_.reset(feature);
+ lockAction(YES);
+}
+
+// Release the lock on the DOM tree.
+void DOMAlteringLock::Release(id<DOMAltering> feature) {
+ DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
+ if (current_dom_altering_feature_.get() == feature)
+ current_dom_altering_feature_.reset();
+}
« no previous file with comments | « ios/chrome/browser/web/dom_altering_lock.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698