| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/appcache/web_application_cache_host_impl.h" | 5 #include "webkit/appcache/web_application_cache_host_impl.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
| 9 #include "base/lazy_instance.h" | |
| 10 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 11 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
| 17 | 16 |
| 18 using WebKit::WebApplicationCacheHost; | 17 using WebKit::WebApplicationCacheHost; |
| 19 using WebKit::WebApplicationCacheHostClient; | 18 using WebKit::WebApplicationCacheHostClient; |
| 20 using WebKit::WebDataSource; | 19 using WebKit::WebDataSource; |
| 21 using WebKit::WebFrame; | 20 using WebKit::WebFrame; |
| 22 using WebKit::WebURLRequest; | 21 using WebKit::WebURLRequest; |
| 23 using WebKit::WebURL; | 22 using WebKit::WebURL; |
| 24 using WebKit::WebURLResponse; | 23 using WebKit::WebURLResponse; |
| 25 using WebKit::WebVector; | 24 using WebKit::WebVector; |
| 26 | 25 |
| 27 namespace appcache { | 26 namespace appcache { |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 typedef IDMap<WebApplicationCacheHostImpl> HostsMap; | |
| 32 static base::LazyInstance<HostsMap> g_hosts_map(base::LINKER_INITIALIZED); | |
| 33 | |
| 34 // Note: the order of the elements in this array must match those | 30 // Note: the order of the elements in this array must match those |
| 35 // of the EventID enum in appcache_interfaces.h. | 31 // of the EventID enum in appcache_interfaces.h. |
| 36 const char* kEventNames[] = { | 32 const char* kEventNames[] = { |
| 37 "Checking", "Error", "NoUpdate", "Downloading", "Progress", | 33 "Checking", "Error", "NoUpdate", "Downloading", "Progress", |
| 38 "UpdateReady", "Cached", "Obsolete" | 34 "UpdateReady", "Cached", "Obsolete" |
| 39 }; | 35 }; |
| 40 | 36 |
| 37 typedef IDMap<WebApplicationCacheHostImpl> HostsMap; |
| 38 |
| 39 HostsMap* all_hosts() { |
| 40 static HostsMap* map = new HostsMap; |
| 41 return map; |
| 42 } |
| 43 |
| 41 GURL ClearUrlRef(const GURL& url) { | 44 GURL ClearUrlRef(const GURL& url) { |
| 42 if (!url.has_ref()) | 45 if (!url.has_ref()) |
| 43 return url; | 46 return url; |
| 44 GURL::Replacements replacements; | 47 GURL::Replacements replacements; |
| 45 replacements.ClearRef(); | 48 replacements.ClearRef(); |
| 46 return url.ReplaceComponents(replacements); | 49 return url.ReplaceComponents(replacements); |
| 47 } | 50 } |
| 48 | 51 |
| 49 } // anon namespace | 52 } // anon namespace |
| 50 | 53 |
| 51 WebApplicationCacheHostImpl* WebApplicationCacheHostImpl::FromId(int id) { | 54 WebApplicationCacheHostImpl* WebApplicationCacheHostImpl::FromId(int id) { |
| 52 return g_hosts_map.Get().Lookup(id); | 55 return all_hosts()->Lookup(id); |
| 53 } | 56 } |
| 54 | 57 |
| 55 WebApplicationCacheHostImpl* WebApplicationCacheHostImpl::FromFrame( | 58 WebApplicationCacheHostImpl* WebApplicationCacheHostImpl::FromFrame( |
| 56 const WebFrame* frame) { | 59 const WebFrame* frame) { |
| 57 if (!frame) | 60 if (!frame) |
| 58 return NULL; | 61 return NULL; |
| 59 WebDataSource* data_source = frame->dataSource(); | 62 WebDataSource* data_source = frame->dataSource(); |
| 60 if (!data_source) | 63 if (!data_source) |
| 61 return NULL; | 64 return NULL; |
| 62 return static_cast<WebApplicationCacheHostImpl*> | 65 return static_cast<WebApplicationCacheHostImpl*> |
| 63 (data_source->applicationCacheHost()); | 66 (data_source->applicationCacheHost()); |
| 64 } | 67 } |
| 65 | 68 |
| 66 WebApplicationCacheHostImpl::WebApplicationCacheHostImpl( | 69 WebApplicationCacheHostImpl::WebApplicationCacheHostImpl( |
| 67 WebApplicationCacheHostClient* client, | 70 WebApplicationCacheHostClient* client, |
| 68 AppCacheBackend* backend) | 71 AppCacheBackend* backend) |
| 69 : client_(client), | 72 : client_(client), |
| 70 backend_(backend), | 73 backend_(backend), |
| 71 ALLOW_THIS_IN_INITIALIZER_LIST(host_id_(g_hosts_map.Get().Add(this))), | 74 ALLOW_THIS_IN_INITIALIZER_LIST(host_id_(all_hosts()->Add(this))), |
| 72 status_(UNCACHED), | 75 status_(UNCACHED), |
| 73 is_scheme_supported_(false), | 76 is_scheme_supported_(false), |
| 74 is_get_method_(false), | 77 is_get_method_(false), |
| 75 is_new_master_entry_(MAYBE), | 78 is_new_master_entry_(MAYBE), |
| 76 was_select_cache_called_(false) { | 79 was_select_cache_called_(false) { |
| 77 DCHECK(client && backend && (host_id_ != kNoHostId)); | 80 DCHECK(client && backend && (host_id_ != kNoHostId)); |
| 78 | 81 |
| 79 backend_->RegisterHost(host_id_); | 82 backend_->RegisterHost(host_id_); |
| 80 } | 83 } |
| 81 | 84 |
| 82 WebApplicationCacheHostImpl::~WebApplicationCacheHostImpl() { | 85 WebApplicationCacheHostImpl::~WebApplicationCacheHostImpl() { |
| 83 backend_->UnregisterHost(host_id_); | 86 backend_->UnregisterHost(host_id_); |
| 84 g_hosts_map.Get().Remove(host_id_); | 87 all_hosts()->Remove(host_id_); |
| 85 } | 88 } |
| 86 | 89 |
| 87 void WebApplicationCacheHostImpl::OnCacheSelected( | 90 void WebApplicationCacheHostImpl::OnCacheSelected( |
| 88 const appcache::AppCacheInfo& info) { | 91 const appcache::AppCacheInfo& info) { |
| 89 cache_info_ = info; | 92 cache_info_ = info; |
| 90 client_->didChangeCacheAssociation(); | 93 client_->didChangeCacheAssociation(); |
| 91 } | 94 } |
| 92 | 95 |
| 93 void WebApplicationCacheHostImpl::OnStatusChanged(appcache::Status status) { | 96 void WebApplicationCacheHostImpl::OnStatusChanged(appcache::Status status) { |
| 94 // TODO(michaeln): delete me, not used | 97 // TODO(michaeln): delete me, not used |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 web_resources[i].isExplicit = resource_infos[i].is_explicit; | 319 web_resources[i].isExplicit = resource_infos[i].is_explicit; |
| 317 web_resources[i].isManifest = resource_infos[i].is_manifest; | 320 web_resources[i].isManifest = resource_infos[i].is_manifest; |
| 318 web_resources[i].isForeign = resource_infos[i].is_foreign; | 321 web_resources[i].isForeign = resource_infos[i].is_foreign; |
| 319 web_resources[i].isFallback = resource_infos[i].is_fallback; | 322 web_resources[i].isFallback = resource_infos[i].is_fallback; |
| 320 web_resources[i].url = resource_infos[i].url; | 323 web_resources[i].url = resource_infos[i].url; |
| 321 } | 324 } |
| 322 resources->swap(web_resources); | 325 resources->swap(web_resources); |
| 323 } | 326 } |
| 324 | 327 |
| 325 } // appcache namespace | 328 } // appcache namespace |
| OLD | NEW |