OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_load_service.h" | 5 #include "apps/app_load_service.h" |
6 | 6 |
7 #include "apps/app_load_service_factory.h" | 7 #include "apps/app_load_service_factory.h" |
8 #include "apps/app_restore_service.h" | 8 #include "apps/app_restore_service.h" |
9 #include "apps/app_window_registry.h" | 9 #include "apps/app_window_registry.h" |
10 #include "apps/launcher.h" | 10 #include "apps/launcher.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/unpacked_installer.h" | 12 #include "chrome/browser/extensions/unpacked_installer.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
17 #include "extensions/browser/extension_host.h" | 17 #include "extensions/browser/extension_host.h" |
18 #include "extensions/browser/extension_prefs.h" | 18 #include "extensions/browser/extension_prefs.h" |
19 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_system.h" |
20 #include "extensions/browser/notification_types.h" | 20 #include "extensions/browser/notification_types.h" |
21 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
22 #include "extensions/browser/extension_registry.h" | |
22 | 23 |
23 using extensions::Extension; | 24 using extensions::Extension; |
24 using extensions::ExtensionPrefs; | 25 using extensions::ExtensionPrefs; |
25 using extensions::ExtensionSystem; | 26 using extensions::ExtensionSystem; |
26 | 27 |
27 namespace apps { | 28 namespace apps { |
28 | 29 |
29 AppLoadService::PostReloadAction::PostReloadAction() | 30 AppLoadService::PostReloadAction::PostReloadAction() |
30 : action_type(LAUNCH), | 31 : action_type(LAUNCH), |
31 command_line(CommandLine::NO_PROGRAM) { | 32 command_line(CommandLine::NO_PROGRAM) { |
32 } | 33 } |
33 | 34 |
34 AppLoadService::AppLoadService(Profile* profile) | 35 AppLoadService::AppLoadService(Profile* profile) |
35 : profile_(profile) { | 36 : profile_(profile), extension_registry_observer_(this) { |
36 registrar_.Add(this, | 37 registrar_.Add(this, |
37 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 38 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
38 content::NotificationService::AllSources()); | 39 content::NotificationService::AllSources()); |
39 registrar_.Add(this, | 40 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); |
40 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
41 content::NotificationService::AllSources()); | |
42 } | 41 } |
43 | 42 |
44 AppLoadService::~AppLoadService() {} | 43 AppLoadService::~AppLoadService() {} |
tapted
2014/08/04 07:05:37
This class is simple enough to just put
extension
limasdf
2014/08/04 07:30:35
Done.
| |
45 | 44 |
46 void AppLoadService::RestartApplication(const std::string& extension_id) { | 45 void AppLoadService::RestartApplication(const std::string& extension_id) { |
47 post_reload_actions_[extension_id].action_type = RESTART; | 46 post_reload_actions_[extension_id].action_type = RESTART; |
48 ExtensionService* service = extensions::ExtensionSystem::Get(profile_)-> | 47 ExtensionService* service = extensions::ExtensionSystem::Get(profile_)-> |
49 extension_service(); | 48 extension_service(); |
50 DCHECK(service); | 49 DCHECK(service); |
51 service->ReloadExtension(extension_id); | 50 service->ReloadExtension(extension_id); |
52 } | 51 } |
53 | 52 |
54 void AppLoadService::RestartApplicationIfRunning( | 53 void AppLoadService::RestartApplicationIfRunning( |
(...skipping 22 matching lines...) Expand all Loading... | |
77 } | 76 } |
78 | 77 |
79 // static | 78 // static |
80 AppLoadService* AppLoadService::Get(Profile* profile) { | 79 AppLoadService* AppLoadService::Get(Profile* profile) { |
81 return apps::AppLoadServiceFactory::GetForProfile(profile); | 80 return apps::AppLoadServiceFactory::GetForProfile(profile); |
82 } | 81 } |
83 | 82 |
84 void AppLoadService::Observe(int type, | 83 void AppLoadService::Observe(int type, |
85 const content::NotificationSource& source, | 84 const content::NotificationSource& source, |
86 const content::NotificationDetails& details) { | 85 const content::NotificationDetails& details) { |
87 switch (type) { | 86 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING); |
88 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { | 87 extensions::ExtensionHost* host = |
89 extensions::ExtensionHost* host = | 88 content::Details<extensions::ExtensionHost>(details).ptr(); |
90 content::Details<extensions::ExtensionHost>(details).ptr(); | 89 const Extension* extension = host->extension(); |
91 const Extension* extension = host->extension(); | 90 // It is possible for an extension to be unloaded before it stops loading. |
92 // It is possible for an extension to be unloaded before it stops loading. | 91 if (!extension) |
93 if (!extension) | 92 return; |
94 break; | 93 std::map<std::string, PostReloadAction>::iterator it = |
95 std::map<std::string, PostReloadAction>::iterator it = | 94 post_reload_actions_.find(extension->id()); |
96 post_reload_actions_.find(extension->id()); | 95 if (it == post_reload_actions_.end()) |
97 if (it == post_reload_actions_.end()) | 96 return; |
98 break; | |
99 | 97 |
100 switch (it->second.action_type) { | 98 switch (it->second.action_type) { |
101 case LAUNCH: | 99 case LAUNCH: |
102 LaunchPlatformApp(profile_, extension); | 100 LaunchPlatformApp(profile_, extension); |
103 break; | |
104 case RESTART: | |
105 RestartPlatformApp(profile_, extension); | |
106 break; | |
107 case LAUNCH_WITH_COMMAND_LINE: | |
108 LaunchPlatformAppWithCommandLine( | |
109 profile_, extension, it->second.command_line, | |
110 it->second.current_dir); | |
111 break; | |
112 default: | |
113 NOTREACHED(); | |
114 } | |
115 | |
116 post_reload_actions_.erase(it); | |
117 break; | 101 break; |
118 } | 102 case RESTART: |
119 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | 103 RestartPlatformApp(profile_, extension); |
120 const extensions::UnloadedExtensionInfo* unload_info = | |
121 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); | |
122 if (!unload_info->extension->is_platform_app()) | |
123 break; | |
124 | |
125 extensions::ExtensionPrefs* extension_prefs = | |
126 extensions::ExtensionPrefs::Get(profile_); | |
127 if (WasUnloadedForReload(*unload_info) && | |
128 extension_prefs->IsActive(unload_info->extension->id()) && | |
129 !HasPostReloadAction(unload_info->extension->id())) { | |
130 post_reload_actions_[unload_info->extension->id()].action_type = LAUNCH; | |
131 } | |
132 break; | 104 break; |
133 } | 105 case LAUNCH_WITH_COMMAND_LINE: |
106 LaunchPlatformAppWithCommandLine( | |
107 profile_, extension, it->second.command_line, it->second.current_dir); | |
108 break; | |
134 default: | 109 default: |
135 NOTREACHED(); | 110 NOTREACHED(); |
136 } | 111 } |
112 | |
113 post_reload_actions_.erase(it); | |
114 } | |
115 | |
116 void AppLoadService::OnExtensionUnloaded( | |
117 content::BrowserContext* browser_context, | |
118 const extensions::Extension* extension, | |
119 extensions::UnloadedExtensionInfo::Reason reason) { | |
120 if (!extension->is_platform_app()) | |
121 return; | |
122 | |
123 extensions::ExtensionPrefs* extension_prefs = | |
124 extensions::ExtensionPrefs::Get(browser_context); | |
125 if (WasUnloadedForReload(extension->id(), reason) && | |
126 extension_prefs->IsActive(extension->id()) && | |
127 !HasPostReloadAction(extension->id())) { | |
128 post_reload_actions_[extension->id()].action_type = LAUNCH; | |
129 } | |
137 } | 130 } |
138 | 131 |
139 bool AppLoadService::WasUnloadedForReload( | 132 bool AppLoadService::WasUnloadedForReload( |
140 const extensions::UnloadedExtensionInfo& unload_info) { | 133 const extensions::ExtensionId& extension_id, |
141 if (unload_info.reason == extensions::UnloadedExtensionInfo::REASON_DISABLE) { | 134 const extensions::UnloadedExtensionInfo::Reason reason) { |
135 if (reason == extensions::UnloadedExtensionInfo::REASON_DISABLE) { | |
142 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); | 136 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); |
143 return (prefs->GetDisableReasons(unload_info.extension->id()) & | 137 return (prefs->GetDisableReasons(extension_id) & |
144 Extension::DISABLE_RELOAD) != 0; | 138 Extension::DISABLE_RELOAD) != 0; |
145 } | 139 } |
146 return false; | 140 return false; |
147 } | 141 } |
148 | 142 |
149 bool AppLoadService::HasPostReloadAction(const std::string& extension_id) { | 143 bool AppLoadService::HasPostReloadAction(const std::string& extension_id) { |
150 return post_reload_actions_.find(extension_id) != post_reload_actions_.end(); | 144 return post_reload_actions_.find(extension_id) != post_reload_actions_.end(); |
151 } | 145 } |
152 | 146 |
153 } // namespace apps | 147 } // namespace apps |
OLD | NEW |