Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(940)

Side by Side Diff: webkit/appcache/web_application_cache_host_impl.cc

Issue 5682008: Make members of Singleton<T> private and only visible to the singleton type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
11 #include "base/singleton.h"
12 #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" 12 #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
13 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" 13 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
14 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" 14 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
15 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" 15 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
16 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" 16 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
17 17
18 using WebKit::WebApplicationCacheHost; 18 using WebKit::WebApplicationCacheHost;
19 using WebKit::WebApplicationCacheHostClient; 19 using WebKit::WebApplicationCacheHostClient;
20 using WebKit::WebDataSource; 20 using WebKit::WebDataSource;
21 using WebKit::WebFrame; 21 using WebKit::WebFrame;
22 using WebKit::WebURLRequest; 22 using WebKit::WebURLRequest;
23 using WebKit::WebURL; 23 using WebKit::WebURL;
24 using WebKit::WebURLResponse; 24 using WebKit::WebURLResponse;
25 using WebKit::WebVector; 25 using WebKit::WebVector;
26 26
27 namespace appcache { 27 namespace appcache {
28 28
29 namespace { 29 namespace {
30 30
31 typedef IDMap<WebApplicationCacheHostImpl> HostsMap; 31 typedef IDMap<WebApplicationCacheHostImpl> HostsMap;
32 static base::LazyInstance<HostsMap> g_hosts_map(base::LINKER_INITIALIZED);
32 33
33 // Note: the order of the elements in this array must match those 34 // Note: the order of the elements in this array must match those
34 // of the EventID enum in appcache_interfaces.h. 35 // of the EventID enum in appcache_interfaces.h.
35 const char* kEventNames[] = { 36 const char* kEventNames[] = {
36 "Checking", "Error", "NoUpdate", "Downloading", "Progress", 37 "Checking", "Error", "NoUpdate", "Downloading", "Progress",
37 "UpdateReady", "Cached", "Obsolete" 38 "UpdateReady", "Cached", "Obsolete"
38 }; 39 };
39 40
40 GURL ClearUrlRef(const GURL& url) { 41 GURL ClearUrlRef(const GURL& url) {
41 if (!url.has_ref()) 42 if (!url.has_ref())
42 return url; 43 return url;
43 GURL::Replacements replacements; 44 GURL::Replacements replacements;
44 replacements.ClearRef(); 45 replacements.ClearRef();
45 return url.ReplaceComponents(replacements); 46 return url.ReplaceComponents(replacements);
46 } 47 }
47 48
48 HostsMap* all_hosts() {
49 return Singleton<HostsMap>::get();
50 }
51
52 } // anon namespace 49 } // anon namespace
53 50
54 WebApplicationCacheHostImpl* WebApplicationCacheHostImpl::FromId(int id) { 51 WebApplicationCacheHostImpl* WebApplicationCacheHostImpl::FromId(int id) {
55 return all_hosts()->Lookup(id); 52 return g_hosts_map.Get().Lookup(id);
56 } 53 }
57 54
58 WebApplicationCacheHostImpl* WebApplicationCacheHostImpl::FromFrame( 55 WebApplicationCacheHostImpl* WebApplicationCacheHostImpl::FromFrame(
59 WebFrame* frame) { 56 WebFrame* frame) {
60 if (!frame) 57 if (!frame)
61 return NULL; 58 return NULL;
62 WebDataSource* data_source = frame->dataSource(); 59 WebDataSource* data_source = frame->dataSource();
63 if (!data_source) 60 if (!data_source)
64 return NULL; 61 return NULL;
65 return static_cast<WebApplicationCacheHostImpl*> 62 return static_cast<WebApplicationCacheHostImpl*>
66 (data_source->applicationCacheHost()); 63 (data_source->applicationCacheHost());
67 } 64 }
68 65
69 WebApplicationCacheHostImpl::WebApplicationCacheHostImpl( 66 WebApplicationCacheHostImpl::WebApplicationCacheHostImpl(
70 WebApplicationCacheHostClient* client, 67 WebApplicationCacheHostClient* client,
71 AppCacheBackend* backend) 68 AppCacheBackend* backend)
72 : client_(client), 69 : client_(client),
73 backend_(backend), 70 backend_(backend),
74 ALLOW_THIS_IN_INITIALIZER_LIST(host_id_(all_hosts()->Add(this))), 71 ALLOW_THIS_IN_INITIALIZER_LIST(host_id_(g_hosts_map.Get().Add(this))),
75 has_status_(false), 72 has_status_(false),
76 status_(UNCACHED), 73 status_(UNCACHED),
77 has_cached_status_(false), 74 has_cached_status_(false),
78 cached_status_(UNCACHED), 75 cached_status_(UNCACHED),
79 is_scheme_supported_(false), 76 is_scheme_supported_(false),
80 is_get_method_(false), 77 is_get_method_(false),
81 is_new_master_entry_(MAYBE) { 78 is_new_master_entry_(MAYBE) {
82 DCHECK(client && backend && (host_id_ != kNoHostId)); 79 DCHECK(client && backend && (host_id_ != kNoHostId));
83 80
84 backend_->RegisterHost(host_id_); 81 backend_->RegisterHost(host_id_);
85 } 82 }
86 83
87 WebApplicationCacheHostImpl::~WebApplicationCacheHostImpl() { 84 WebApplicationCacheHostImpl::~WebApplicationCacheHostImpl() {
88 backend_->UnregisterHost(host_id_); 85 backend_->UnregisterHost(host_id_);
89 all_hosts()->Remove(host_id_); 86 g_hosts_map.Get().Remove(host_id_);
90 } 87 }
91 88
92 void WebApplicationCacheHostImpl::OnCacheSelected( 89 void WebApplicationCacheHostImpl::OnCacheSelected(
93 const appcache::AppCacheInfo& info) { 90 const appcache::AppCacheInfo& info) {
94 status_ = info.status; 91 status_ = info.status;
95 has_status_ = true; 92 has_status_ = true;
96 cache_info_ = info; 93 cache_info_ = info;
97 client_->didChangeCacheAssociation(); 94 client_->didChangeCacheAssociation();
98 } 95 }
99 96
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 307
311 bool WebApplicationCacheHostImpl::swapCache() { 308 bool WebApplicationCacheHostImpl::swapCache() {
312 // Cache status will change when cache is swapped. Clear out any saved idea 309 // Cache status will change when cache is swapped. Clear out any saved idea
313 // of status so that backend will be queried for actual status. 310 // of status so that backend will be queried for actual status.
314 has_status_ = false; 311 has_status_ = false;
315 has_cached_status_ = false; 312 has_cached_status_ = false;
316 return backend_->SwapCache(host_id_); 313 return backend_->SwapCache(host_id_);
317 } 314 }
318 315
319 } // appcache namespace 316 } // appcache namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698