summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/shortcut_manager.cc34
-rw-r--r--apps/shortcut_manager.h9
2 files changed, 41 insertions, 2 deletions
diff --git a/apps/shortcut_manager.cc b/apps/shortcut_manager.cc
index a3629d4..d03cf5ca 100644
--- a/apps/shortcut_manager.cc
+++ b/apps/shortcut_manager.cc
@@ -11,15 +11,19 @@
#include "base/prefs/pref_service.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_info_cache.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/web_applications/web_app_ui.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_set.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
@@ -50,6 +54,7 @@ namespace apps {
ShortcutManager::ShortcutManager(Profile* profile)
: profile_(profile),
+ is_profile_info_cache_observer_(false),
prefs_(profile->GetPrefs()),
weak_factory_(this) {
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
@@ -59,9 +64,26 @@ ShortcutManager::ShortcutManager(Profile* profile)
// Wait for extensions to be ready before running OnceOffCreateShortcuts.
registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
content::Source<Profile>(profile_));
+
+ // TODO(mgiuca): This use of g_browser_process should be DCHECKed for
+ // content::BrowserThread::CurrentlyOn(content::BrowserThread::UI). This check
+ // currently fails browser_tests, due to http://crbug.com/251191.
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ // profile_manager might be NULL in testing environments.
+ if (profile_manager) {
+ profile_manager->GetProfileInfoCache().AddObserver(this);
+ is_profile_info_cache_observer_ = true;
+ }
}
-ShortcutManager::~ShortcutManager() {}
+ShortcutManager::~ShortcutManager() {
+ if (g_browser_process && is_profile_info_cache_observer_) {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ // profile_manager might be NULL in testing environments or during shutdown.
+ if (profile_manager)
+ profile_manager->GetProfileInfoCache().RemoveObserver(this);
+ }
+}
void ShortcutManager::Observe(int type,
const content::NotificationSource& source,
@@ -112,6 +134,16 @@ void ShortcutManager::Observe(int type,
}
}
+void ShortcutManager::OnProfileWillBeRemoved(
+ const base::FilePath& profile_path) {
+ if (profile_path != profile_->GetPath())
+ return;
+ content::BrowserThread::PostTask(
+ content::BrowserThread::FILE, FROM_HERE,
+ base::Bind(&web_app::internals::DeleteAllShortcutsForProfile,
+ profile_path));
+}
+
void ShortcutManager::OnceOffCreateShortcuts() {
bool was_enabled = prefs_->GetBoolean(apps::prefs::kShortcutsHaveBeenCreated);
diff --git a/apps/shortcut_manager.h b/apps/shortcut_manager.h
index b654053..408802a 100644
--- a/apps/shortcut_manager.h
+++ b/apps/shortcut_manager.h
@@ -6,6 +6,7 @@
#define APPS_SHORTCUT_MANAGER_H_
#include "base/memory/weak_ptr.h"
+#include "chrome/browser/profiles/profile_info_cache_observer.h"
#include "chrome/common/extensions/extension.h"
#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
#include "content/public/browser/notification_observer.h"
@@ -18,7 +19,8 @@ namespace apps {
// This class manages the installation of shortcuts for platform apps.
class ShortcutManager : public BrowserContextKeyedService,
- public content::NotificationObserver {
+ public content::NotificationObserver,
+ public ProfileInfoCacheObserver {
public:
explicit ShortcutManager(Profile* profile);
@@ -29,6 +31,10 @@ class ShortcutManager : public BrowserContextKeyedService,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
+ // ProfileInfoCacheObserver
+ virtual void OnProfileWillBeRemoved(
+ const base::FilePath& profile_path) OVERRIDE;
+
private:
// Checks if kShortcutsEnabled is set in prefs. If not, this sets it and
// creates shortcuts for all apps.
@@ -38,6 +44,7 @@ class ShortcutManager : public BrowserContextKeyedService,
content::NotificationRegistrar registrar_;
Profile* profile_;
+ bool is_profile_info_cache_observer_;
PrefService* prefs_;
// Fields used when installing application shortcuts.