Commit 9955ef24 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

[ios] Add lock preventing nest batch operation on WebStateList

WebStateList is not re-entrant (already asserted by locked_)
so there is no point nesting batched operations. Add a bool
to ensure this is not the case.

Add a method to check whether a batched operation is in
progress (could be used internally to also omit sending
notification during a batched operation).

Bug: 1014526
Change-Id: I6b6dc3278312895a32898d898245f538f9a5264d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2089675
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750916}
parent d5a6d52a
...@@ -85,6 +85,9 @@ class WebStateList { ...@@ -85,6 +85,9 @@ class WebStateList {
// Returns true if the list is currently mutating. // Returns true if the list is currently mutating.
bool IsMutating() const; bool IsMutating() const;
// Returns true if a batch operation is in progress.
bool IsBatchInProgress() const;
// Returns the currently active WebState or null if there is none. // Returns the currently active WebState or null if there is none.
web::WebState* GetActiveWebState() const; web::WebState* GetActiveWebState() const;
...@@ -276,6 +279,9 @@ class WebStateList { ...@@ -276,6 +279,9 @@ class WebStateList {
// by the returned base::AutoReset<bool>). // by the returned base::AutoReset<bool>).
bool locked_ = false; bool locked_ = false;
// Lock to prevent nesting batched operations.
bool batch_operation_in_progress_ = false;
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(WebStateList); DISALLOW_COPY_AND_ASSIGN(WebStateList);
......
...@@ -132,6 +132,11 @@ bool WebStateList::IsMutating() const { ...@@ -132,6 +132,11 @@ bool WebStateList::IsMutating() const {
return locked_; return locked_;
} }
bool WebStateList::IsBatchInProgress() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return batch_operation_in_progress_;
}
web::WebState* WebStateList::GetActiveWebState() const { web::WebState* WebStateList::GetActiveWebState() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (active_index_ != kInvalidIndex) if (active_index_ != kInvalidIndex)
...@@ -451,6 +456,10 @@ void WebStateList::RemoveObserver(WebStateListObserver* observer) { ...@@ -451,6 +456,10 @@ void WebStateList::RemoveObserver(WebStateListObserver* observer) {
void WebStateList::PerformBatchOperation( void WebStateList::PerformBatchOperation(
base::OnceCallback<void(WebStateList*)> operation) { base::OnceCallback<void(WebStateList*)> operation) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!batch_operation_in_progress_);
base::AutoReset<bool> lock(&batch_operation_in_progress_, /*locked=*/true);
for (auto& observer : observers_) for (auto& observer : observers_)
observer.WillBeginBatchOperation(this); observer.WillBeginBatchOperation(this);
if (!operation.is_null()) if (!operation.is_null())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment