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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "apps/app_launch_on_restart_service_win.h"
6
7 #include "apps/pref_names.h"
8 #include "base/bind.h"
9 #include "base/files/file_path.h"
10 #include "base/message_loop.h"
11 #include "base/prefs/pref_service.h"
12 #include "base/time.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h"
15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/extension_system.h"
17 #include "chrome/browser/extensions/platform_app_launcher.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_manager.h"
20 #include "win8/util/win8_util.h"
21
22 using extensions::Extension;
23 using extensions::ExtensionSystem;
24
25 namespace apps {
26
27 namespace {
28
29 void LaunchAppWithId(const base::FilePath& profile_dir,
30 const std::string& extension_id) {
31 Profile* profile =
32 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
33 if (!profile)
34 return;
35
36 ExtensionService* extension_service =
37 ExtensionSystem::Get(profile)->extension_service();
38 if (!extension_service)
39 return;
40
41 const Extension* extension =
42 extension_service->GetExtensionById(extension_id, false);
43 if (!extension)
44 return;
45
46 extensions::AppEventRouter::DispatchOnLaunchedEvent(profile, extension);
47 }
48
49 } // namespace
50
51 // static
52 void AppLaunchOnRestartServiceWin::HandleStartupForProfile(Profile* profile) {
53 PrefService* prefs = g_browser_process->local_state();
54 if (!prefs->HasPrefPath(prefs::kRestartFromMetroWithProfileDir))
55 return;
56
57 base::FilePath profile_dir = base::FilePath::FromUTF8Unsafe(
58 prefs->GetString(prefs::kRestartFromMetroWithProfileDir));
59 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.
60 return;
61
62 prefs->ClearPref(prefs::kRestartFromMetroWithProfileDir);
63
64 if (!prefs->HasPrefPath(prefs::kRestartFromMetroWithAppLaunch))
65 return;
66
67 std::string extension_id =
68 prefs->GetString(prefs::kRestartFromMetroWithAppLaunch);
69 if (extension_id.empty())
70 return;
71
72 prefs->ClearPref(prefs::kRestartFromMetroWithAppLaunch);
73
74 if (win8::IsSingleWindowMetroMode()) {
tapted 2013/03/18 06:54:31 IsMetroProcess from base/win/metro.h is a feasible
75 // In this case we have relaunched with the correct profile, but we are not
76 // in Desktop mode, so can not launch apps. Leave the preferences cleared so
77 // there are no surprises later.
78 return;
79 }
80
81 const int kRestartAppLaunchDelayMs = 1000;
82 MessageLoop::current()->PostDelayedTask(
83 FROM_HERE,
84 base::Bind(&LaunchAppWithId,
85 profile->GetPath(),
86 extension_id),
87 base::TimeDelta::FromMilliseconds(kRestartAppLaunchDelayMs));
88 }
89
90 // static
91 void AppLaunchOnRestartServiceWin::SetAppLaunchOnStartupForProfile(
92 Profile* profile, const std::string& extension_id) {
93 PrefService* prefs = g_browser_process->local_state();
94 prefs->SetString(prefs::kRestartFromMetroWithProfileDir,
95 profile->GetPath().BaseName().MaybeAsASCII());
96 prefs->SetString(prefs::kRestartFromMetroWithAppLaunch, extension_id);
97 }
98
99 } // namespace apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698