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

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: 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
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..75298bbc867be15e88078716b979b1a78bc9d4af
--- /dev/null
+++ b/ios/chrome/browser/web/dom_altering_lock.mm
@@ -0,0 +1,45 @@
+// 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"
+
+DEFINE_WEB_STATE_USER_DATA_KEY(DOMAlteringLock);
+
+DOMAlteringLock::DOMAlteringLock(web::WebState* web_state) {
+}
+
+DOMAlteringLock::~DOMAlteringLock() {
+}
+
+void DOMAlteringLock::Acquire(id<DOMAltering> feature,
+ ProceduralBlockWithBool lockAction) {
+ DCHECK([NSThread isMainThread]);
sdefresne 2015/02/17 13:20:55 Can you use web::WebThread? And everywhere else.
+ 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([NSThread isMainThread]);
+ 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([NSThread isMainThread]);
+ if (current_dom_altering_feature_.get() == feature)
+ current_dom_altering_feature_.reset();
+}

Powered by Google App Engine
This is Rietveld 408576698