Chromium Code Reviews| 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 auto* shortcut_info_ptr = shortcut_info.get(); |
|
tapted
2017/02/27 06:57:37
perhaps spell out what the auto type is to make th
tzik
2017/02/27 07:42:12
Done.
| |
| 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, shortcut_info_ptr), |
|
tapted
2017/02/27 06:57:37
the raw pointer here feels bad.. and shouldn't it
tzik
2017/02/27 07:42:12
Added base::Unretained().
base::Bind() does enforc
| |
| 98 } else { | 98 base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread, |
| 99 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, task, | 99 base::Passed(&shortcut_info), callback)); |
| 100 callback); | |
| 101 } | |
| 102 } | 100 } |
| 103 | 101 |
| 104 void OnImageLoaded(std::unique_ptr<web_app::ShortcutInfo> shortcut_info, | 102 void OnImageLoaded(std::unique_ptr<web_app::ShortcutInfo> shortcut_info, |
| 105 web_app::ShortcutInfoCallback callback, | 103 web_app::ShortcutInfoCallback callback, |
| 106 const gfx::ImageFamily& image_family) { | 104 const gfx::ImageFamily& image_family) { |
| 107 // If the image failed to load (e.g. if the resource being loaded was empty) | 105 // If the image failed to load (e.g. if the resource being loaded was empty) |
| 108 // use the standard application icon. | 106 // use the standard application icon. |
| 109 if (image_family.empty()) { | 107 if (image_family.empty()) { |
| 110 gfx::Image default_icon = | 108 gfx::Image default_icon = |
| 111 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON); | 109 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 123 } | 121 } |
| 124 | 122 |
| 125 callback.Run(std::move(shortcut_info)); | 123 callback.Run(std::move(shortcut_info)); |
| 126 } | 124 } |
| 127 | 125 |
| 128 void ScheduleCreatePlatformShortcut( | 126 void ScheduleCreatePlatformShortcut( |
| 129 web_app::ShortcutCreationReason reason, | 127 web_app::ShortcutCreationReason reason, |
| 130 const web_app::ShortcutLocations& locations, | 128 const web_app::ShortcutLocations& locations, |
| 131 std::unique_ptr<web_app::ShortcutInfo> shortcut_info) { | 129 std::unique_ptr<web_app::ShortcutInfo> shortcut_info) { |
| 132 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info); | 130 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info); |
| 133 BrowserThread::PostTask( | 131 |
| 132 auto* shortcut_info_ptr = shortcut_info.get(); | |
| 133 BrowserThread::PostTaskAndReply( | |
| 134 BrowserThread::FILE, FROM_HERE, | 134 BrowserThread::FILE, FROM_HERE, |
| 135 base::Bind( | 135 base::Bind( |
| 136 base::IgnoreResult(&web_app::internals::CreatePlatformShortcuts), | 136 base::IgnoreResult(&web_app::internals::CreatePlatformShortcuts), |
| 137 shortcut_data_dir, base::Passed(&shortcut_info), locations, reason)); | 137 shortcut_data_dir, shortcut_info_ptr, locations, reason), |
| 138 base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread, | |
| 139 base::Passed(&shortcut_info), base::Closure())); | |
| 138 } | 140 } |
| 139 | 141 |
| 140 } // namespace | 142 } // namespace |
| 141 | 143 |
| 142 namespace web_app { | 144 namespace web_app { |
| 143 | 145 |
| 144 // The following string is used to build the directory name for | 146 // The following string is used to build the directory name for |
| 145 // shortcuts to chrome applications (the kind which are installed | 147 // shortcuts to chrome applications (the kind which are installed |
| 146 // from a CRX). Application shortcuts to URLs use the {host}_{path} | 148 // from a CRX). Application shortcuts to URLs use the {host}_{path} |
| 147 // for the name of this directory. Hosts can't include an underscore. | 149 // for the name of this directory. Hosts can't include an underscore. |
| 148 // By starting this string with an underscore, we ensure that there | 150 // By starting this string with an underscore, we ensure that there |
| 149 // are no naming conflicts. | 151 // are no naming conflicts. |
| 150 static const char kCrxAppPrefix[] = "_crx_"; | 152 static const char kCrxAppPrefix[] = "_crx_"; |
| 151 | 153 |
| 152 namespace internals { | 154 namespace internals { |
| 153 | 155 |
| 154 base::FilePath GetSanitizedFileName(const base::string16& name) { | 156 base::FilePath GetSanitizedFileName(const base::string16& name) { |
| 155 #if defined(OS_WIN) | 157 #if defined(OS_WIN) |
| 156 base::string16 file_name = name; | 158 base::string16 file_name = name; |
| 157 #else | 159 #else |
| 158 std::string file_name = base::UTF16ToUTF8(name); | 160 std::string file_name = base::UTF16ToUTF8(name); |
| 159 #endif | 161 #endif |
| 160 base::i18n::ReplaceIllegalCharactersInPath(&file_name, '_'); | 162 base::i18n::ReplaceIllegalCharactersInPath(&file_name, '_'); |
| 161 return base::FilePath(file_name); | 163 return base::FilePath(file_name); |
| 162 } | 164 } |
| 163 | 165 |
| 166 void DeleteShortcutInfoOnUIThread( | |
| 167 std::unique_ptr<web_app::ShortcutInfo> shortcut_info, | |
| 168 const base::Closure& callback) { | |
| 169 shortcut_info.reset(); | |
| 170 if (callback) | |
| 171 callback.Run(); | |
| 172 } | |
| 173 | |
| 164 } // namespace internals | 174 } // namespace internals |
| 165 | 175 |
| 166 ShortcutInfo::ShortcutInfo() {} | 176 ShortcutInfo::ShortcutInfo() {} |
| 167 ShortcutInfo::~ShortcutInfo() {} | 177 ShortcutInfo::~ShortcutInfo() {} |
| 168 | 178 |
| 169 ShortcutLocations::ShortcutLocations() | 179 ShortcutLocations::ShortcutLocations() |
| 170 : on_desktop(false), | 180 : on_desktop(false), |
| 171 applications_menu_location(APP_MENU_LOCATION_NONE), | 181 applications_menu_location(APP_MENU_LOCATION_NONE), |
| 172 in_quick_launch_bar(false) { | 182 in_quick_launch_bar(false) { |
| 173 } | 183 } |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 GetShortcutInfoForApp( | 433 GetShortcutInfoForApp( |
| 424 app, profile, base::Bind(&CreateShortcutsWithInfo, reason, locations)); | 434 app, profile, base::Bind(&CreateShortcutsWithInfo, reason, locations)); |
| 425 } | 435 } |
| 426 | 436 |
| 427 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { | 437 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { |
| 428 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 438 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 429 | 439 |
| 430 std::unique_ptr<ShortcutInfo> shortcut_info( | 440 std::unique_ptr<ShortcutInfo> shortcut_info( |
| 431 ShortcutInfoForExtensionAndProfile(app, profile)); | 441 ShortcutInfoForExtensionAndProfile(app, profile)); |
| 432 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info); | 442 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info); |
| 433 BrowserThread::PostTask( | 443 auto* shortcut_info_ptr = shortcut_info.get(); |
| 444 | |
| 445 BrowserThread::PostTaskAndReply( | |
| 434 BrowserThread::FILE, FROM_HERE, | 446 BrowserThread::FILE, FROM_HERE, |
| 435 base::Bind(&web_app::internals::DeletePlatformShortcuts, | 447 base::Bind(&web_app::internals::DeletePlatformShortcuts, |
| 436 shortcut_data_dir, base::Passed(&shortcut_info))); | 448 shortcut_data_dir, shortcut_info_ptr), |
| 449 base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread, | |
| 450 base::Passed(&shortcut_info), base::Closure())); | |
| 437 } | 451 } |
| 438 | 452 |
| 439 void UpdateAllShortcuts(const base::string16& old_app_title, | 453 void UpdateAllShortcuts(const base::string16& old_app_title, |
| 440 Profile* profile, | 454 Profile* profile, |
| 441 const extensions::Extension* app, | 455 const extensions::Extension* app, |
| 442 const base::Closure& callback) { | 456 const base::Closure& callback) { |
| 443 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 457 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 444 | 458 |
| 445 GetShortcutInfoForApp( | 459 GetShortcutInfoForApp( |
| 446 app, profile, | 460 app, profile, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 | 498 |
| 485 #if defined(OS_LINUX) | 499 #if defined(OS_LINUX) |
| 486 std::string GetWMClassFromAppName(std::string app_name) { | 500 std::string GetWMClassFromAppName(std::string app_name) { |
| 487 base::i18n::ReplaceIllegalCharactersInPath(&app_name, '_'); | 501 base::i18n::ReplaceIllegalCharactersInPath(&app_name, '_'); |
| 488 base::TrimString(app_name, "_", &app_name); | 502 base::TrimString(app_name, "_", &app_name); |
| 489 return app_name; | 503 return app_name; |
| 490 } | 504 } |
| 491 #endif | 505 #endif |
| 492 | 506 |
| 493 } // namespace web_app | 507 } // namespace web_app |
| OLD | NEW |