This source file includes following definitions.
- LaunchAppWithId
- HandleAppLaunchForMetroRestart
- SetAppLaunchForMetroRestart
- RegisterPrefs
#include "chrome/browser/apps/app_launch_for_metro_restart_win.h"
#include "apps/browser/api/app_runtime/app_runtime_api.h"
#include "apps/launcher.h"
#include "apps/pref_names.h"
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
#include "extensions/browser/extension_system.h"
#include "win8/util/win8_util.h"
using extensions::Extension;
using extensions::ExtensionSystem;
namespace app_metro_launch {
namespace {
void LaunchAppWithId(Profile* profile,
const std::string& extension_id) {
ExtensionService* extension_service =
ExtensionSystem::Get(profile)->extension_service();
if (!extension_service)
return;
const Extension* extension =
extension_service->GetExtensionById(extension_id, false);
if (!extension)
return;
apps::AppEventRouter::DispatchOnLaunchedEvent(profile, extension);
}
}
void HandleAppLaunchForMetroRestart(Profile* profile) {
PrefService* prefs = g_browser_process->local_state();
if (!prefs->HasPrefPath(prefs::kAppLaunchForMetroRestartProfile))
return;
base::FilePath profile_dir = base::FilePath::FromUTF8Unsafe(
prefs->GetString(prefs::kAppLaunchForMetroRestartProfile));
if (profile_dir.empty() || profile->GetPath().BaseName() != profile_dir)
return;
prefs->ClearPref(prefs::kAppLaunchForMetroRestartProfile);
if (!prefs->HasPrefPath(prefs::kAppLaunchForMetroRestart))
return;
std::string extension_id = prefs->GetString(prefs::kAppLaunchForMetroRestart);
if (extension_id.empty())
return;
prefs->ClearPref(prefs::kAppLaunchForMetroRestart);
if (win8::IsSingleWindowMetroMode()) {
return;
}
const int kRestartAppLaunchDelayMs = 1000;
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&LaunchAppWithId, profile, extension_id),
base::TimeDelta::FromMilliseconds(kRestartAppLaunchDelayMs));
}
void SetAppLaunchForMetroRestart(Profile* profile,
const std::string& extension_id) {
PrefService* prefs = g_browser_process->local_state();
prefs->SetString(prefs::kAppLaunchForMetroRestartProfile,
profile->GetPath().BaseName().MaybeAsASCII());
prefs->SetString(prefs::kAppLaunchForMetroRestart, extension_id);
}
void RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterStringPref(prefs::kAppLaunchForMetroRestart, "");
registry->RegisterStringPref(prefs::kAppLaunchForMetroRestartProfile, "");
}
}