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/chrome_notification_types.h" | |
16 #include "chrome/common/pref_names.h" | |
17 #include "content/public/browser/notification_details.h" | |
18 #include "content/public/browser/notification_service.h" | |
19 #include "content/public/browser/notification_types.h" | |
20 | |
21 namespace extensions { | |
22 | |
23 AppRestoreService::AppRestoreService(Profile* profile) | |
24 : profile_(profile) { | |
25 registrar_.Add( | |
26 this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | |
27 content::NotificationService::AllSources()); | |
28 registrar_.Add( | |
29 this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | |
30 content::NotificationService::AllSources()); | |
31 registrar_.Add( | |
32 this, content::NOTIFICATION_APP_TERMINATING, | |
33 content::NotificationService::AllSources()); | |
34 } | |
35 | |
36 void AppRestoreService::RestoreApps() { | |
37 PrefService* prefs = profile_->GetPrefs(); | |
38 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.
| |
39 ExtensionPrefs::GetExtensionsFrom(prefs)); | |
40 ExtensionPrefs* extension_prefs = | |
41 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); | |
42 | |
43 // TODO(koz): As event dispatch occurs asynchronously the order of windows | |
44 // created in response to the onRestarted event is not stable, which means | |
45 // that the alt-tab order of windows won't remain constant over restarts. | |
46 // This can be fixed by acking each event before dispatching the next one. | |
47 for (ExtensionPrefs::ExtensionIds::const_iterator it = extension_ids.begin(); | |
48 it != extension_ids.end(); it++) { | |
49 if (extension_prefs->WasExtensionRunningLastSession(*it)) | |
50 RestoreApp(*it); | |
51 else | |
52 extension_prefs->SetExtensionRunning(*it, false); | |
53 } | |
54 } | |
55 | |
56 void AppRestoreService::Observe(int type, | |
57 const content::NotificationSource& source, | |
58 const content::NotificationDetails& details) { | |
59 switch (type) { | |
60 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { | |
61 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.
| |
62 content::Details<extensions::ExtensionHost>(details).ptr(); | |
63 if (host->extension()->is_platform_app()) { | |
64 RecordAppStart(host->extension()->id()); | |
65 } | |
66 break; | |
67 } | |
68 | |
69 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | |
70 extensions::ExtensionHost* host = | |
71 content::Details<extensions::ExtensionHost>(details).ptr(); | |
72 if (host->extension()->is_platform_app()) { | |
73 RecordAppStop(host->extension()->id()); | |
74 } | |
75 break; | |
76 } | |
77 | |
78 case content::NOTIFICATION_APP_TERMINATING: { | |
79 // Stop listening to NOTIFICATION_EXTENSION_HOST_DESTROYED in particular | |
80 // as all extension hosts will be destroyed as a result of shutdown. | |
81 registrar_.RemoveAll(); | |
82 break; | |
83 } | |
84 } | |
85 } | |
86 | |
87 | |
88 void AppRestoreService::RecordAppStart(const std::string& extension_id) { | |
89 ExtensionPrefs* extension_prefs = | |
90 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); | |
91 extension_prefs->SetExtensionRunning(extension_id, true); | |
92 } | |
93 | |
94 void AppRestoreService::RecordAppStop(const std::string& extension_id) { | |
95 ExtensionPrefs* extension_prefs = | |
96 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); | |
97 extension_prefs->SetExtensionRunning(extension_id, false); | |
98 } | |
99 | |
100 void AppRestoreService::RestoreApp(const std::string& extension_id) { | |
101 const extensions::Extension* extension = | |
102 extensions::ExtensionSystem::Get(profile_)->extension_service()-> | |
103 extensions()->GetByID(extension_id); | |
104 extensions::AppEventRouter::DispatchOnRestartedEvent(profile_, extension); | |
105 } | |
106 | |
107 } // namespace extensions | |
OLD | NEW |