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

Side by Side Diff: chrome/browser/web_applications/web_app.cc

Issue 2703283005: Destroy web_app::ShortcutInfo on UI thread (Closed)
Patch Set: +TestBrowserThreadBundle Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/web_applications/web_app.h" 5 #include "chrome/browser/web_applications/web_app.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 return web_app::GetWebAppDataDirectory(shortcut_info.profile_path, 83 return web_app::GetWebAppDataDirectory(shortcut_info.profile_path,
84 shortcut_info.extension_id, 84 shortcut_info.extension_id,
85 shortcut_info.url); 85 shortcut_info.url);
86 } 86 }
87 87
88 void UpdateAllShortcutsForShortcutInfo( 88 void UpdateAllShortcutsForShortcutInfo(
89 const base::string16& old_app_title, 89 const base::string16& old_app_title,
90 const base::Closure& callback, 90 const base::Closure& callback,
91 std::unique_ptr<web_app::ShortcutInfo> shortcut_info) { 91 std::unique_ptr<web_app::ShortcutInfo> shortcut_info) {
92 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info); 92 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info);
93 base::Closure task = base::Bind(&web_app::internals::UpdatePlatformShortcuts, 93 const web_app::ShortcutInfo& shortcut_info_ref = *shortcut_info;
94 shortcut_data_dir, old_app_title, 94 BrowserThread::PostTaskAndReply(
95 base::Passed(&shortcut_info)); 95 BrowserThread::FILE, FROM_HERE,
96 if (callback.is_null()) { 96 base::Bind(&web_app::internals::UpdatePlatformShortcuts,
97 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); 97 shortcut_data_dir, old_app_title,
98 } else { 98 base::ConstRef(shortcut_info_ref)),
99 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, task, 99 base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread,
100 callback); 100 base::Passed(&shortcut_info), callback));
101 }
102 } 101 }
103 102
104 void OnImageLoaded(std::unique_ptr<web_app::ShortcutInfo> shortcut_info, 103 void OnImageLoaded(std::unique_ptr<web_app::ShortcutInfo> shortcut_info,
105 web_app::ShortcutInfoCallback callback, 104 web_app::ShortcutInfoCallback callback,
106 const gfx::ImageFamily& image_family) { 105 const gfx::ImageFamily& image_family) {
107 // If the image failed to load (e.g. if the resource being loaded was empty) 106 // If the image failed to load (e.g. if the resource being loaded was empty)
108 // use the standard application icon. 107 // use the standard application icon.
109 if (image_family.empty()) { 108 if (image_family.empty()) {
110 gfx::Image default_icon = 109 gfx::Image default_icon =
111 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON); 110 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON);
(...skipping 11 matching lines...) Expand all
123 } 122 }
124 123
125 callback.Run(std::move(shortcut_info)); 124 callback.Run(std::move(shortcut_info));
126 } 125 }
127 126
128 void ScheduleCreatePlatformShortcut( 127 void ScheduleCreatePlatformShortcut(
129 web_app::ShortcutCreationReason reason, 128 web_app::ShortcutCreationReason reason,
130 const web_app::ShortcutLocations& locations, 129 const web_app::ShortcutLocations& locations,
131 std::unique_ptr<web_app::ShortcutInfo> shortcut_info) { 130 std::unique_ptr<web_app::ShortcutInfo> shortcut_info) {
132 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info); 131 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info);
133 BrowserThread::PostTask( 132
133 const web_app::ShortcutInfo& shortcut_info_ref = *shortcut_info;
134 BrowserThread::PostTaskAndReply(
134 BrowserThread::FILE, FROM_HERE, 135 BrowserThread::FILE, FROM_HERE,
135 base::Bind( 136 base::Bind(
136 base::IgnoreResult(&web_app::internals::CreatePlatformShortcuts), 137 base::IgnoreResult(&web_app::internals::CreatePlatformShortcuts),
137 shortcut_data_dir, base::Passed(&shortcut_info), locations, reason)); 138 shortcut_data_dir, base::ConstRef(shortcut_info_ref), locations,
139 reason),
140 base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread,
141 base::Passed(&shortcut_info), base::Closure()));
138 } 142 }
139 143
140 } // namespace 144 } // namespace
141 145
142 namespace web_app { 146 namespace web_app {
143 147
144 // The following string is used to build the directory name for 148 // The following string is used to build the directory name for
145 // shortcuts to chrome applications (the kind which are installed 149 // shortcuts to chrome applications (the kind which are installed
146 // from a CRX). Application shortcuts to URLs use the {host}_{path} 150 // from a CRX). Application shortcuts to URLs use the {host}_{path}
147 // for the name of this directory. Hosts can't include an underscore. 151 // for the name of this directory. Hosts can't include an underscore.
148 // By starting this string with an underscore, we ensure that there 152 // By starting this string with an underscore, we ensure that there
149 // are no naming conflicts. 153 // are no naming conflicts.
150 static const char kCrxAppPrefix[] = "_crx_"; 154 static const char kCrxAppPrefix[] = "_crx_";
151 155
152 namespace internals { 156 namespace internals {
153 157
154 base::FilePath GetSanitizedFileName(const base::string16& name) { 158 base::FilePath GetSanitizedFileName(const base::string16& name) {
155 #if defined(OS_WIN) 159 #if defined(OS_WIN)
156 base::string16 file_name = name; 160 base::string16 file_name = name;
157 #else 161 #else
158 std::string file_name = base::UTF16ToUTF8(name); 162 std::string file_name = base::UTF16ToUTF8(name);
159 #endif 163 #endif
160 base::i18n::ReplaceIllegalCharactersInPath(&file_name, '_'); 164 base::i18n::ReplaceIllegalCharactersInPath(&file_name, '_');
161 return base::FilePath(file_name); 165 return base::FilePath(file_name);
162 } 166 }
163 167
168 void DeleteShortcutInfoOnUIThread(
169 std::unique_ptr<web_app::ShortcutInfo> shortcut_info,
170 const base::Closure& callback) {
171 shortcut_info.reset();
172 if (callback)
173 callback.Run();
174 }
175
164 } // namespace internals 176 } // namespace internals
165 177
166 ShortcutInfo::ShortcutInfo() {} 178 ShortcutInfo::ShortcutInfo() {}
167 ShortcutInfo::~ShortcutInfo() {} 179
180 ShortcutInfo::~ShortcutInfo() {
181 DCHECK_CURRENTLY_ON(BrowserThread::UI);
182 }
168 183
169 ShortcutLocations::ShortcutLocations() 184 ShortcutLocations::ShortcutLocations()
170 : on_desktop(false), 185 : on_desktop(false),
171 applications_menu_location(APP_MENU_LOCATION_NONE), 186 applications_menu_location(APP_MENU_LOCATION_NONE),
172 in_quick_launch_bar(false) { 187 in_quick_launch_bar(false) {
173 } 188 }
174 189
175 #if defined(TOOLKIT_VIEWS) 190 #if defined(TOOLKIT_VIEWS)
176 std::unique_ptr<ShortcutInfo> GetShortcutInfoForTab( 191 std::unique_ptr<ShortcutInfo> GetShortcutInfoForTab(
177 content::WebContents* web_contents) { 192 content::WebContents* web_contents) {
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 GetShortcutInfoForApp( 438 GetShortcutInfoForApp(
424 app, profile, base::Bind(&CreateShortcutsWithInfo, reason, locations)); 439 app, profile, base::Bind(&CreateShortcutsWithInfo, reason, locations));
425 } 440 }
426 441
427 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { 442 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) {
428 DCHECK_CURRENTLY_ON(BrowserThread::UI); 443 DCHECK_CURRENTLY_ON(BrowserThread::UI);
429 444
430 std::unique_ptr<ShortcutInfo> shortcut_info( 445 std::unique_ptr<ShortcutInfo> shortcut_info(
431 ShortcutInfoForExtensionAndProfile(app, profile)); 446 ShortcutInfoForExtensionAndProfile(app, profile));
432 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info); 447 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info);
433 BrowserThread::PostTask( 448 const web_app::ShortcutInfo& shortcut_info_ref = *shortcut_info;
449
450 BrowserThread::PostTaskAndReply(
434 BrowserThread::FILE, FROM_HERE, 451 BrowserThread::FILE, FROM_HERE,
435 base::Bind(&web_app::internals::DeletePlatformShortcuts, 452 base::Bind(&web_app::internals::DeletePlatformShortcuts,
436 shortcut_data_dir, base::Passed(&shortcut_info))); 453 shortcut_data_dir, base::ConstRef(shortcut_info_ref)),
454 base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread,
455 base::Passed(&shortcut_info), base::Closure()));
437 } 456 }
438 457
439 void UpdateAllShortcuts(const base::string16& old_app_title, 458 void UpdateAllShortcuts(const base::string16& old_app_title,
440 Profile* profile, 459 Profile* profile,
441 const extensions::Extension* app, 460 const extensions::Extension* app,
442 const base::Closure& callback) { 461 const base::Closure& callback) {
443 DCHECK_CURRENTLY_ON(BrowserThread::UI); 462 DCHECK_CURRENTLY_ON(BrowserThread::UI);
444 463
445 GetShortcutInfoForApp( 464 GetShortcutInfoForApp(
446 app, profile, 465 app, profile,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 503
485 #if defined(OS_LINUX) 504 #if defined(OS_LINUX)
486 std::string GetWMClassFromAppName(std::string app_name) { 505 std::string GetWMClassFromAppName(std::string app_name) {
487 base::i18n::ReplaceIllegalCharactersInPath(&app_name, '_'); 506 base::i18n::ReplaceIllegalCharactersInPath(&app_name, '_');
488 base::TrimString(app_name, "_", &app_name); 507 base::TrimString(app_name, "_", &app_name);
489 return app_name; 508 return app_name;
490 } 509 }
491 #endif 510 #endif
492 511
493 } // namespace web_app 512 } // namespace web_app
OLDNEW
« 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