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

Side by Side Diff: chrome/browser/extensions/app_restore_service.cc

Issue 10875027: Restart running apps when chrome restarts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/app_restore_service.h"
6
7 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h"
8 #include "chrome/browser/extensions/event_router.h"
9 #include "chrome/browser/extensions/extension_host.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/prefs/scoped_user_pref_update.h"
14 #include "chrome/common/extensions/extension.h"
15 #include "chrome/common/extensions/extension_set.h"
16 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/pref_names.h"
18 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_types.h"
21
22 namespace extensions {
23
24 AppRestoreService::AppRestoreService(Profile* profile)
25 : profile_(profile) {
26 registrar_.Add(
27 this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
28 content::NotificationService::AllSources());
29 registrar_.Add(
30 this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
31 content::NotificationService::AllSources());
32 registrar_.Add(
33 this, chrome::NOTIFICATION_APP_TERMINATING,
34 content::NotificationService::AllSources());
35 }
36
37 void AppRestoreService::RestoreApps() {
38 ExtensionService* extension_service =
39 ExtensionSystem::Get(profile_)->extension_service();
40 const ExtensionSet* extensions = extension_service->extensions();
41 ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
42
43 for (ExtensionSet::const_iterator it = extensions->begin();
44 it != extensions->end(); ++it) {
45 const Extension* extension = *it;
46 if (extension_prefs->IsExtensionRunning(extension->id()))
47 RestoreApp(extension);
48 }
49 }
50
51 void AppRestoreService::Observe(int type,
52 const content::NotificationSource& source,
53 const content::NotificationDetails& details) {
54 switch (type) {
55 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
56 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
57 if (host->extension()->is_platform_app()) {
58 RecordAppStart(host->extension()->id());
59 }
60 break;
61 }
62
63 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
64 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
65 if (host->extension()->is_platform_app()) {
66 RecordAppStop(host->extension()->id());
67 }
68 break;
69 }
70
71 case chrome::NOTIFICATION_APP_TERMINATING: {
72 // Stop listening to NOTIFICATION_EXTENSION_HOST_DESTROYED in particular
73 // as all extension hosts will be destroyed as a result of shutdown.
74 registrar_.RemoveAll();
75 break;
76 }
77 }
78 }
79
80
81 void AppRestoreService::RecordAppStart(const std::string& extension_id) {
82 ExtensionPrefs* extension_prefs =
83 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs();
84 extension_prefs->SetExtensionRunning(extension_id, true);
85 }
86
87 void AppRestoreService::RecordAppStop(const std::string& extension_id) {
88 ExtensionPrefs* extension_prefs =
89 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs();
90 extension_prefs->SetExtensionRunning(extension_id, false);
91 }
92
93 void AppRestoreService::RestoreApp(const Extension* extension) {
94 AppEventRouter::DispatchOnRestartedEvent(profile_, extension);
95 }
96
97 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/app_restore_service.h ('k') | chrome/browser/extensions/app_restore_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698