OLD | NEW |
---|---|
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 Loading... | |
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 web_app::ShortcutInfo* shortcut_info_ptr = shortcut_info.get(); |
tapted
2017/03/01 10:38:57
(I see this as taking an extra reference to a Shor
Matt Giuca
2017/03/01 23:17:28
The difference is that this code (you can verify b
| |
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::Unretained(shortcut_info_ptr)), |
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 Loading... | |
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 web_app::ShortcutInfo* shortcut_info_ptr = shortcut_info.get(); | |
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::Unretained(shortcut_info_ptr), 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 ShortcutInfo::~ShortcutInfo() {} |
tapted
2017/03/01 10:38:57
DCHECK_CURRENTLY_ON(BrowserThread::UI);
tzik
2017/03/01 12:34:04
Done.
| |
168 | 180 |
169 ShortcutLocations::ShortcutLocations() | 181 ShortcutLocations::ShortcutLocations() |
170 : on_desktop(false), | 182 : on_desktop(false), |
171 applications_menu_location(APP_MENU_LOCATION_NONE), | 183 applications_menu_location(APP_MENU_LOCATION_NONE), |
172 in_quick_launch_bar(false) { | 184 in_quick_launch_bar(false) { |
173 } | 185 } |
174 | 186 |
175 #if defined(TOOLKIT_VIEWS) | 187 #if defined(TOOLKIT_VIEWS) |
176 std::unique_ptr<ShortcutInfo> GetShortcutInfoForTab( | 188 std::unique_ptr<ShortcutInfo> GetShortcutInfoForTab( |
177 content::WebContents* web_contents) { | 189 content::WebContents* web_contents) { |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 GetShortcutInfoForApp( | 435 GetShortcutInfoForApp( |
424 app, profile, base::Bind(&CreateShortcutsWithInfo, reason, locations)); | 436 app, profile, base::Bind(&CreateShortcutsWithInfo, reason, locations)); |
425 } | 437 } |
426 | 438 |
427 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { | 439 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { |
428 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 440 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
429 | 441 |
430 std::unique_ptr<ShortcutInfo> shortcut_info( | 442 std::unique_ptr<ShortcutInfo> shortcut_info( |
431 ShortcutInfoForExtensionAndProfile(app, profile)); | 443 ShortcutInfoForExtensionAndProfile(app, profile)); |
432 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info); | 444 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info); |
433 BrowserThread::PostTask( | 445 web_app::ShortcutInfo* shortcut_info_ptr = shortcut_info.get(); |
446 | |
447 BrowserThread::PostTaskAndReply( | |
434 BrowserThread::FILE, FROM_HERE, | 448 BrowserThread::FILE, FROM_HERE, |
435 base::Bind(&web_app::internals::DeletePlatformShortcuts, | 449 base::Bind(&web_app::internals::DeletePlatformShortcuts, |
436 shortcut_data_dir, base::Passed(&shortcut_info))); | 450 shortcut_data_dir, base::Unretained(shortcut_info_ptr)), |
451 base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread, | |
452 base::Passed(&shortcut_info), base::Closure())); | |
437 } | 453 } |
438 | 454 |
439 void UpdateAllShortcuts(const base::string16& old_app_title, | 455 void UpdateAllShortcuts(const base::string16& old_app_title, |
440 Profile* profile, | 456 Profile* profile, |
441 const extensions::Extension* app, | 457 const extensions::Extension* app, |
442 const base::Closure& callback) { | 458 const base::Closure& callback) { |
443 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 459 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
444 | 460 |
445 GetShortcutInfoForApp( | 461 GetShortcutInfoForApp( |
446 app, profile, | 462 app, profile, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 | 500 |
485 #if defined(OS_LINUX) | 501 #if defined(OS_LINUX) |
486 std::string GetWMClassFromAppName(std::string app_name) { | 502 std::string GetWMClassFromAppName(std::string app_name) { |
487 base::i18n::ReplaceIllegalCharactersInPath(&app_name, '_'); | 503 base::i18n::ReplaceIllegalCharactersInPath(&app_name, '_'); |
488 base::TrimString(app_name, "_", &app_name); | 504 base::TrimString(app_name, "_", &app_name); |
489 return app_name; | 505 return app_name; |
490 } | 506 } |
491 #endif | 507 #endif |
492 | 508 |
493 } // namespace web_app | 509 } // namespace web_app |
OLD | NEW |