Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / content_settings / local_shared_objects_container.cc
blobda2b794aa7a5cb906564e8341594489f4c4da07d
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_channel_id_helper.h"
9 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
10 #include "chrome/browser/browsing_data/browsing_data_database_helper.h"
11 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
12 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
13 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
14 #include "chrome/browser/browsing_data/browsing_data_service_worker_helper.h"
15 #include "chrome/browser/browsing_data/canonical_cookie_hash.h"
16 #include "chrome/browser/browsing_data/cookies_tree_model.h"
17 #include "chrome/browser/profiles/profile.h"
18 #include "content/public/browser/storage_partition.h"
19 #include "content/public/common/url_constants.h"
20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
21 #include "net/cookies/canonical_cookie.h"
22 #include "url/gurl.h"
24 namespace {
26 bool SameDomainOrHost(const GURL& gurl1, const GURL& gurl2) {
27 return net::registry_controlled_domains::SameDomainOrHost(
28 gurl1,
29 gurl2,
30 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
33 } // namespace
35 LocalSharedObjectsContainer::LocalSharedObjectsContainer(Profile* profile)
36 : appcaches_(new CannedBrowsingDataAppCacheHelper(profile)),
37 channel_ids_(new CannedBrowsingDataChannelIDHelper()),
38 cookies_(new CannedBrowsingDataCookieHelper(
39 profile->GetRequestContext())),
40 databases_(new CannedBrowsingDataDatabaseHelper(profile)),
41 file_systems_(new CannedBrowsingDataFileSystemHelper(profile)),
42 indexed_dbs_(new CannedBrowsingDataIndexedDBHelper(
43 content::BrowserContext::GetDefaultStoragePartition(profile)->
44 GetIndexedDBContext())),
45 local_storages_(new CannedBrowsingDataLocalStorageHelper(profile)),
46 service_workers_(new CannedBrowsingDataServiceWorkerHelper(
47 content::BrowserContext::GetDefaultStoragePartition(profile)->
48 GetServiceWorkerContext())),
49 session_storages_(new CannedBrowsingDataLocalStorageHelper(profile)) {
52 LocalSharedObjectsContainer::~LocalSharedObjectsContainer() {
55 size_t LocalSharedObjectsContainer::GetObjectCount() const {
56 size_t count = 0;
57 count += appcaches()->GetAppCacheCount();
58 count += channel_ids()->GetChannelIDCount();
59 count += cookies()->GetCookieCount();
60 count += databases()->GetDatabaseCount();
61 count += file_systems()->GetFileSystemCount();
62 count += indexed_dbs()->GetIndexedDBCount();
63 count += local_storages()->GetLocalStorageCount();
64 count += service_workers()->GetServiceWorkerCount();
65 count += session_storages()->GetLocalStorageCount();
66 return count;
69 size_t LocalSharedObjectsContainer::GetObjectCountForDomain(
70 const GURL& origin) const {
71 size_t count = 0;
73 // Count all cookies that have the same domain as the provided |origin|. This
74 // means count all cookies that has been set by a host that is not considered
75 // to be a third party regarding the domain of the provided |origin|.
76 // E.g. if the origin is "http://foo.com" then all cookies with domain foo.com,
77 // a.foo.com, b.a.foo.com or *.foo.com will be counted.
78 typedef CannedBrowsingDataCookieHelper::OriginCookieSetMap OriginCookieSetMap;
79 const OriginCookieSetMap& origin_cookies_set_map =
80 cookies()->origin_cookie_set_map();
81 for (OriginCookieSetMap::const_iterator it = origin_cookies_set_map.begin();
82 it != origin_cookies_set_map.end();
83 ++it) {
84 const canonical_cookie::CookieHashSet* cookie_list = it->second;
85 for (canonical_cookie::CookieHashSet::const_iterator cookie =
86 cookie_list->begin();
87 cookie != cookie_list->end();
88 ++cookie) {
89 // Strip leading '.'s.
90 std::string cookie_domain = cookie->Domain();
91 if (cookie_domain[0] == '.')
92 cookie_domain = cookie_domain.substr(1);
93 // The |domain_url| is only created in order to use the
94 // SameDomainOrHost method below. It does not matter which scheme is
95 // used as the scheme is ignored by the SameDomainOrHost method.
96 GURL domain_url(std::string(url::kHttpScheme) +
97 url::kStandardSchemeSeparator + cookie_domain);
98 if (SameDomainOrHost(origin, domain_url))
99 ++count;
103 // Count local storages for the domain of the given |origin|.
104 const std::set<GURL> local_storage_info =
105 local_storages()->GetLocalStorageInfo();
106 for (std::set<GURL>::const_iterator it = local_storage_info.begin();
107 it != local_storage_info.end();
108 ++it) {
109 if (SameDomainOrHost(origin, *it))
110 ++count;
113 // Count session storages for the domain of the given |origin|.
114 const std::set<GURL> urls = session_storages()->GetLocalStorageInfo();
115 for (std::set<GURL>::const_iterator it = urls.begin();
116 it != urls.end();
117 ++it) {
118 if (SameDomainOrHost(origin, *it))
119 ++count;
122 // Count indexed dbs for the domain of the given |origin|.
123 typedef CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo IndexedDBInfo;
124 const std::set<IndexedDBInfo>& indexed_db_info =
125 indexed_dbs()->GetIndexedDBInfo();
126 for (std::set<IndexedDBInfo>::const_iterator it =
127 indexed_db_info.begin();
128 it != indexed_db_info.end();
129 ++it) {
130 if (SameDomainOrHost(origin, it->origin))
131 ++count;
134 // Count service workers for the domain of the given |origin|.
135 typedef CannedBrowsingDataServiceWorkerHelper::PendingServiceWorkerUsageInfo
136 ServiceWorkerInfo;
137 const std::set<ServiceWorkerInfo>& service_worker_info =
138 service_workers()->GetServiceWorkerUsageInfo();
139 for (std::set<ServiceWorkerInfo>::const_iterator it =
140 service_worker_info.begin();
141 it != service_worker_info.end();
142 ++it) {
143 if (SameDomainOrHost(origin, it->origin))
144 ++count;
147 // Count filesystems for the domain of the given |origin|.
148 typedef BrowsingDataFileSystemHelper::FileSystemInfo FileSystemInfo;
149 typedef std::list<FileSystemInfo> FileSystemInfoList;
150 const FileSystemInfoList& file_system_info =
151 file_systems()->GetFileSystemInfo();
152 for (FileSystemInfoList::const_iterator it = file_system_info.begin();
153 it != file_system_info.end();
154 ++it) {
155 if (SameDomainOrHost(origin, it->origin))
156 ++count;
159 // Count databases for the domain of the given |origin|.
160 typedef CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo DatabaseInfo;
161 const std::set<DatabaseInfo>& database_list =
162 databases()->GetPendingDatabaseInfo();
163 for (std::set<DatabaseInfo>::const_iterator it =
164 database_list.begin();
165 it != database_list.end();
166 ++it) {
167 if (SameDomainOrHost(origin, it->origin))
168 ++count;
171 // Count the AppCache manifest files for the domain of the given |origin|.
172 typedef BrowsingDataAppCacheHelper::OriginAppCacheInfoMap
173 OriginAppCacheInfoMap;
174 const OriginAppCacheInfoMap& map = appcaches()->GetOriginAppCacheInfoMap();
175 for (OriginAppCacheInfoMap::const_iterator it = map.begin();
176 it != map.end();
177 ++it) {
178 const content::AppCacheInfoVector& info_vector = it->second;
179 for (content::AppCacheInfoVector::const_iterator info =
180 info_vector.begin();
181 info != info_vector.end();
182 ++info) {
183 if (SameDomainOrHost(origin, info->manifest_url))
184 ++count;
188 return count;
191 void LocalSharedObjectsContainer::Reset() {
192 appcaches_->Reset();
193 channel_ids_->Reset();
194 cookies_->Reset();
195 databases_->Reset();
196 file_systems_->Reset();
197 indexed_dbs_->Reset();
198 local_storages_->Reset();
199 service_workers_->Reset();
200 session_storages_->Reset();
203 scoped_ptr<CookiesTreeModel>
204 LocalSharedObjectsContainer::CreateCookiesTreeModel() const {
205 LocalDataContainer* container = new LocalDataContainer(
206 cookies(),
207 databases(),
208 local_storages(),
209 session_storages(),
210 appcaches(),
211 indexed_dbs(),
212 file_systems(),
213 NULL,
214 channel_ids(),
215 service_workers(),
216 NULL);
218 return make_scoped_ptr(new CookiesTreeModel(container, NULL, true));