OLD | NEW |
---|---|
(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, content::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->id()); | |
Mihai Parparita -not on Chrome
2012/09/06 23:07:09
Given that RestoreApp then looks up the Extension
koz (OOO until 15th September)
2012/09/10 04:51:57
Done.
| |
48 else | |
49 extension_prefs->SetExtensionRunning(extension->id(), false); | |
Mihai Parparita -not on Chrome
2012/09/06 23:07:09
Not sure I understand the need for this. It seems
koz (OOO until 15th September)
2012/09/10 04:51:57
Oh, yeah. Silly mistake.
| |
50 } | |
51 } | |
52 | |
53 void AppRestoreService::Observe(int type, | |
54 const content::NotificationSource& source, | |
55 const content::NotificationDetails& details) { | |
56 switch (type) { | |
57 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { | |
58 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | |
59 if (host->extension()->is_platform_app()) { | |
60 RecordAppStart(host->extension()->id()); | |
61 } | |
62 break; | |
63 } | |
64 | |
65 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | |
66 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | |
67 if (host->extension()->is_platform_app()) { | |
68 RecordAppStop(host->extension()->id()); | |
69 } | |
70 break; | |
71 } | |
72 | |
73 case content::NOTIFICATION_APP_TERMINATING: { | |
74 // Stop listening to NOTIFICATION_EXTENSION_HOST_DESTROYED in particular | |
75 // as all extension hosts will be destroyed as a result of shutdown. | |
76 registrar_.RemoveAll(); | |
77 break; | |
78 } | |
79 } | |
80 } | |
81 | |
82 | |
83 void AppRestoreService::RecordAppStart(const std::string& extension_id) { | |
84 ExtensionPrefs* extension_prefs = | |
85 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); | |
86 extension_prefs->SetExtensionRunning(extension_id, true); | |
87 } | |
88 | |
89 void AppRestoreService::RecordAppStop(const std::string& extension_id) { | |
90 ExtensionPrefs* extension_prefs = | |
91 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); | |
92 extension_prefs->SetExtensionRunning(extension_id, false); | |
93 } | |
94 | |
95 void AppRestoreService::RestoreApp(const std::string& extension_id) { | |
96 const Extension* extension = ExtensionSystem::Get(profile_)-> | |
97 extension_service()->extensions()->GetByID(extension_id); | |
98 AppEventRouter::DispatchOnRestartedEvent(profile_, extension); | |
99 } | |
100 | |
101 } // namespace extensions | |
OLD | NEW |