This source file includes following definitions.
- ShouldRestoreApps
- HandleStartup
- IsAppRestorable
- Get
- OnAppStart
- OnAppActivated
- OnAppDeactivated
- OnAppStop
- OnChromeTerminating
- Shutdown
- RecordAppStart
- RecordAppStop
- RecordAppActiveState
- RestoreApp
- StartObservingAppLifetime
- StopObservingAppLifetime
#include "apps/app_restore_service.h"
#include "apps/app_lifetime_monitor_factory.h"
#include "apps/app_restore_service_factory.h"
#include "apps/app_window.h"
#include "apps/browser/api/app_runtime/app_runtime_api.h"
#include "apps/launcher.h"
#include "apps/saved_files_service.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#if defined(OS_WIN)
#include "win8/util/win8_util.h"
#endif
using extensions::Extension;
using extensions::ExtensionHost;
using extensions::ExtensionPrefs;
using extensions::ExtensionRegistry;
namespace apps {
bool AppRestoreService::ShouldRestoreApps(bool is_browser_restart) {
bool should_restore_apps = is_browser_restart;
#if defined(OS_CHROMEOS)
should_restore_apps = true;
#elif defined(OS_WIN)
if (win8::IsSingleWindowMetroMode())
should_restore_apps = false;
#endif
return should_restore_apps;
}
AppRestoreService::AppRestoreService(Profile* profile)
: profile_(profile) {
StartObservingAppLifetime();
}
void AppRestoreService::HandleStartup(bool should_restore_apps) {
const extensions::ExtensionSet& extensions =
ExtensionRegistry::Get(profile_)->enabled_extensions();
ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_);
for (extensions::ExtensionSet::const_iterator it = extensions.begin();
it != extensions.end(); ++it) {
const Extension* extension = it->get();
if (extension_prefs->IsExtensionRunning(extension->id())) {
RecordAppStop(extension->id());
if (should_restore_apps) {
RestoreApp(it->get());
} else {
SavedFilesService::Get(profile_)->ClearQueueIfNoRetainPermission(
extension);
}
}
}
}
bool AppRestoreService::IsAppRestorable(const std::string& extension_id) {
return ExtensionPrefs::Get(profile_)->IsExtensionRunning(extension_id);
}
AppRestoreService* AppRestoreService::Get(Profile* profile) {
return apps::AppRestoreServiceFactory::GetForProfile(profile);
}
void AppRestoreService::OnAppStart(Profile* profile,
const std::string& app_id) {
RecordAppStart(app_id);
}
void AppRestoreService::OnAppActivated(Profile* profile,
const std::string& app_id) {
RecordAppActiveState(app_id, true);
}
void AppRestoreService::OnAppDeactivated(Profile* profile,
const std::string& app_id) {
RecordAppActiveState(app_id, false);
}
void AppRestoreService::OnAppStop(Profile* profile, const std::string& app_id) {
RecordAppStop(app_id);
}
void AppRestoreService::OnChromeTerminating() {
StopObservingAppLifetime();
}
void AppRestoreService::Shutdown() {
StopObservingAppLifetime();
}
void AppRestoreService::RecordAppStart(const std::string& extension_id) {
ExtensionPrefs::Get(profile_)->SetExtensionRunning(extension_id, true);
}
void AppRestoreService::RecordAppStop(const std::string& extension_id) {
ExtensionPrefs::Get(profile_)->SetExtensionRunning(extension_id, false);
}
void AppRestoreService::RecordAppActiveState(const std::string& id,
bool is_active) {
ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_);
if (!extension_prefs->IsExtensionRunning(id))
return;
extension_prefs->SetIsActive(id, is_active);
}
void AppRestoreService::RestoreApp(const Extension* extension) {
RestartPlatformApp(profile_, extension);
}
void AppRestoreService::StartObservingAppLifetime() {
AppLifetimeMonitor* app_lifetime_monitor =
AppLifetimeMonitorFactory::GetForProfile(profile_);
DCHECK(app_lifetime_monitor);
app_lifetime_monitor->AddObserver(this);
}
void AppRestoreService::StopObservingAppLifetime() {
AppLifetimeMonitor* app_lifetime_monitor =
AppLifetimeMonitorFactory::GetForProfile(profile_);
if (app_lifetime_monitor)
app_lifetime_monitor->RemoveObserver(this);
}
}