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

Unified Diff: chrome/browser/web_applications/web_app.cc

Issue 2703283005: Destroy web_app::ShortcutInfo on UI thread (Closed)
Patch Set: +TestBrowserThreadBundle 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/web_applications/web_app.h ('k') | chrome/browser/web_applications/web_app_chromeos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/web_applications/web_app.cc
diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc
index d0da8543b40f3381214cef41238a0f50b9bd3003..298dcb96d7df2401bce8fa3b9077f16b3cd1ad5f 100644
--- a/chrome/browser/web_applications/web_app.cc
+++ b/chrome/browser/web_applications/web_app.cc
@@ -90,15 +90,14 @@ void UpdateAllShortcutsForShortcutInfo(
const base::Closure& callback,
std::unique_ptr<web_app::ShortcutInfo> shortcut_info) {
base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info);
- base::Closure task = base::Bind(&web_app::internals::UpdatePlatformShortcuts,
- shortcut_data_dir, old_app_title,
- base::Passed(&shortcut_info));
- if (callback.is_null()) {
- BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task);
- } else {
- BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, task,
- callback);
- }
+ const web_app::ShortcutInfo& shortcut_info_ref = *shortcut_info;
+ BrowserThread::PostTaskAndReply(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&web_app::internals::UpdatePlatformShortcuts,
+ shortcut_data_dir, old_app_title,
+ base::ConstRef(shortcut_info_ref)),
+ base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread,
+ base::Passed(&shortcut_info), callback));
}
void OnImageLoaded(std::unique_ptr<web_app::ShortcutInfo> shortcut_info,
@@ -130,11 +129,16 @@ void ScheduleCreatePlatformShortcut(
const web_app::ShortcutLocations& locations,
std::unique_ptr<web_app::ShortcutInfo> shortcut_info) {
base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info);
- BrowserThread::PostTask(
+
+ const web_app::ShortcutInfo& shortcut_info_ref = *shortcut_info;
+ BrowserThread::PostTaskAndReply(
BrowserThread::FILE, FROM_HERE,
base::Bind(
base::IgnoreResult(&web_app::internals::CreatePlatformShortcuts),
- shortcut_data_dir, base::Passed(&shortcut_info), locations, reason));
+ shortcut_data_dir, base::ConstRef(shortcut_info_ref), locations,
+ reason),
+ base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread,
+ base::Passed(&shortcut_info), base::Closure()));
}
} // namespace
@@ -161,10 +165,21 @@ base::FilePath GetSanitizedFileName(const base::string16& name) {
return base::FilePath(file_name);
}
+void DeleteShortcutInfoOnUIThread(
+ std::unique_ptr<web_app::ShortcutInfo> shortcut_info,
+ const base::Closure& callback) {
+ shortcut_info.reset();
+ if (callback)
+ callback.Run();
+}
+
} // namespace internals
ShortcutInfo::ShortcutInfo() {}
-ShortcutInfo::~ShortcutInfo() {}
+
+ShortcutInfo::~ShortcutInfo() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+}
ShortcutLocations::ShortcutLocations()
: on_desktop(false),
@@ -430,10 +445,14 @@ void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) {
std::unique_ptr<ShortcutInfo> shortcut_info(
ShortcutInfoForExtensionAndProfile(app, profile));
base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info);
- BrowserThread::PostTask(
+ const web_app::ShortcutInfo& shortcut_info_ref = *shortcut_info;
+
+ BrowserThread::PostTaskAndReply(
BrowserThread::FILE, FROM_HERE,
base::Bind(&web_app::internals::DeletePlatformShortcuts,
- shortcut_data_dir, base::Passed(&shortcut_info)));
+ shortcut_data_dir, base::ConstRef(shortcut_info_ref)),
+ base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread,
+ base::Passed(&shortcut_info), base::Closure()));
}
void UpdateAllShortcuts(const base::string16& old_app_title,
« no previous file with comments | « chrome/browser/web_applications/web_app.h ('k') | chrome/browser/web_applications/web_app_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698