OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/service_worker/service_worker_cache_quota_client.h" |
| 6 |
| 7 #include "content/browser/service_worker/service_worker_cache_storage_manager.h" |
5 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
6 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | |
7 | 9 |
8 using content::BrowserThread; | 10 namespace content { |
9 | 11 |
10 namespace extensions { | 12 ServiceWorkerCacheQuotaClient::ServiceWorkerCacheQuotaClient( |
11 | 13 base::WeakPtr<ServiceWorkerCacheStorageManager> cache_manager) |
12 // static | 14 : cache_manager_(cache_manager) { |
13 WebViewRendererState* WebViewRendererState::GetInstance() { | |
14 return Singleton<WebViewRendererState>::get(); | |
15 } | 15 } |
16 | 16 |
17 WebViewRendererState::WebViewRendererState() { | 17 ServiceWorkerCacheQuotaClient::~ServiceWorkerCacheQuotaClient() { |
18 } | 18 } |
19 | 19 |
20 WebViewRendererState::~WebViewRendererState() { | 20 storage::QuotaClient::ID ServiceWorkerCacheQuotaClient::id() const { |
| 21 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 22 return kServiceWorkerCache; |
21 } | 23 } |
22 | 24 |
23 bool WebViewRendererState::IsGuest(int render_process_id) { | 25 void ServiceWorkerCacheQuotaClient::OnQuotaManagerDestroyed() { |
24 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 26 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
25 return webview_partition_id_map_.find(render_process_id) != | 27 delete this; |
26 webview_partition_id_map_.end(); | |
27 } | 28 } |
28 | 29 |
29 void WebViewRendererState::AddGuest(int guest_process_id, | 30 void ServiceWorkerCacheQuotaClient::GetOriginUsage( |
30 int guest_routing_id, | 31 const GURL& origin_url, |
31 const WebViewInfo& webview_info) { | 32 storage::StorageType type, |
| 33 const GetUsageCallback& callback) { |
32 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 34 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
33 RenderId render_id(guest_process_id, guest_routing_id); | 35 |
34 webview_info_map_[render_id] = webview_info; | 36 if (!cache_manager_ || !DoesSupport(type)) { |
35 WebViewPartitionIDMap::iterator iter = | 37 callback.Run(0); |
36 webview_partition_id_map_.find(guest_process_id); | |
37 if (iter != webview_partition_id_map_.end()) { | |
38 ++iter->second.web_view_count; | |
39 return; | 38 return; |
40 } | 39 } |
41 WebViewPartitionInfo partition_info(1, webview_info.partition_id); | 40 |
42 webview_partition_id_map_[guest_process_id] = partition_info; | 41 cache_manager_->GetOriginUsage(origin_url, callback); |
43 } | 42 } |
44 | 43 |
45 void WebViewRendererState::RemoveGuest(int guest_process_id, | 44 void ServiceWorkerCacheQuotaClient::GetOriginsForType( |
46 int guest_routing_id) { | 45 storage::StorageType type, |
| 46 const GetOriginsCallback& callback) { |
47 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 47 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
48 RenderId render_id(guest_process_id, guest_routing_id); | 48 |
49 webview_info_map_.erase(render_id); | 49 if (!cache_manager_ || !DoesSupport(type)) { |
50 WebViewPartitionIDMap::iterator iter = | 50 callback.Run(std::set<GURL>()); |
51 webview_partition_id_map_.find(guest_process_id); | |
52 if (iter != webview_partition_id_map_.end() && | |
53 iter->second.web_view_count > 1) { | |
54 --iter->second.web_view_count; | |
55 return; | 51 return; |
56 } | 52 } |
57 webview_partition_id_map_.erase(guest_process_id); | 53 |
| 54 cache_manager_->GetOrigins(callback); |
58 } | 55 } |
59 | 56 |
60 bool WebViewRendererState::GetInfo(int guest_process_id, | 57 void ServiceWorkerCacheQuotaClient::GetOriginsForHost( |
61 int guest_routing_id, | 58 storage::StorageType type, |
62 WebViewInfo* webview_info) { | 59 const std::string& host, |
| 60 const GetOriginsCallback& callback) { |
63 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
64 RenderId render_id(guest_process_id, guest_routing_id); | 62 |
65 WebViewInfoMap::iterator iter = webview_info_map_.find(render_id); | 63 if (!cache_manager_ || !DoesSupport(type)) { |
66 if (iter != webview_info_map_.end()) { | 64 callback.Run(std::set<GURL>()); |
67 *webview_info = iter->second; | 65 return; |
68 return true; | |
69 } | 66 } |
70 return false; | 67 |
| 68 cache_manager_->GetOriginsForHost(host, callback); |
71 } | 69 } |
72 | 70 |
73 bool WebViewRendererState::GetPartitionID(int guest_process_id, | 71 void ServiceWorkerCacheQuotaClient::DeleteOriginData( |
74 std::string* partition_id) { | 72 const GURL& origin, |
| 73 storage::StorageType type, |
| 74 const DeletionCallback& callback) { |
75 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 75 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
76 WebViewPartitionIDMap::iterator iter = | 76 |
77 webview_partition_id_map_.find(guest_process_id); | 77 if (!cache_manager_) { |
78 if (iter != webview_partition_id_map_.end()) { | 78 callback.Run(storage::kQuotaErrorAbort); |
79 *partition_id = iter->second.partition_id; | 79 return; |
80 return true; | |
81 } | 80 } |
82 return false; | 81 |
| 82 if (!DoesSupport(type)) { |
| 83 callback.Run(storage::kQuotaStatusOk); |
| 84 return; |
| 85 } |
| 86 |
| 87 cache_manager_->DeleteOriginData(origin, callback); |
83 } | 88 } |
84 | 89 |
85 } // namespace extensions | 90 bool ServiceWorkerCacheQuotaClient::DoesSupport( |
| 91 storage::StorageType type) const { |
| 92 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 93 |
| 94 return type == storage::kStorageTypeTemporary; |
| 95 } |
| 96 |
| 97 } // namespace content |
OLD | NEW |