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

Unified Diff: apps/app_launch_on_restart_service_win.cc

Issue 12450014: Show an InfoBar when trying to start Packaged Apps from Metro mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: handle flakiness Created 7 years, 9 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: apps/app_launch_on_restart_service_win.cc
diff --git a/apps/app_launch_on_restart_service_win.cc b/apps/app_launch_on_restart_service_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ed688c415109fa9771a31c5be63c95fe3592e3b8
--- /dev/null
+++ b/apps/app_launch_on_restart_service_win.cc
@@ -0,0 +1,99 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/app_launch_on_restart_service_win.h"
+
+#include "apps/pref_names.h"
+#include "base/bind.h"
+#include "base/files/file_path.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/extension_service.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/platform_app_launcher.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "win8/util/win8_util.h"
+
+using extensions::Extension;
+using extensions::ExtensionSystem;
+
+namespace apps {
+
+namespace {
+
+void LaunchAppWithId(const base::FilePath& profile_dir,
+ const std::string& extension_id) {
+ Profile* profile =
+ g_browser_process->profile_manager()->GetProfile(profile_dir);
benwells 2013/03/18 22:16:47 Why not just send the profile to this function?
tapted 2013/03/19 02:49:05 Yeah, this might be overly paranoid. I wasn't sure
+ if (!profile)
+ return;
+
+ ExtensionService* extension_service =
+ ExtensionSystem::Get(profile)->extension_service();
+ if (!extension_service)
+ return;
+
+ const Extension* extension =
+ extension_service->GetExtensionById(extension_id, false);
+ if (!extension)
+ return;
+
+ extensions::AppEventRouter::DispatchOnLaunchedEvent(profile, extension);
+}
+
+} // namespace
+
+// static
+void AppLaunchOnRestartServiceWin::HandleStartupForProfile(Profile* profile) {
+ PrefService* prefs = g_browser_process->local_state();
+ if (!prefs->HasPrefPath(prefs::kRestartFromMetroWithProfileDir))
+ return;
+
+ base::FilePath profile_dir = base::FilePath::FromUTF8Unsafe(
+ prefs->GetString(prefs::kRestartFromMetroWithProfileDir));
+ if (profile_dir.empty() || profile->GetPath().BaseName() != profile_dir)
benwells 2013/03/18 22:16:47 Could you add a comment why we need the profiles t
tapted 2013/03/19 02:49:05 Done.
+ return;
+
+ prefs->ClearPref(prefs::kRestartFromMetroWithProfileDir);
+
+ if (!prefs->HasPrefPath(prefs::kRestartFromMetroWithAppLaunch))
+ return;
+
+ std::string extension_id =
+ prefs->GetString(prefs::kRestartFromMetroWithAppLaunch);
+ if (extension_id.empty())
+ return;
+
+ prefs->ClearPref(prefs::kRestartFromMetroWithAppLaunch);
+
+ if (win8::IsSingleWindowMetroMode()) {
tapted 2013/03/18 06:54:31 IsMetroProcess from base/win/metro.h is a feasible
+ // In this case we have relaunched with the correct profile, but we are not
+ // in Desktop mode, so can not launch apps. Leave the preferences cleared so
+ // there are no surprises later.
+ return;
+ }
+
+ const int kRestartAppLaunchDelayMs = 1000;
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&LaunchAppWithId,
+ profile->GetPath(),
+ extension_id),
+ base::TimeDelta::FromMilliseconds(kRestartAppLaunchDelayMs));
+}
+
+// static
+void AppLaunchOnRestartServiceWin::SetAppLaunchOnStartupForProfile(
+ Profile* profile, const std::string& extension_id) {
+ PrefService* prefs = g_browser_process->local_state();
+ prefs->SetString(prefs::kRestartFromMetroWithProfileDir,
+ profile->GetPath().BaseName().MaybeAsASCII());
+ prefs->SetString(prefs::kRestartFromMetroWithAppLaunch, extension_id);
+}
+
+} // namespace apps

Powered by Google App Engine
This is Rietveld 408576698