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

Unified Diff: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc

Issue 2691943010: Fix a data race on the ref count of AddToHomescreenDataFetcher (Closed)
Patch Set: +#include. +RetainedRef Created 3 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 | « chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
diff --git a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
index 576bbc3a43e1e97215e3cc8578a12e86669ff957..2dea7aa3a00b0457d742b1b3fc685e6c50b030e1 100644
--- a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
+++ b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
@@ -10,6 +10,7 @@
#include "base/callback.h"
#include "base/location.h"
#include "base/strings/string16.h"
+#include "base/task_runner_util.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/android/offline_pages/offline_page_utils.h"
#include "chrome/browser/android/shortcut_helper.h"
@@ -74,6 +75,10 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
bool check_webapk_compatibility,
Observer* observer)
: WebContentsObserver(web_contents),
+ background_task_runner_(
+ content::BrowserThread::GetBlockingPool()
+ ->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
weak_observer_(observer),
shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(),
web_contents->GetLastCommittedURL())),
@@ -286,14 +291,16 @@ void AddToHomescreenDataFetcher::OnFaviconFetched(
if (!web_contents() || !weak_observer_ || is_icon_saved_)
return;
- content::BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior(
- FROM_HERE, base::Bind(&AddToHomescreenDataFetcher::
- CreateLauncherIconFromFaviconInBackground,
- this, bitmap_result),
- base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
+ base::PostTaskAndReplyWithResult(
+ background_task_runner_.get(), FROM_HERE,
+ base::Bind(&AddToHomescreenDataFetcher::
+ CreateLauncherIconFromFaviconInBackground,
+ base::Unretained(this), bitmap_result),
+ base::Bind(&AddToHomescreenDataFetcher::NotifyObserver,
+ base::RetainedRef(this)));
}
-void AddToHomescreenDataFetcher::CreateLauncherIconFromFaviconInBackground(
+SkBitmap AddToHomescreenDataFetcher::CreateLauncherIconFromFaviconInBackground(
const favicon_base::FaviconRawBitmapResult& bitmap_result) {
DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
@@ -304,19 +311,20 @@ void AddToHomescreenDataFetcher::CreateLauncherIconFromFaviconInBackground(
}
shortcut_info_.best_primary_icon_url = bitmap_result.icon_url;
- CreateLauncherIconInBackground(raw_icon);
+ return CreateLauncherIconInBackground(raw_icon);
}
void AddToHomescreenDataFetcher::CreateLauncherIcon(const SkBitmap& raw_icon) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- content::BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior(
- FROM_HERE,
+ base::PostTaskAndReplyWithResult(
+ background_task_runner_.get(), FROM_HERE,
base::Bind(&AddToHomescreenDataFetcher::CreateLauncherIconInBackground,
- this, raw_icon),
- base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
+ base::Unretained(this), raw_icon),
+ base::Bind(&AddToHomescreenDataFetcher::NotifyObserver,
+ base::RetainedRef(this)));
}
-void AddToHomescreenDataFetcher::CreateLauncherIconInBackground(
+SkBitmap AddToHomescreenDataFetcher::CreateLauncherIconInBackground(
const SkBitmap& raw_icon) {
DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
@@ -330,10 +338,7 @@ void AddToHomescreenDataFetcher::CreateLauncherIconInBackground(
if (is_generated)
shortcut_info_.best_primary_icon_url = GURL();
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::Bind(&AddToHomescreenDataFetcher::NotifyObserver, this,
- primary_icon));
+ return primary_icon;
}
void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) {
« no previous file with comments | « chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698