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/launcher.h" | 9 #include "apps/launcher.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "extensions/browser/notification_types.h" | 21 #include "extensions/browser/notification_types.h" |
22 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
23 | 23 |
24 using extensions::Extension; | 24 using extensions::Extension; |
25 using extensions::ExtensionPrefs; | 25 using extensions::ExtensionPrefs; |
26 using extensions::ExtensionSystem; | 26 using extensions::ExtensionSystem; |
27 | 27 |
28 namespace apps { | 28 namespace apps { |
29 | 29 |
30 AppLoadService::PostReloadAction::PostReloadAction() | 30 AppLoadService::PostReloadAction::PostReloadAction() |
31 : action_type(LAUNCH), | 31 : action_type(RELOAD), command_line(CommandLine::NO_PROGRAM) { |
32 command_line(CommandLine::NO_PROGRAM) { | |
33 } | 32 } |
34 | 33 |
35 AppLoadService::AppLoadService(Profile* profile) | 34 AppLoadService::AppLoadService(Profile* profile) |
36 : profile_(profile) { | 35 : profile_(profile) { |
37 registrar_.Add(this, | 36 registrar_.Add(this, |
38 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 37 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
39 content::NotificationService::AllSources()); | 38 content::NotificationService::AllSources()); |
40 extensions::ExtensionRegistry::Get(profile_)->AddObserver(this); | 39 extensions::ExtensionRegistry::Get(profile_)->AddObserver(this); |
41 } | 40 } |
42 | 41 |
(...skipping 21 matching lines...) Expand all Loading... |
64 ExtensionService* extension_service = | 63 ExtensionService* extension_service = |
65 ExtensionSystem::Get(profile_)->extension_service(); | 64 ExtensionSystem::Get(profile_)->extension_service(); |
66 std::string extension_id; | 65 std::string extension_id; |
67 if (!extensions::UnpackedInstaller::Create(extension_service)-> | 66 if (!extensions::UnpackedInstaller::Create(extension_service)-> |
68 LoadFromCommandLine(base::FilePath(extension_path), &extension_id)) { | 67 LoadFromCommandLine(base::FilePath(extension_path), &extension_id)) { |
69 return false; | 68 return false; |
70 } | 69 } |
71 | 70 |
72 // Schedule the app to be launched once loaded. | 71 // Schedule the app to be launched once loaded. |
73 PostReloadAction& action = post_reload_actions_[extension_id]; | 72 PostReloadAction& action = post_reload_actions_[extension_id]; |
74 action.action_type = LAUNCH_WITH_COMMAND_LINE; | 73 action.action_type = LOAD_AND_LAUNCH; |
75 action.command_line = command_line; | 74 action.command_line = command_line; |
76 action.current_dir = current_dir; | 75 action.current_dir = current_dir; |
77 return true; | 76 return true; |
78 } | 77 } |
79 | 78 |
80 // static | 79 // static |
81 AppLoadService* AppLoadService::Get(Profile* profile) { | 80 AppLoadService* AppLoadService::Get(Profile* profile) { |
82 return apps::AppLoadServiceFactory::GetForProfile(profile); | 81 return apps::AppLoadServiceFactory::GetForProfile(profile); |
83 } | 82 } |
84 | 83 |
85 void AppLoadService::Observe(int type, | 84 void AppLoadService::Observe(int type, |
86 const content::NotificationSource& source, | 85 const content::NotificationSource& source, |
87 const content::NotificationDetails& details) { | 86 const content::NotificationDetails& details) { |
88 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING); | 87 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING); |
89 extensions::ExtensionHost* host = | 88 extensions::ExtensionHost* host = |
90 content::Details<extensions::ExtensionHost>(details).ptr(); | 89 content::Details<extensions::ExtensionHost>(details).ptr(); |
91 const Extension* extension = host->extension(); | 90 const Extension* extension = host->extension(); |
92 // It is possible for an extension to be unloaded before it stops loading. | 91 // It is possible for an extension to be unloaded before it stops loading. |
93 if (!extension) | 92 if (!extension) |
94 return; | 93 return; |
95 std::map<std::string, PostReloadAction>::iterator it = | 94 std::map<std::string, PostReloadAction>::iterator it = |
96 post_reload_actions_.find(extension->id()); | 95 post_reload_actions_.find(extension->id()); |
97 if (it == post_reload_actions_.end()) | 96 if (it == post_reload_actions_.end()) |
98 return; | 97 return; |
99 | 98 |
100 switch (it->second.action_type) { | 99 switch (it->second.action_type) { |
101 case LAUNCH: | 100 case RELOAD: |
102 LaunchPlatformApp(profile_, extension); | 101 LaunchPlatformApp(profile_, extension, extensions::SOURCE_RELOAD); |
103 break; | 102 break; |
104 case RESTART: | 103 case RESTART: |
105 RestartPlatformApp(profile_, extension); | 104 RestartPlatformApp(profile_, extension); |
106 break; | 105 break; |
107 case LAUNCH_WITH_COMMAND_LINE: | 106 case LOAD_AND_LAUNCH: |
108 LaunchPlatformAppWithCommandLine( | 107 LaunchPlatformAppWithCommandLine(profile_, |
109 profile_, extension, it->second.command_line, it->second.current_dir); | 108 extension, |
| 109 it->second.command_line, |
| 110 it->second.current_dir, |
| 111 extensions::SOURCE_LOAD_AND_LAUNCH); |
110 break; | 112 break; |
111 default: | 113 default: |
112 NOTREACHED(); | 114 NOTREACHED(); |
113 } | 115 } |
114 | 116 |
115 post_reload_actions_.erase(it); | 117 post_reload_actions_.erase(it); |
116 } | 118 } |
117 | 119 |
118 void AppLoadService::OnExtensionUnloaded( | 120 void AppLoadService::OnExtensionUnloaded( |
119 content::BrowserContext* browser_context, | 121 content::BrowserContext* browser_context, |
120 const Extension* extension, | 122 const Extension* extension, |
121 extensions::UnloadedExtensionInfo::Reason reason) { | 123 extensions::UnloadedExtensionInfo::Reason reason) { |
122 if (!extension->is_platform_app()) | 124 if (!extension->is_platform_app()) |
123 return; | 125 return; |
124 | 126 |
125 extensions::ExtensionPrefs* extension_prefs = | 127 extensions::ExtensionPrefs* extension_prefs = |
126 extensions::ExtensionPrefs::Get(browser_context); | 128 extensions::ExtensionPrefs::Get(browser_context); |
127 if (WasUnloadedForReload(extension->id(), reason) && | 129 if (WasUnloadedForReload(extension->id(), reason) && |
128 extension_prefs->IsActive(extension->id()) && | 130 extension_prefs->IsActive(extension->id()) && |
129 !HasPostReloadAction(extension->id())) { | 131 !HasPostReloadAction(extension->id())) { |
130 post_reload_actions_[extension->id()].action_type = LAUNCH; | 132 post_reload_actions_[extension->id()].action_type = RELOAD; |
131 } | 133 } |
132 } | 134 } |
133 | 135 |
134 bool AppLoadService::WasUnloadedForReload( | 136 bool AppLoadService::WasUnloadedForReload( |
135 const extensions::ExtensionId& extension_id, | 137 const extensions::ExtensionId& extension_id, |
136 const extensions::UnloadedExtensionInfo::Reason reason) { | 138 const extensions::UnloadedExtensionInfo::Reason reason) { |
137 if (reason == extensions::UnloadedExtensionInfo::REASON_DISABLE) { | 139 if (reason == extensions::UnloadedExtensionInfo::REASON_DISABLE) { |
138 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); | 140 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); |
139 return (prefs->GetDisableReasons(extension_id) & | 141 return (prefs->GetDisableReasons(extension_id) & |
140 Extension::DISABLE_RELOAD) != 0; | 142 Extension::DISABLE_RELOAD) != 0; |
141 } | 143 } |
142 return false; | 144 return false; |
143 } | 145 } |
144 | 146 |
145 bool AppLoadService::HasPostReloadAction(const std::string& extension_id) { | 147 bool AppLoadService::HasPostReloadAction(const std::string& extension_id) { |
146 return post_reload_actions_.find(extension_id) != post_reload_actions_.end(); | 148 return post_reload_actions_.find(extension_id) != post_reload_actions_.end(); |
147 } | 149 } |
148 | 150 |
149 } // namespace apps | 151 } // namespace apps |
OLD | NEW |