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 "content/browser/appcache/appcache.h" | 5 #include "content/browser/appcache/appcache.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "content/browser/appcache/appcache_executable_handler.h" | 13 #include "content/browser/appcache/appcache_executable_handler.h" |
14 #include "content/browser/appcache/appcache_group.h" | 14 #include "content/browser/appcache/appcache_group.h" |
15 #include "content/browser/appcache/appcache_host.h" | 15 #include "content/browser/appcache/appcache_host.h" |
16 #include "content/browser/appcache/appcache_storage.h" | 16 #include "content/browser/appcache/appcache_storage.h" |
17 #include "content/common/appcache_interfaces.h" | 17 #include "content/common/appcache_interfaces.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 AppCache::AppCache(AppCacheStorage* storage, int64_t cache_id) | 21 AppCache::AppCache(AppCacheStorage* storage, int64_t cache_id) |
22 : cache_id_(cache_id), | 22 : cache_id_(cache_id), |
23 owning_group_(NULL), | 23 owning_group_(nullptr), |
24 online_whitelist_all_(false), | 24 online_whitelist_all_(false), |
25 is_complete_(false), | 25 is_complete_(false), |
26 cache_size_(0), | 26 cache_size_(0), |
27 storage_(storage) { | 27 storage_(storage) { |
28 storage_->working_set()->AddCache(this); | 28 storage_->working_set()->AddCache(this); |
29 } | 29 } |
30 | 30 |
31 AppCache::~AppCache() { | 31 AppCache::~AppCache() { |
32 DCHECK(associated_hosts_.empty()); | 32 DCHECK(associated_hosts_.empty()); |
33 if (owning_group_.get()) { | 33 if (owning_group_.get()) { |
34 DCHECK(is_complete_); | 34 DCHECK(is_complete_); |
35 owning_group_->RemoveCache(this); | 35 owning_group_->RemoveCache(this); |
36 } | 36 } |
37 DCHECK(!owning_group_.get()); | 37 DCHECK(!owning_group_.get()); |
38 storage_->working_set()->RemoveCache(this); | 38 storage_->working_set()->RemoveCache(this); |
39 base::STLDeleteContainerPairSecondPointers(executable_handlers_.begin(), | |
40 executable_handlers_.end()); | |
41 } | 39 } |
42 | 40 |
43 void AppCache::UnassociateHost(AppCacheHost* host) { | 41 void AppCache::UnassociateHost(AppCacheHost* host) { |
44 associated_hosts_.erase(host); | 42 associated_hosts_.erase(host); |
45 } | 43 } |
46 | 44 |
47 void AppCache::AddEntry(const GURL& url, const AppCacheEntry& entry) { | 45 void AppCache::AddEntry(const GURL& url, const AppCacheEntry& entry) { |
48 DCHECK(entries_.find(url) == entries_.end()); | 46 DCHECK(entries_.find(url) == entries_.end()); |
49 entries_.insert(EntryMap::value_type(url, entry)); | 47 entries_.insert(EntryMap::value_type(url, entry)); |
50 cache_size_ += entry.response_size(); | 48 cache_size_ += entry.response_size(); |
(...skipping 13 matching lines...) Expand all Loading... |
64 | 62 |
65 void AppCache::RemoveEntry(const GURL& url) { | 63 void AppCache::RemoveEntry(const GURL& url) { |
66 EntryMap::iterator found = entries_.find(url); | 64 EntryMap::iterator found = entries_.find(url); |
67 DCHECK(found != entries_.end()); | 65 DCHECK(found != entries_.end()); |
68 cache_size_ -= found->second.response_size(); | 66 cache_size_ -= found->second.response_size(); |
69 entries_.erase(found); | 67 entries_.erase(found); |
70 } | 68 } |
71 | 69 |
72 AppCacheEntry* AppCache::GetEntry(const GURL& url) { | 70 AppCacheEntry* AppCache::GetEntry(const GURL& url) { |
73 EntryMap::iterator it = entries_.find(url); | 71 EntryMap::iterator it = entries_.find(url); |
74 return (it != entries_.end()) ? &(it->second) : NULL; | 72 return (it != entries_.end()) ? &(it->second) : nullptr; |
75 } | 73 } |
76 | 74 |
77 const AppCacheEntry* AppCache::GetEntryAndUrlWithResponseId( | 75 const AppCacheEntry* AppCache::GetEntryAndUrlWithResponseId( |
78 int64_t response_id, | 76 int64_t response_id, |
79 GURL* optional_url_out) { | 77 GURL* optional_url_out) { |
80 for (EntryMap::const_iterator iter = entries_.begin(); | 78 for (EntryMap::const_iterator iter = entries_.begin(); |
81 iter != entries_.end(); ++iter) { | 79 iter != entries_.end(); ++iter) { |
82 if (iter->second.response_id() == response_id) { | 80 if (iter->second.response_id() == response_id) { |
83 if (optional_url_out) | 81 if (optional_url_out) |
84 *optional_url_out = iter->first; | 82 *optional_url_out = iter->first; |
85 return &iter->second; | 83 return &iter->second; |
86 } | 84 } |
87 } | 85 } |
88 return NULL; | 86 return nullptr; |
89 } | 87 } |
90 | 88 |
91 AppCacheExecutableHandler* AppCache::GetExecutableHandler(int64_t response_id) { | 89 AppCacheExecutableHandler* AppCache::GetExecutableHandler(int64_t response_id) { |
92 HandlerMap::const_iterator found = executable_handlers_.find(response_id); | 90 HandlerMap::const_iterator found = executable_handlers_.find(response_id); |
93 if (found != executable_handlers_.end()) | 91 if (found != executable_handlers_.end()) |
94 return found->second; | 92 return found->second.get(); |
95 return NULL; | 93 return nullptr; |
96 } | 94 } |
97 | 95 |
98 AppCacheExecutableHandler* AppCache::GetOrCreateExecutableHandler( | 96 AppCacheExecutableHandler* AppCache::GetOrCreateExecutableHandler( |
99 int64_t response_id, | 97 int64_t response_id, |
100 net::IOBuffer* handler_source) { | 98 net::IOBuffer* handler_source) { |
101 AppCacheExecutableHandler* handler = GetExecutableHandler(response_id); | 99 AppCacheExecutableHandler* handler = GetExecutableHandler(response_id); |
102 if (handler) | 100 if (handler) |
103 return handler; | 101 return handler; |
104 | 102 |
105 GURL handler_url; | 103 GURL handler_url; |
106 const AppCacheEntry* entry = GetEntryAndUrlWithResponseId( | 104 const AppCacheEntry* entry = GetEntryAndUrlWithResponseId( |
107 response_id, &handler_url); | 105 response_id, &handler_url); |
108 if (!entry || !entry->IsExecutable()) | 106 if (!entry || !entry->IsExecutable()) |
109 return NULL; | 107 return nullptr; |
110 | 108 |
111 DCHECK(storage_->service()->handler_factory()); | 109 DCHECK(storage_->service()->handler_factory()); |
112 std::unique_ptr<AppCacheExecutableHandler> own_ptr = | 110 std::unique_ptr<AppCacheExecutableHandler> own_ptr = |
113 storage_->service()->handler_factory()->CreateHandler(handler_url, | 111 storage_->service()->handler_factory()->CreateHandler(handler_url, |
114 handler_source); | 112 handler_source); |
115 handler = own_ptr.release(); | 113 handler = own_ptr.get(); |
116 if (!handler) | 114 if (!handler) |
117 return NULL; | 115 return nullptr; |
118 executable_handlers_[response_id] = handler; | 116 executable_handlers_[response_id] = std::move(own_ptr); |
119 return handler; | 117 return handler; |
120 } | 118 } |
121 | 119 |
122 GURL AppCache::GetNamespaceEntryUrl(const AppCacheNamespaceVector& namespaces, | 120 GURL AppCache::GetNamespaceEntryUrl(const AppCacheNamespaceVector& namespaces, |
123 const GURL& namespace_url) const { | 121 const GURL& namespace_url) const { |
124 size_t count = namespaces.size(); | 122 size_t count = namespaces.size(); |
125 for (size_t i = 0; i < count; ++i) { | 123 for (size_t i = 0; i < count; ++i) { |
126 if (namespaces[i].namespace_url == namespace_url) | 124 if (namespaces[i].namespace_url == namespace_url) |
127 return namespaces[i].target_url; | 125 return namespaces[i].target_url; |
128 } | 126 } |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 | 316 |
319 // static | 317 // static |
320 const AppCacheNamespace* AppCache::FindNamespace( | 318 const AppCacheNamespace* AppCache::FindNamespace( |
321 const AppCacheNamespaceVector& namespaces, | 319 const AppCacheNamespaceVector& namespaces, |
322 const GURL& url) { | 320 const GURL& url) { |
323 size_t count = namespaces.size(); | 321 size_t count = namespaces.size(); |
324 for (size_t i = 0; i < count; ++i) { | 322 for (size_t i = 0; i < count; ++i) { |
325 if (namespaces[i].IsMatch(url)) | 323 if (namespaces[i].IsMatch(url)) |
326 return &namespaces[i]; | 324 return &namespaces[i]; |
327 } | 325 } |
328 return NULL; | 326 return nullptr; |
329 } | 327 } |
330 | 328 |
331 } // namespace content | 329 } // namespace content |
OLD | NEW |