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

Side by Side Diff: apps/app_restore_service.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: add a 1 second delay, some nits 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "apps/app_restore_service.h" 5 #include "apps/app_restore_service.h"
6 6
7 #include "apps/pref_names.h"
8 #include "base/bind.h"
9 #include "base/message_loop.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/time.h"
12 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" 13 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h"
8 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" 14 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
9 #include "chrome/browser/extensions/event_router.h" 15 #include "chrome/browser/extensions/event_router.h"
10 #include "chrome/browser/extensions/extension_host.h" 16 #include "chrome/browser/extensions/extension_host.h"
11 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_system.h" 18 #include "chrome/browser/extensions/extension_system.h"
13 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/common/extensions/extension.h" 20 #include "chrome/common/extensions/extension.h"
15 #include "chrome/common/extensions/extension_set.h" 21 #include "chrome/common/extensions/extension_set.h"
16 #include "content/public/browser/notification_details.h" 22 #include "content/public/browser/notification_details.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 it != extensions->end(); ++it) { 54 it != extensions->end(); ++it) {
49 const Extension* extension = *it; 55 const Extension* extension = *it;
50 if (extension_prefs->IsExtensionRunning(extension->id())) { 56 if (extension_prefs->IsExtensionRunning(extension->id())) {
51 std::vector<SavedFileEntry> file_entries; 57 std::vector<SavedFileEntry> file_entries;
52 extension_prefs->GetSavedFileEntries(extension->id(), &file_entries); 58 extension_prefs->GetSavedFileEntries(extension->id(), &file_entries);
53 RecordAppStop(extension->id()); 59 RecordAppStop(extension->id());
54 if (should_restore_apps) 60 if (should_restore_apps)
55 RestoreApp(*it, file_entries); 61 RestoreApp(*it, file_entries);
56 } 62 }
57 } 63 }
64
65 MaybeHandleMetroRelaunch(extension_service);
58 } 66 }
59 67
60 void AppRestoreService::Observe(int type, 68 void AppRestoreService::Observe(int type,
61 const content::NotificationSource& source, 69 const content::NotificationSource& source,
62 const content::NotificationDetails& details) { 70 const content::NotificationDetails& details) {
63 switch (type) { 71 switch (type) {
64 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { 72 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
65 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); 73 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
66 const Extension* extension = host->extension(); 74 const Extension* extension = host->extension();
67 if (extension && extension->is_platform_app()) 75 if (extension && extension->is_platform_app())
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 extension_prefs->ClearSavedFileEntries(extension_id); 108 extension_prefs->ClearSavedFileEntries(extension_id);
101 } 109 }
102 110
103 void AppRestoreService::RestoreApp( 111 void AppRestoreService::RestoreApp(
104 const Extension* extension, 112 const Extension* extension,
105 const std::vector<SavedFileEntry>& file_entries) { 113 const std::vector<SavedFileEntry>& file_entries) {
106 // TODO(koz): Make |file_entries| available to the newly restarted app. 114 // TODO(koz): Make |file_entries| available to the newly restarted app.
107 AppEventRouter::DispatchOnRestartedEvent(profile_, extension); 115 AppEventRouter::DispatchOnRestartedEvent(profile_, extension);
108 } 116 }
109 117
118 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
119 ExtensionService* extension_service =
120 ExtensionSystem::Get(profile_)->extension_service();
121 const Extension* extension =
122 extension_service->GetExtensionById(extension_id, false);
123 // There is a possibility of the extension getting uninstalled.
124 if (!extension)
125 return;
126
127 extensions::AppEventRouter::DispatchOnLaunchedEvent(profile_, extension);
128 }
129
130 void AppRestoreService::MaybeHandleMetroRelaunch(
131 ExtensionService* extension_service) {
132 #if defined(OS_WIN)
133 const int kRestartAppLaunchDelayMs = 1000;
134 PrefService* prefs = g_browser_process->local_state();
135 if (!prefs->HasPrefPath(prefs::kRestartFromMetroWithAppLaunch))
136 return;
137
138 std::string extension_id =
139 prefs->GetString(prefs::kRestartFromMetroWithAppLaunch);
140 if (extension_id.empty())
141 return;
142
143 prefs->ClearPref(prefs::kRestartFromMetroWithAppLaunch);
144 MessageLoop::current()->PostDelayedTask(
145 FROM_HERE,
146 base::Bind(&AppRestoreService::LaunchAppWithId,
147 base::Unretained(this),
148 extension_id),
149 base::TimeDelta::FromMilliseconds(kRestartAppLaunchDelayMs));
150 #endif // defined(OS_WIN)
151 }
152
110 } // namespace apps 153 } // namespace apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698