BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / content_settings / local_shared_objects_container.cc
blob4d3c0903f92fa4aa77dae0e93937e111362416aa
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
3 // found in the LICENSE file.
5 #include "chrome/browser/content_settings/local_shared_objects_container.h"
7 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h"
8 #include "chrome/browser/browsing_data/browsing_data_cache_storage_helper.h"
9 #include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h"
10 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
11 #include "chrome/browser/browsing_data/browsing_data_database_helper.h"
12 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
13 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
14 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
15 #include "chrome/browser/browsing_data/browsing_data_service_worker_helper.h"
16 #include "chrome/browser/browsing_data/canonical_cookie_hash.h"
17 #include "chrome/browser/browsing_data/cookies_tree_model.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "content/public/browser/storage_partition.h"
20 #include "content/public/common/url_constants.h"
21 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
22 #include "net/cookies/canonical_cookie.h"
23 #include "url/gurl.h"
25 namespace {
27 bool SameDomainOrHost(const GURL& gurl1, const GURL& gurl2) {
28 return net::registry_controlled_domains::SameDomainOrHost(
29 gurl1,
30 gurl2,
31 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
34 } // namespace
36 LocalSharedObjectsContainer::LocalSharedObjectsContainer(Profile* profile)
37 : appcaches_(new CannedBrowsingDataAppCacheHelper(profile)),
38 channel_ids_(new CannedBrowsingDataChannelIDHelper()),
39 cookies_(
40 new CannedBrowsingDataCookieHelper(profile->GetRequestContext())),
41 databases_(new CannedBrowsingDataDatabaseHelper(profile)),
42 file_systems_(new CannedBrowsingDataFileSystemHelper(profile)),
43 indexed_dbs_(new CannedBrowsingDataIndexedDBHelper(
44 content::BrowserContext::GetDefaultStoragePartition(profile)
45 ->GetIndexedDBContext())),
46 local_storages_(new CannedBrowsingDataLocalStorageHelper(profile)),
47 service_workers_(new CannedBrowsingDataServiceWorkerHelper(
48 content::BrowserContext::GetDefaultStoragePartition(profile)
49 ->GetServiceWorkerContext())),
50 cache_storages_(new CannedBrowsingDataCacheStorageHelper(
51 content::BrowserContext::GetDefaultStoragePartition(profile)
52 ->GetCacheStorageContext())),
53 session_storages_(new CannedBrowsingDataLocalStorageHelper(profile)) {}
55 LocalSharedObjectsContainer::~LocalSharedObjectsContainer() {
58 size_t LocalSharedObjectsContainer::GetObjectCount() const {
59 size_t count = 0;
60 count += appcaches()->GetAppCacheCount();
61 count += channel_ids()->GetChannelIDCount();
62 count += cookies()->GetCookieCount();
63 count += databases()->GetDatabaseCount();
64 count += file_systems()->GetFileSystemCount();
65 count += indexed_dbs()->GetIndexedDBCount();
66 count += local_storages()->GetLocalStorageCount();
67 count += service_workers()->GetServiceWorkerCount();
68 count += cache_storages()->GetCacheStorageCount();
69 count += session_storages()->GetLocalStorageCount();
70 return count;
73 size_t LocalSharedObjectsContainer::GetObjectCountForDomain(
74 const GURL& origin) const {
75 size_t count = 0;
77 // Count all cookies that have the same domain as the provided |origin|. This
78 // means count all cookies that has been set by a host that is not considered
79 // to be a third party regarding the domain of the provided |origin|.
80 // E.g. if the origin is "http://foo.com" then all cookies with domain foo.com,
81 // a.foo.com, b.a.foo.com or *.foo.com will be counted.
82 typedef CannedBrowsingDataCookieHelper::OriginCookieSetMap OriginCookieSetMap;
83 const OriginCookieSetMap& origin_cookies_set_map =
84 cookies()->origin_cookie_set_map();
85 for (OriginCookieSetMap::const_iterator it = origin_cookies_set_map.begin();
86 it != origin_cookies_set_map.end();
87 ++it) {
88 const canonical_cookie::CookieHashSet* cookie_list = it->second;
89 for (canonical_cookie::CookieHashSet::const_iterator cookie =
90 cookie_list->begin();
91 cookie != cookie_list->end();
92 ++cookie) {
93 // Strip leading '.'s.
94 std::string cookie_domain = cookie->Domain();
95 if (cookie_domain[0] == '.')
96 cookie_domain = cookie_domain.substr(1);
97 // The |domain_url| is only created in order to use the
98 // SameDomainOrHost method below. It does not matter which scheme is
99 // used as the scheme is ignored by the SameDomainOrHost method.
100 GURL domain_url(std::string(url::kHttpScheme) +
101 url::kStandardSchemeSeparator + cookie_domain);
102 if (SameDomainOrHost(origin, domain_url))
103 ++count;
107 // Count local storages for the domain of the given |origin|.
108 const std::set<GURL> local_storage_info =
109 local_storages()->GetLocalStorageInfo();
110 for (std::set<GURL>::const_iterator it = local_storage_info.begin();
111 it != local_storage_info.end();
112 ++it) {
113 if (SameDomainOrHost(origin, *it))
114 ++count;
117 // Count session storages for the domain of the given |origin|.
118 const std::set<GURL> urls = session_storages()->GetLocalStorageInfo();
119 for (std::set<GURL>::const_iterator it = urls.begin();
120 it != urls.end();
121 ++it) {
122 if (SameDomainOrHost(origin, *it))
123 ++count;
126 // Count indexed dbs for the domain of the given |origin|.
127 typedef CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo IndexedDBInfo;
128 const std::set<IndexedDBInfo>& indexed_db_info =
129 indexed_dbs()->GetIndexedDBInfo();
130 for (std::set<IndexedDBInfo>::const_iterator it =
131 indexed_db_info.begin();
132 it != indexed_db_info.end();
133 ++it) {
134 if (SameDomainOrHost(origin, it->origin))
135 ++count;
138 // Count service workers for the domain of the given |origin|.
139 typedef CannedBrowsingDataServiceWorkerHelper::PendingServiceWorkerUsageInfo
140 ServiceWorkerInfo;
141 const std::set<ServiceWorkerInfo>& service_worker_info =
142 service_workers()->GetServiceWorkerUsageInfo();
143 for (std::set<ServiceWorkerInfo>::const_iterator it =
144 service_worker_info.begin();
145 it != service_worker_info.end();
146 ++it) {
147 if (SameDomainOrHost(origin, it->origin))
148 ++count;
151 // Count cache storages for the domain of the given |origin|.
152 typedef CannedBrowsingDataCacheStorageHelper::PendingCacheStorageUsageInfo
153 CacheStorageInfo;
154 const std::set<CacheStorageInfo>& cache_storage_info =
155 cache_storages()->GetCacheStorageUsageInfo();
156 for (const CacheStorageInfo& it : cache_storage_info) {
157 if (SameDomainOrHost(origin, it.origin))
158 ++count;
161 // Count filesystems for the domain of the given |origin|.
162 typedef BrowsingDataFileSystemHelper::FileSystemInfo FileSystemInfo;
163 typedef std::list<FileSystemInfo> FileSystemInfoList;
164 const FileSystemInfoList& file_system_info =
165 file_systems()->GetFileSystemInfo();
166 for (FileSystemInfoList::const_iterator it = file_system_info.begin();
167 it != file_system_info.end();
168 ++it) {
169 if (SameDomainOrHost(origin, it->origin))
170 ++count;
173 // Count databases for the domain of the given |origin|.
174 typedef CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo DatabaseInfo;
175 const std::set<DatabaseInfo>& database_list =
176 databases()->GetPendingDatabaseInfo();
177 for (std::set<DatabaseInfo>::const_iterator it =
178 database_list.begin();
179 it != database_list.end();
180 ++it) {
181 if (SameDomainOrHost(origin, it->origin))
182 ++count;
185 // Count the AppCache manifest files for the domain of the given |origin|.
186 typedef BrowsingDataAppCacheHelper::OriginAppCacheInfoMap
187 OriginAppCacheInfoMap;
188 const OriginAppCacheInfoMap& map = appcaches()->GetOriginAppCacheInfoMap();
189 for (OriginAppCacheInfoMap::const_iterator it = map.begin();
190 it != map.end();
191 ++it) {
192 const content::AppCacheInfoVector& info_vector = it->second;
193 for (content::AppCacheInfoVector::const_iterator info =
194 info_vector.begin();
195 info != info_vector.end();
196 ++info) {
197 if (SameDomainOrHost(origin, info->manifest_url))
198 ++count;
202 return count;
205 void LocalSharedObjectsContainer::Reset() {
206 appcaches_->Reset();
207 channel_ids_->Reset();
208 cookies_->Reset();
209 databases_->Reset();
210 file_systems_->Reset();
211 indexed_dbs_->Reset();
212 local_storages_->Reset();
213 service_workers_->Reset();
214 cache_storages_->Reset();
215 session_storages_->Reset();
218 scoped_ptr<CookiesTreeModel>
219 LocalSharedObjectsContainer::CreateCookiesTreeModel() const {
220 LocalDataContainer* container = new LocalDataContainer(
221 cookies(), databases(), local_storages(), session_storages(), appcaches(),
222 indexed_dbs(), file_systems(), NULL, channel_ids(), service_workers(),
223 cache_storages(), NULL);
225 return make_scoped_ptr(new CookiesTreeModel(container, NULL, true));