Index: chrome/browser/extensions/app_restore_service.cc |
diff --git a/chrome/browser/extensions/app_restore_service.cc b/chrome/browser/extensions/app_restore_service.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c9afbfd8563be7d35bd13f6d14405874494ebe75 |
--- /dev/null |
+++ b/chrome/browser/extensions/app_restore_service.cc |
@@ -0,0 +1,107 @@ |
+// Copyright (c) 2012 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 "chrome/browser/extensions/app_restore_service.h" |
+ |
+#include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" |
+#include "chrome/browser/extensions/event_router.h" |
+#include "chrome/browser/extensions/extension_host.h" |
+#include "chrome/browser/extensions/extension_service.h" |
+#include "chrome/browser/extensions/extension_system.h" |
+#include "chrome/browser/prefs/pref_service.h" |
+#include "chrome/browser/prefs/scoped_user_pref_update.h" |
+#include "chrome/common/extensions/extension.h" |
+#include "chrome/common/chrome_notification_types.h" |
+#include "chrome/common/pref_names.h" |
+#include "content/public/browser/notification_details.h" |
+#include "content/public/browser/notification_service.h" |
+#include "content/public/browser/notification_types.h" |
+ |
+namespace extensions { |
+ |
+AppRestoreService::AppRestoreService(Profile* profile) |
+ : profile_(profile) { |
+ registrar_.Add( |
+ this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
+ content::NotificationService::AllSources()); |
+ registrar_.Add( |
+ this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
+ content::NotificationService::AllSources()); |
+ registrar_.Add( |
+ this, content::NOTIFICATION_APP_TERMINATING, |
+ content::NotificationService::AllSources()); |
+} |
+ |
+void AppRestoreService::RestoreApps() { |
+ PrefService* prefs = profile_->GetPrefs(); |
+ ExtensionPrefs::ExtensionIds extension_ids( |
Mihai Parparita -not on Chrome
2012/09/05 20:54:06
You can also get the list of apps from the extensi
koz (OOO until 15th September)
2012/09/06 07:50:44
Done.
|
+ ExtensionPrefs::GetExtensionsFrom(prefs)); |
+ ExtensionPrefs* extension_prefs = |
+ ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); |
+ |
+ // TODO(koz): As event dispatch occurs asynchronously the order of windows |
+ // created in response to the onRestarted event is not stable, which means |
+ // that the alt-tab order of windows won't remain constant over restarts. |
+ // This can be fixed by acking each event before dispatching the next one. |
+ for (ExtensionPrefs::ExtensionIds::const_iterator it = extension_ids.begin(); |
+ it != extension_ids.end(); it++) { |
+ if (extension_prefs->WasExtensionRunningLastSession(*it)) |
+ RestoreApp(*it); |
+ else |
+ extension_prefs->SetExtensionRunning(*it, false); |
+ } |
+} |
+ |
+void AppRestoreService::Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ switch (type) { |
+ case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { |
+ extensions::ExtensionHost* host = |
Mihai Parparita -not on Chrome
2012/09/05 20:54:06
Now that you're in the extensions namespace you ca
koz (OOO until 15th September)
2012/09/06 07:50:44
Done.
|
+ content::Details<extensions::ExtensionHost>(details).ptr(); |
+ if (host->extension()->is_platform_app()) { |
+ RecordAppStart(host->extension()->id()); |
+ } |
+ break; |
+ } |
+ |
+ case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
+ extensions::ExtensionHost* host = |
+ content::Details<extensions::ExtensionHost>(details).ptr(); |
+ if (host->extension()->is_platform_app()) { |
+ RecordAppStop(host->extension()->id()); |
+ } |
+ break; |
+ } |
+ |
+ case content::NOTIFICATION_APP_TERMINATING: { |
+ // Stop listening to NOTIFICATION_EXTENSION_HOST_DESTROYED in particular |
+ // as all extension hosts will be destroyed as a result of shutdown. |
+ registrar_.RemoveAll(); |
+ break; |
+ } |
+ } |
+} |
+ |
+ |
+void AppRestoreService::RecordAppStart(const std::string& extension_id) { |
+ ExtensionPrefs* extension_prefs = |
+ ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); |
+ extension_prefs->SetExtensionRunning(extension_id, true); |
+} |
+ |
+void AppRestoreService::RecordAppStop(const std::string& extension_id) { |
+ ExtensionPrefs* extension_prefs = |
+ ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); |
+ extension_prefs->SetExtensionRunning(extension_id, false); |
+} |
+ |
+void AppRestoreService::RestoreApp(const std::string& extension_id) { |
+ const extensions::Extension* extension = |
+ extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
+ extensions()->GetByID(extension_id); |
+ extensions::AppEventRouter::DispatchOnRestartedEvent(profile_, extension); |
+} |
+ |
+} // namespace extensions |