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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 if (app_name.substr(0, prefix.length()) != prefix) | 376 if (app_name.substr(0, prefix.length()) != prefix) |
377 return std::string(); | 377 return std::string(); |
378 return app_name.substr(prefix.length()); | 378 return app_name.substr(prefix.length()); |
379 } | 379 } |
380 | 380 |
381 void CreateShortcutsWithInfo( | 381 void CreateShortcutsWithInfo( |
382 ShortcutCreationReason reason, | 382 ShortcutCreationReason reason, |
383 const ShortcutLocations& locations, | 383 const ShortcutLocations& locations, |
384 scoped_ptr<ShortcutInfo> shortcut_info, | 384 scoped_ptr<ShortcutInfo> shortcut_info, |
385 const extensions::FileHandlersInfo& file_handlers_info) { | 385 const extensions::FileHandlersInfo& file_handlers_info) { |
386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 386 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
387 | 387 |
388 // If the shortcut is for an application shortcut with the new bookmark app | 388 // If the shortcut is for an application shortcut with the new bookmark app |
389 // flow disabled, there will be no corresponding extension. | 389 // flow disabled, there will be no corresponding extension. |
390 if (!shortcut_info->extension_id.empty()) { | 390 if (!shortcut_info->extension_id.empty()) { |
391 // It's possible for the extension to be deleted before we get here. | 391 // It's possible for the extension to be deleted before we get here. |
392 // For example, creating a hosted app from a website. Double check that | 392 // For example, creating a hosted app from a website. Double check that |
393 // it still exists. | 393 // it still exists. |
394 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath( | 394 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath( |
395 shortcut_info->profile_path); | 395 shortcut_info->profile_path); |
396 if (!profile) | 396 if (!profile) |
(...skipping 15 matching lines...) Expand all Loading... |
412 scoped_ptr<ShortcutInfo> shortcut_info) { | 412 scoped_ptr<ShortcutInfo> shortcut_info) { |
413 ScheduleCreatePlatformShortcut(SHORTCUT_CREATION_AUTOMATED, locations, | 413 ScheduleCreatePlatformShortcut(SHORTCUT_CREATION_AUTOMATED, locations, |
414 shortcut_info.Pass(), | 414 shortcut_info.Pass(), |
415 extensions::FileHandlersInfo()); | 415 extensions::FileHandlersInfo()); |
416 } | 416 } |
417 | 417 |
418 void CreateShortcuts(ShortcutCreationReason reason, | 418 void CreateShortcuts(ShortcutCreationReason reason, |
419 const ShortcutLocations& locations, | 419 const ShortcutLocations& locations, |
420 Profile* profile, | 420 Profile* profile, |
421 const extensions::Extension* app) { | 421 const extensions::Extension* app) { |
422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 422 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
423 | 423 |
424 if (!ShouldCreateShortcutFor(reason, profile, app)) | 424 if (!ShouldCreateShortcutFor(reason, profile, app)) |
425 return; | 425 return; |
426 | 426 |
427 GetInfoForApp( | 427 GetInfoForApp( |
428 app, profile, base::Bind(&CreateShortcutsWithInfo, reason, locations)); | 428 app, profile, base::Bind(&CreateShortcutsWithInfo, reason, locations)); |
429 } | 429 } |
430 | 430 |
431 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { | 431 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { |
432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 432 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
433 | 433 |
434 scoped_ptr<ShortcutInfo> shortcut_info( | 434 scoped_ptr<ShortcutInfo> shortcut_info( |
435 ShortcutInfoForExtensionAndProfile(app, profile)); | 435 ShortcutInfoForExtensionAndProfile(app, profile)); |
436 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info); | 436 base::FilePath shortcut_data_dir = GetShortcutDataDir(*shortcut_info); |
437 BrowserThread::PostTask( | 437 BrowserThread::PostTask( |
438 BrowserThread::FILE, FROM_HERE, | 438 BrowserThread::FILE, FROM_HERE, |
439 base::Bind(&web_app::internals::DeletePlatformShortcuts, | 439 base::Bind(&web_app::internals::DeletePlatformShortcuts, |
440 shortcut_data_dir, base::Passed(&shortcut_info))); | 440 shortcut_data_dir, base::Passed(&shortcut_info))); |
441 } | 441 } |
442 | 442 |
443 void UpdateAllShortcuts(const base::string16& old_app_title, | 443 void UpdateAllShortcuts(const base::string16& old_app_title, |
444 Profile* profile, | 444 Profile* profile, |
445 const extensions::Extension* app) { | 445 const extensions::Extension* app) { |
446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 446 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
447 | 447 |
448 GetInfoForApp(app, | 448 GetInfoForApp(app, |
449 profile, | 449 profile, |
450 base::Bind(&UpdateAllShortcutsForShortcutInfo, old_app_title)); | 450 base::Bind(&UpdateAllShortcutsForShortcutInfo, old_app_title)); |
451 } | 451 } |
452 | 452 |
453 bool IsValidUrl(const GURL& url) { | 453 bool IsValidUrl(const GURL& url) { |
454 static const char* const kValidUrlSchemes[] = { | 454 static const char* const kValidUrlSchemes[] = { |
455 url::kFileScheme, | 455 url::kFileScheme, |
456 url::kFileSystemScheme, | 456 url::kFileSystemScheme, |
(...skipping 30 matching lines...) Expand all Loading... |
487 | 487 |
488 #if defined(OS_LINUX) | 488 #if defined(OS_LINUX) |
489 std::string GetWMClassFromAppName(std::string app_name) { | 489 std::string GetWMClassFromAppName(std::string app_name) { |
490 base::i18n::ReplaceIllegalCharactersInPath(&app_name, '_'); | 490 base::i18n::ReplaceIllegalCharactersInPath(&app_name, '_'); |
491 base::TrimString(app_name, "_", &app_name); | 491 base::TrimString(app_name, "_", &app_name); |
492 return app_name; | 492 return app_name; |
493 } | 493 } |
494 #endif | 494 #endif |
495 | 495 |
496 } // namespace web_app | 496 } // namespace web_app |
OLD | NEW |