OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/extensions/api/runtime/runtime_api.h" | 5 #include "chrome/browser/extensions/api/runtime/runtime_api.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 break; | 204 break; |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
208 void RuntimeAPI::OnExtensionsReady() { | 208 void RuntimeAPI::OnExtensionsReady() { |
209 // We're done restarting Chrome after an update. | 209 // We're done restarting Chrome after an update. |
210 dispatch_chrome_updated_event_ = false; | 210 dispatch_chrome_updated_event_ = false; |
211 | 211 |
212 registered_for_updates_ = true; | 212 registered_for_updates_ = true; |
213 | 213 |
214 ExtensionSystem::Get(browser_context_)->extension_service()-> | 214 ExtensionSystem* extension_system = ExtensionSystem::Get(browser_context_); |
215 AddUpdateObserver(this); | 215 extension_system->extension_service()->AddUpdateObserver(this); |
| 216 |
| 217 // RuntimeAPI is redirected in incognito, so |browser_context_| is never |
| 218 // incognito. We don't observe incognito ProcessManagers but that is OK |
| 219 // because we don't send onStartup events to incognito browser contexts. |
| 220 DCHECK(!browser_context_->IsOffTheRecord()); |
| 221 // Some tests use partially constructed Profiles without a process manager. |
| 222 if (extension_system->process_manager()) |
| 223 extension_system->process_manager()->AddObserver(this); |
216 } | 224 } |
217 | 225 |
218 void RuntimeAPI::OnExtensionLoaded(const Extension* extension) { | 226 void RuntimeAPI::OnExtensionLoaded(const Extension* extension) { |
219 if (!dispatch_chrome_updated_event_) | 227 if (!dispatch_chrome_updated_event_) |
220 return; | 228 return; |
221 | 229 |
222 // Dispatch the onInstalled event with reason "chrome_update". | 230 // Dispatch the onInstalled event with reason "chrome_update". |
223 base::MessageLoop::current()->PostTask( | 231 base::MessageLoop::current()->PostTask( |
224 FROM_HERE, | 232 FROM_HERE, |
225 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, | 233 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 void RuntimeAPI::OnExtensionUninstalled(const Extension* extension) { | 265 void RuntimeAPI::OnExtensionUninstalled(const Extension* extension) { |
258 // Ephemeral apps are not considered to be installed, so the uninstall URL | 266 // Ephemeral apps are not considered to be installed, so the uninstall URL |
259 // is not invoked when they are removed. | 267 // is not invoked when they are removed. |
260 if (extension->is_ephemeral()) | 268 if (extension->is_ephemeral()) |
261 return; | 269 return; |
262 | 270 |
263 Profile* profile = Profile::FromBrowserContext(browser_context_); | 271 Profile* profile = Profile::FromBrowserContext(browser_context_); |
264 RuntimeEventRouter::OnExtensionUninstalled(profile, extension->id()); | 272 RuntimeEventRouter::OnExtensionUninstalled(profile, extension->id()); |
265 } | 273 } |
266 | 274 |
| 275 void RuntimeAPI::Shutdown() { |
| 276 // ExtensionSystem deletes its ProcessManager during the Shutdown() phase, so |
| 277 // the observer must be removed here and not in the RuntimeAPI destructor. |
| 278 ProcessManager* process_manager = |
| 279 ExtensionSystem::Get(browser_context_)->process_manager(); |
| 280 // Some tests use partially constructed Profiles without a process manager. |
| 281 if (process_manager) |
| 282 process_manager->RemoveObserver(this); |
| 283 } |
| 284 |
267 void RuntimeAPI::OnAppUpdateAvailable(const Extension* extension) { | 285 void RuntimeAPI::OnAppUpdateAvailable(const Extension* extension) { |
268 Profile* profile = Profile::FromBrowserContext(browser_context_); | 286 Profile* profile = Profile::FromBrowserContext(browser_context_); |
269 RuntimeEventRouter::DispatchOnUpdateAvailableEvent( | 287 RuntimeEventRouter::DispatchOnUpdateAvailableEvent( |
270 profile, extension->id(), extension->manifest()->value()); | 288 profile, extension->id(), extension->manifest()->value()); |
271 } | 289 } |
272 | 290 |
273 void RuntimeAPI::OnChromeUpdateAvailable() { | 291 void RuntimeAPI::OnChromeUpdateAvailable() { |
274 Profile* profile = Profile::FromBrowserContext(browser_context_); | 292 Profile* profile = Profile::FromBrowserContext(browser_context_); |
275 RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent(profile); | 293 RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent(profile); |
276 } | 294 } |
277 | 295 |
| 296 void RuntimeAPI::OnBackgroundHostStartup(const Extension* extension) { |
| 297 RuntimeEventRouter::DispatchOnStartupEvent(browser_context_, extension->id()); |
| 298 } |
| 299 |
278 /////////////////////////////////////////////////////////////////////////////// | 300 /////////////////////////////////////////////////////////////////////////////// |
279 | 301 |
280 // static | 302 // static |
281 void RuntimeEventRouter::DispatchOnStartupEvent( | 303 void RuntimeEventRouter::DispatchOnStartupEvent( |
282 content::BrowserContext* context, const std::string& extension_id) { | 304 content::BrowserContext* context, const std::string& extension_id) { |
283 DispatchOnStartupEventImpl(context, extension_id, true, NULL); | 305 DispatchOnStartupEventImpl(context, extension_id, true, NULL); |
284 } | 306 } |
285 | 307 |
286 // static | 308 // static |
287 void RuntimeEventRouter::DispatchOnInstalledEvent( | 309 void RuntimeEventRouter::DispatchOnInstalledEvent( |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 content::ChildProcessSecurityPolicy::GetInstance(); | 613 content::ChildProcessSecurityPolicy::GetInstance(); |
592 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 614 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
593 base::DictionaryValue* dict = new base::DictionaryValue(); | 615 base::DictionaryValue* dict = new base::DictionaryValue(); |
594 SetResult(dict); | 616 SetResult(dict); |
595 dict->SetString("fileSystemId", filesystem_id); | 617 dict->SetString("fileSystemId", filesystem_id); |
596 dict->SetString("baseName", relative_path); | 618 dict->SetString("baseName", relative_path); |
597 return true; | 619 return true; |
598 } | 620 } |
599 | 621 |
600 } // namespace extensions | 622 } // namespace extensions |
OLD | NEW |