OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "extensions/browser/service_worker_manager.h" | 5 #include "extensions/browser/service_worker_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
9 #include "content/public/browser/service_worker_context.h" | 9 #include "content/public/browser/service_worker_context.h" |
10 #include "content/public/browser/storage_partition.h" | 10 #include "content/public/browser/storage_partition.h" |
11 #include "extensions/browser/extension_registry.h" | 11 #include "extensions/browser/extension_registry.h" |
12 | 12 |
13 namespace extensions { | 13 namespace extensions { |
14 | 14 |
15 namespace { | 15 namespace { |
16 void EmptySuccessCallback(bool success) {} | 16 void EmptySuccessCallback(bool success) {} |
17 } | 17 } |
18 | 18 |
19 ServiceWorkerManager::ServiceWorkerManager( | 19 ServiceWorkerManager::ServiceWorkerManager( |
20 content::BrowserContext* browser_context) | 20 content::BrowserContext* browser_context) |
21 : browser_context_(browser_context), registry_observer_(this) { | 21 : browser_context_(browser_context), registry_observer_(this) { |
22 registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); | 22 registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); |
23 } | 23 } |
24 | 24 |
25 ServiceWorkerManager::~ServiceWorkerManager() {} | 25 ServiceWorkerManager::~ServiceWorkerManager() {} |
26 | 26 |
27 void ServiceWorkerManager::OnExtensionUnloaded( | 27 void ServiceWorkerManager::OnExtensionUnloaded( |
28 content::BrowserContext* browser_context, | 28 content::BrowserContext* browser_context, |
29 const Extension* extension, | 29 const Extension* extension, |
30 UnloadedExtensionInfo::Reason reason) { | 30 UnloadedExtensionReason reason) { |
31 content::BrowserContext::GetStoragePartitionForSite(browser_context_, | 31 content::BrowserContext::GetStoragePartitionForSite(browser_context_, |
32 extension->url()) | 32 extension->url()) |
33 ->GetServiceWorkerContext() | 33 ->GetServiceWorkerContext() |
34 ->StopAllServiceWorkersForOrigin(extension->url()); | 34 ->StopAllServiceWorkersForOrigin(extension->url()); |
35 } | 35 } |
36 | 36 |
37 void ServiceWorkerManager::OnExtensionUninstalled( | 37 void ServiceWorkerManager::OnExtensionUninstalled( |
38 content::BrowserContext* browser_context, | 38 content::BrowserContext* browser_context, |
39 const Extension* extension, | 39 const Extension* extension, |
40 extensions::UninstallReason reason) { | 40 extensions::UninstallReason reason) { |
41 // TODO(devlin): Technically, this can fail. We should ideally: | 41 // TODO(devlin): Technically, this can fail. We should ideally: |
42 // a) Keep track of extensions with registered service workers. | 42 // a) Keep track of extensions with registered service workers. |
43 // b) Add a callback to the (Un)SuspendServiceWorkersOnOrigin() method. | 43 // b) Add a callback to the (Un)SuspendServiceWorkersOnOrigin() method. |
44 // c) Check for any orphaned workers. | 44 // c) Check for any orphaned workers. |
45 content::BrowserContext::GetStoragePartitionForSite(browser_context_, | 45 content::BrowserContext::GetStoragePartitionForSite(browser_context_, |
46 extension->url()) | 46 extension->url()) |
47 ->GetServiceWorkerContext() | 47 ->GetServiceWorkerContext() |
48 ->DeleteForOrigin(extension->url(), base::Bind(&EmptySuccessCallback)); | 48 ->DeleteForOrigin(extension->url(), base::Bind(&EmptySuccessCallback)); |
49 } | 49 } |
50 | 50 |
51 } // namespace extensions | 51 } // namespace extensions |
OLD | NEW |