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

Unified 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: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/web_applications/web_app.cc
diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc
index 313e261886555939c2a2b6fec826a81f97149743..612c5fc3b096b2b11d5a65fba667c6d3cc277bf9 100644
--- a/chrome/browser/web_applications/web_app.cc
+++ b/chrome/browser/web_applications/web_app.cc
@@ -12,10 +12,13 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/image_loader.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/extensions/api/file_handlers/file_handlers_parser.h"
@@ -23,8 +26,11 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/browser/extension_system.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
+#include "extensions/common/extension_set.h"
#include "extensions/common/manifest_handlers/icons_handler.h"
#include "grit/theme_resources.h"
#include "skia/ext/image_operations.h"
@@ -69,6 +75,12 @@ bool IconPrecedes(const WebApplicationInfo::IconInfo& left,
}
#endif
+bool ShouldCreateShortcutFor(const extensions::Extension* extension) {
+ return extension->is_platform_app() &&
+ extension->location() != extensions::Manifest::COMPONENT &&
+ extension->ShouldDisplayInAppLauncher();
+}
+
bool CreateShortcutsWithInfoOnFileThread(
web_app::ShortcutCreationReason reason,
const web_app::ShortcutLocations& locations,
@@ -234,6 +246,25 @@ static const char* kCrxAppPrefix = "_crx_";
namespace internals {
+void CallForProfileAndAppId(
+ const base::FilePath& profile_path,
+ const std::string app_id,
+ const ShortcutOperationCallback& callback) {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ Profile* profile = profile_manager->GetProfileByPath(profile_path);
+ if (!profile || !profile_manager->IsValidProfile(profile))
+ return;
+
+ extensions::ExtensionRegistry* registry =
+ extensions::ExtensionRegistry::Get(profile);
+ const extensions::Extension* extension = registry->GetExtensionById(
+ app_id, extensions::ExtensionRegistry::ENABLED);
+ if (!extension || !extension->is_platform_app())
+ return;
+
+ callback.Run(profile, extension);
+}
+
base::FilePath GetSanitizedFileName(const base::string16& name) {
#if defined(OS_WIN)
base::string16 file_name = name;
@@ -254,6 +285,29 @@ bool CreateShortcutsOnFileThread(
reason, locations, shortcut_info, extensions::FileHandlersInfo());
}
+void UpdateShortcutsForAllAppsForProfile(const base::FilePath& profile_path,
+ const std::set<std::string>& app_ids) {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
calamity 2014/05/07 06:00:19 Why does this need to be on the FILE thread? Can y
jackhou1 2014/05/22 05:26:47 This is where we'll scan for shortcuts and decide
+ web_app::ShortcutLocations creation_locations;
+ // Create the shortcut in the Chrome Apps subdir.
+ creation_locations.applications_menu_location =
+ web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS;
+
+ for (std::set<std::string>::const_iterator it = app_ids.begin();
+ it != app_ids.end();
+ ++it) {
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&web_app::internals::CallForProfileAndAppId,
+ profile_path,
+ *it,
+ base::Bind(&web_app::CreateShortcuts,
+ web_app::SHORTCUT_CREATION_AUTOMATED,
+ creation_locations)));
+ }
+}
+
} // namespace internals
web_app::ShortcutInfo::ShortcutInfo()
@@ -412,6 +466,9 @@ void CreateShortcuts(
const extensions::Extension* app) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!ShouldCreateShortcutFor(app))
+ return;
+
GetInfoForApp(app,
profile,
base::Bind(&CreateShortcutsWithInfo, reason, locations));
@@ -437,6 +494,32 @@ void UpdateAllShortcuts(const base::string16& old_app_title,
base::Bind(&UpdateAllShortcutsForShortcutInfo, old_app_title));
}
+void UpdateShortcutsForAllApps(Profile* profile) {
+ // Check if extension system/service are available. They might not be in
+ // tests.
+ extensions::ExtensionSystem* extension_system;
+ ExtensionServiceInterface* extension_service;
+ if (!(extension_system = extensions::ExtensionSystem::Get(profile)) ||
+ !(extension_service = extension_system->extension_service()))
+ return;
+
+ // Get a set of app ids.
+ const extensions::ExtensionSet* apps = extension_service->extensions();
+ std::set<std::string> app_ids;
+ for (extensions::ExtensionSet::const_iterator it = apps->begin();
+ it != apps->end(); ++it) {
+ if (ShouldCreateShortcutFor(it->get()))
+ app_ids.insert((*it)->id());
+ }
+
+ BrowserThread::PostTask(
+ BrowserThread::FILE,
+ FROM_HERE,
+ base::Bind(
+ &web_app::internals::UpdateShortcutsForAllAppsForProfile,
+ profile->GetPath(), app_ids));
+}
+
bool IsValidUrl(const GURL& url) {
static const char* const kValidUrlSchemes[] = {
content::kFileScheme,

Powered by Google App Engine
This is Rietveld 408576698