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

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

Issue 263403002: Replace OnceOffCreateShortcuts with UpdateShortcutsForAllAppsIfNeeded. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove CallForProfileAndAppId, change Mac implementation to Update instead of Create Created 6 years, 6 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 | Annotate | Revision Log
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/i18n/file_util_icu.h" 10 #include "base/i18n/file_util_icu.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "chrome/browser/extensions/extension_ui_util.h"
15 #include "chrome/browser/extensions/image_loader.h" 16 #include "chrome/browser/extensions/image_loader.h"
16 #include "chrome/browser/extensions/tab_helper.h" 17 #include "chrome/browser/extensions/tab_helper.h"
17 #include "chrome/browser/favicon/favicon_tab_helper.h" 18 #include "chrome/browser/favicon/favicon_tab_helper.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/chrome_constants.h" 20 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/chrome_version_info.h" 21 #include "chrome/common/chrome_version_info.h"
21 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 22 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
23 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
25 #include "extensions/browser/extension_registry.h"
24 #include "extensions/common/constants.h" 26 #include "extensions/common/constants.h"
25 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
28 #include "extensions/common/extension_set.h"
26 #include "extensions/common/manifest_handlers/icons_handler.h" 29 #include "extensions/common/manifest_handlers/icons_handler.h"
27 #include "grit/theme_resources.h" 30 #include "grit/theme_resources.h"
28 #include "skia/ext/image_operations.h" 31 #include "skia/ext/image_operations.h"
29 #include "third_party/skia/include/core/SkBitmap.h" 32 #include "third_party/skia/include/core/SkBitmap.h"
30 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/gfx/image/image.h" 34 #include "ui/gfx/image/image.h"
32 #include "ui/gfx/image/image_family.h" 35 #include "ui/gfx/image/image_family.h"
33 #include "ui/gfx/image/image_skia.h" 36 #include "ui/gfx/image/image_skia.h"
34 #include "url/url_constants.h" 37 #include "url/url_constants.h"
35 38
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return left.width < right.width; 70 return left.width < right.width;
68 } 71 }
69 #endif 72 #endif
70 73
71 base::FilePath GetShortcutDataDir(const web_app::ShortcutInfo& shortcut_info) { 74 base::FilePath GetShortcutDataDir(const web_app::ShortcutInfo& shortcut_info) {
72 return web_app::GetWebAppDataDirectory(shortcut_info.profile_path, 75 return web_app::GetWebAppDataDirectory(shortcut_info.profile_path,
73 shortcut_info.extension_id, 76 shortcut_info.extension_id,
74 shortcut_info.url); 77 shortcut_info.url);
75 } 78 }
76 79
80 bool ShouldCreateShortcutFor(Profile* profile,
81 const extensions::Extension* extension) {
82 return extension->is_platform_app() &&
83 extension->location() != extensions::Manifest::COMPONENT &&
84 extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile);
85 }
86
77 void CreateShortcutsWithInfo( 87 void CreateShortcutsWithInfo(
78 web_app::ShortcutCreationReason reason, 88 web_app::ShortcutCreationReason reason,
79 const web_app::ShortcutLocations& locations, 89 const web_app::ShortcutLocations& locations,
80 const web_app::ShortcutInfo& shortcut_info, 90 const web_app::ShortcutInfo& shortcut_info,
81 const extensions::FileHandlersInfo& file_handlers_info) { 91 const extensions::FileHandlersInfo& file_handlers_info) {
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
83 93
84 BrowserThread::PostTask( 94 BrowserThread::PostTask(
85 BrowserThread::FILE, 95 BrowserThread::FILE,
86 FROM_HERE, 96 FROM_HERE,
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 base::IgnoreResult(&web_app::internals::CreateShortcutsOnFileThread), 377 base::IgnoreResult(&web_app::internals::CreateShortcutsOnFileThread),
368 reason, locations, shortcut_info)); 378 reason, locations, shortcut_info));
369 } 379 }
370 380
371 void CreateShortcuts(ShortcutCreationReason reason, 381 void CreateShortcuts(ShortcutCreationReason reason,
372 const ShortcutLocations& locations, 382 const ShortcutLocations& locations,
373 Profile* profile, 383 Profile* profile,
374 const extensions::Extension* app) { 384 const extensions::Extension* app) {
375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
376 386
387 if (!ShouldCreateShortcutFor(profile, app))
388 return;
389
377 GetInfoForApp(app, 390 GetInfoForApp(app,
378 profile, 391 profile,
379 base::Bind(&CreateShortcutsWithInfo, reason, locations)); 392 base::Bind(&CreateShortcutsWithInfo, reason, locations));
380 } 393 }
381 394
382 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { 395 void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) {
383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
384 397
385 ShortcutInfo shortcut_info = 398 ShortcutInfo shortcut_info =
386 ShortcutInfoForExtensionAndProfile(app, profile); 399 ShortcutInfoForExtensionAndProfile(app, profile);
387 BrowserThread::PostTask( 400 BrowserThread::PostTask(
388 BrowserThread::FILE, 401 BrowserThread::FILE,
389 FROM_HERE, 402 FROM_HERE,
390 base::Bind(&web_app::internals::DeletePlatformShortcuts, 403 base::Bind(&web_app::internals::DeletePlatformShortcuts,
391 GetShortcutDataDir(shortcut_info), shortcut_info)); 404 GetShortcutDataDir(shortcut_info), shortcut_info));
392 } 405 }
393 406
394 void UpdateAllShortcuts(const base::string16& old_app_title, 407 void UpdateAllShortcuts(const base::string16& old_app_title,
395 Profile* profile, 408 Profile* profile,
396 const extensions::Extension* app) { 409 const extensions::Extension* app) {
397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
398 411
399 GetInfoForApp(app, 412 GetInfoForApp(app,
400 profile, 413 profile,
401 base::Bind(&UpdateAllShortcutsForShortcutInfo, old_app_title)); 414 base::Bind(&UpdateAllShortcutsForShortcutInfo, old_app_title));
402 } 415 }
403 416
417 void UpdateShortcutsForAllApps(Profile* profile) {
418 extensions::ExtensionRegistry* registry =
419 extensions::ExtensionRegistry::Get(profile);
420 if (!registry)
421 return;
422
423 // Get a set of app ids.
424 scoped_ptr<extensions::ExtensionSet> everything =
425 registry->GenerateInstalledExtensionsSet();
426 std::set<std::string> app_ids;
427 for (extensions::ExtensionSet::const_iterator it = everything->begin();
428 it != everything->end(); ++it) {
429 if (ShouldCreateShortcutFor(profile, it->get()))
430 app_ids.insert((*it)->id());
tapted 2014/05/30 06:33:27 Why not just call web_app::UpdateAllShortcuts(bas
jackhou1 2014/06/02 04:25:19 Yeah, I agree with making this simpler until we ac
431 }
432
433 BrowserThread::PostTask(
434 BrowserThread::FILE,
435 FROM_HERE,
436 base::Bind(
437 &web_app::internals::UpdateShortcutsForAllAppsForProfile,
438 profile->GetPath(), app_ids));
439 }
440
404 bool IsValidUrl(const GURL& url) { 441 bool IsValidUrl(const GURL& url) {
405 static const char* const kValidUrlSchemes[] = { 442 static const char* const kValidUrlSchemes[] = {
406 url::kFileScheme, 443 url::kFileScheme,
407 url::kFileSystemScheme, 444 url::kFileSystemScheme,
408 url::kFtpScheme, 445 url::kFtpScheme,
409 url::kHttpScheme, 446 url::kHttpScheme,
410 url::kHttpsScheme, 447 url::kHttpsScheme,
411 extensions::kExtensionScheme, 448 extensions::kExtensionScheme,
412 }; 449 };
413 450
(...skipping 24 matching lines...) Expand all
438 475
439 #if defined(OS_LINUX) 476 #if defined(OS_LINUX)
440 std::string GetWMClassFromAppName(std::string app_name) { 477 std::string GetWMClassFromAppName(std::string app_name) {
441 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); 478 file_util::ReplaceIllegalCharactersInPath(&app_name, '_');
442 base::TrimString(app_name, "_", &app_name); 479 base::TrimString(app_name, "_", &app_name);
443 return app_name; 480 return app_name;
444 } 481 }
445 #endif 482 #endif
446 483
447 } // namespace web_app 484 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698