Index: apps/app_restore_service.cc |
diff --git a/apps/app_restore_service.cc b/apps/app_restore_service.cc |
index f1b3fd3801998ef13600d1afa24fd36a67015d20..c669616eef7057df61b60419782eee15313fd5cc 100644 |
--- a/apps/app_restore_service.cc |
+++ b/apps/app_restore_service.cc |
@@ -4,6 +4,12 @@ |
#include "apps/app_restore_service.h" |
+#include "apps/pref_names.h" |
+#include "base/bind.h" |
+#include "base/message_loop.h" |
+#include "base/prefs/pref_service.h" |
+#include "base/time.h" |
+#include "chrome/browser/browser_process.h" |
#include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" |
#include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
#include "chrome/browser/extensions/event_router.h" |
@@ -55,6 +61,8 @@ void AppRestoreService::HandleStartup(bool should_restore_apps) { |
RestoreApp(*it, file_entries); |
} |
} |
+ |
+ MaybeHandleMetroRelaunch(extension_service); |
} |
void AppRestoreService::Observe(int type, |
@@ -107,4 +115,39 @@ void AppRestoreService::RestoreApp( |
AppEventRouter::DispatchOnRestartedEvent(profile_, extension); |
} |
+void AppRestoreService::LaunchAppWithId(const std::string& extension_id) { |
benwells
2013/03/15 00:39:04
I would prefer all this in a different PKS dedicat
tapted
2013/03/15 00:51:16
I'll try that out.
Although I think the #if is st
|
+ ExtensionService* extension_service = |
+ ExtensionSystem::Get(profile_)->extension_service(); |
+ const Extension* extension = |
+ extension_service->GetExtensionById(extension_id, false); |
+ // There is a possibility of the extension getting uninstalled. |
+ if (!extension) |
+ return; |
+ |
+ extensions::AppEventRouter::DispatchOnLaunchedEvent(profile_, extension); |
+} |
+ |
+void AppRestoreService::MaybeHandleMetroRelaunch( |
+ ExtensionService* extension_service) { |
+#if defined(OS_WIN) |
+ const int kRestartAppLaunchDelayMs = 1000; |
+ PrefService* prefs = g_browser_process->local_state(); |
+ if (!prefs->HasPrefPath(prefs::kRestartFromMetroWithAppLaunch)) |
+ return; |
+ |
+ std::string extension_id = |
+ prefs->GetString(prefs::kRestartFromMetroWithAppLaunch); |
+ if (extension_id.empty()) |
+ return; |
+ |
+ prefs->ClearPref(prefs::kRestartFromMetroWithAppLaunch); |
+ MessageLoop::current()->PostDelayedTask( |
+ FROM_HERE, |
+ base::Bind(&AppRestoreService::LaunchAppWithId, |
+ base::Unretained(this), |
+ extension_id), |
+ base::TimeDelta::FromMilliseconds(kRestartAppLaunchDelayMs)); |
+#endif // defined(OS_WIN) |
+} |
+ |
} // namespace apps |