Commit 108ed6bd authored by Huanzhong Huang's avatar Huanzhong Huang Committed by Commit Bot

[iOS] Fix: cache counter might crash

Current implementation of the cache counter has a stability issue that
might crash the app due to certain timing of events.

This is an attempt to fix the issue.

Bug: 963006
Change-Id: I9da00ee138196286863a51d6d695c5434aa6f69a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1698540Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Commit-Queue: Huanzhong Huang <huanzhong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680009}
parent e332c4c8
......@@ -43,13 +43,12 @@ class IOThreadCacheCounter {
STEP_GET_BACKEND, // Get the disk_cache::Backend instance.
STEP_COUNT, // Run CalculateSizeOfAllEntries() on it.
STEP_CALLBACK, // Respond on the UI thread.
STEP_DONE // Calculation completed.
};
void CountInternal(int64_t rv) {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
while (rv != net::ERR_IO_PENDING && next_step_ != STEP_DONE) {
while (rv != net::ERR_IO_PENDING) {
// In case of an error, skip to the last step.
if (rv < 0)
next_step_ = STEP_CALLBACK;
......@@ -83,7 +82,6 @@ class IOThreadCacheCounter {
}
case STEP_CALLBACK: {
next_step_ = STEP_DONE;
result_ = rv;
base::PostTaskWithTraits(
......@@ -91,11 +89,10 @@ class IOThreadCacheCounter {
base::BindOnce(&IOThreadCacheCounter::OnCountingFinished,
base::Unretained(this)));
break;
}
case STEP_DONE: {
NOTREACHED();
// Return instead of break.
// The task above deletes this object; app would crash if this object
// is deleted before reentrance of the loop.
return;
}
}
}
......
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