OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/apps/app_launch_for_metro_restart_win.h" | 5 #include "chrome/browser/apps/app_launch_for_metro_restart_win.h" |
6 | 6 |
7 #include "apps/browser/api/app_runtime/app_runtime_api.h" | 7 #include "apps/browser/api/app_runtime/app_runtime_api.h" |
8 #include "apps/launcher.h" | 8 #include "apps/launcher.h" |
9 #include "apps/pref_names.h" | 9 #include "apps/pref_names.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
21 #include "extensions/browser/extension_system.h" | 21 #include "extensions/browser/extension_system.h" |
22 #include "win8/util/win8_util.h" | |
23 | 22 |
24 using extensions::Extension; | 23 using extensions::Extension; |
25 using extensions::ExtensionSystem; | 24 using extensions::ExtensionSystem; |
26 | 25 |
27 namespace app_metro_launch { | 26 namespace app_metro_launch { |
28 | 27 |
29 namespace { | 28 namespace { |
30 | 29 |
31 void LaunchAppWithId(Profile* profile, | 30 void LaunchAppWithId(Profile* profile, |
32 const std::string& extension_id) { | 31 const std::string& extension_id) { |
(...skipping 30 matching lines...) Expand all Loading... |
63 | 62 |
64 if (!prefs->HasPrefPath(prefs::kAppLaunchForMetroRestart)) | 63 if (!prefs->HasPrefPath(prefs::kAppLaunchForMetroRestart)) |
65 return; | 64 return; |
66 | 65 |
67 std::string extension_id = prefs->GetString(prefs::kAppLaunchForMetroRestart); | 66 std::string extension_id = prefs->GetString(prefs::kAppLaunchForMetroRestart); |
68 if (extension_id.empty()) | 67 if (extension_id.empty()) |
69 return; | 68 return; |
70 | 69 |
71 prefs->ClearPref(prefs::kAppLaunchForMetroRestart); | 70 prefs->ClearPref(prefs::kAppLaunchForMetroRestart); |
72 | 71 |
73 if (win8::IsSingleWindowMetroMode()) { | |
74 // In this case we have relaunched with the correct profile, but we are not | |
75 // in Desktop mode, so can not launch apps. Leave the preferences cleared so | |
76 // there are no surprises later. | |
77 return; | |
78 } | |
79 | |
80 const int kRestartAppLaunchDelayMs = 1000; | 72 const int kRestartAppLaunchDelayMs = 1000; |
81 base::MessageLoop::current()->PostDelayedTask( | 73 base::MessageLoop::current()->PostDelayedTask( |
82 FROM_HERE, | 74 FROM_HERE, |
83 base::Bind(&LaunchAppWithId, profile, extension_id), | 75 base::Bind(&LaunchAppWithId, profile, extension_id), |
84 base::TimeDelta::FromMilliseconds(kRestartAppLaunchDelayMs)); | 76 base::TimeDelta::FromMilliseconds(kRestartAppLaunchDelayMs)); |
85 } | 77 } |
86 | 78 |
87 void SetAppLaunchForMetroRestart(Profile* profile, | 79 void SetAppLaunchForMetroRestart(Profile* profile, |
88 const std::string& extension_id) { | 80 const std::string& extension_id) { |
89 PrefService* prefs = g_browser_process->local_state(); | 81 PrefService* prefs = g_browser_process->local_state(); |
90 prefs->SetString(prefs::kAppLaunchForMetroRestartProfile, | 82 prefs->SetString(prefs::kAppLaunchForMetroRestartProfile, |
91 profile->GetPath().BaseName().MaybeAsASCII()); | 83 profile->GetPath().BaseName().MaybeAsASCII()); |
92 prefs->SetString(prefs::kAppLaunchForMetroRestart, extension_id); | 84 prefs->SetString(prefs::kAppLaunchForMetroRestart, extension_id); |
93 } | 85 } |
94 | 86 |
95 void RegisterPrefs(PrefRegistrySimple* registry) { | 87 void RegisterPrefs(PrefRegistrySimple* registry) { |
96 registry->RegisterStringPref(prefs::kAppLaunchForMetroRestart, ""); | 88 registry->RegisterStringPref(prefs::kAppLaunchForMetroRestart, ""); |
97 registry->RegisterStringPref(prefs::kAppLaunchForMetroRestartProfile, ""); | 89 registry->RegisterStringPref(prefs::kAppLaunchForMetroRestartProfile, ""); |
98 } | 90 } |
99 | 91 |
100 } // namespace app_metro_launch | 92 } // namespace app_metro_launch |
OLD | NEW |