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/browsing_data/local_data_container.h"
8 #include "base/memory/linked_ptr.h"
9 #include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h"
10 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h"
11 #include "chrome/browser/browsing_data/cookies_tree_model.h"
12 #include "chrome/browser/content_settings/cookie_settings.h"
13 #include "net/cookies/canonical_cookie.h"
15 ///////////////////////////////////////////////////////////////////////////////
16 // LocalDataContainer, public:
18 LocalDataContainer::LocalDataContainer(
19 BrowsingDataCookieHelper
* cookie_helper
,
20 BrowsingDataDatabaseHelper
* database_helper
,
21 BrowsingDataLocalStorageHelper
* local_storage_helper
,
22 BrowsingDataLocalStorageHelper
* session_storage_helper
,
23 BrowsingDataAppCacheHelper
* appcache_helper
,
24 BrowsingDataIndexedDBHelper
* indexed_db_helper
,
25 BrowsingDataFileSystemHelper
* file_system_helper
,
26 BrowsingDataQuotaHelper
* quota_helper
,
27 BrowsingDataChannelIDHelper
* channel_id_helper
,
28 BrowsingDataServiceWorkerHelper
* service_worker_helper
,
29 BrowsingDataFlashLSOHelper
* flash_lso_helper
)
30 : appcache_helper_(appcache_helper
),
31 cookie_helper_(cookie_helper
),
32 database_helper_(database_helper
),
33 local_storage_helper_(local_storage_helper
),
34 session_storage_helper_(session_storage_helper
),
35 indexed_db_helper_(indexed_db_helper
),
36 file_system_helper_(file_system_helper
),
37 quota_helper_(quota_helper
),
38 channel_id_helper_(channel_id_helper
),
39 service_worker_helper_(service_worker_helper
),
40 flash_lso_helper_(flash_lso_helper
),
43 weak_ptr_factory_(this) {
46 LocalDataContainer::~LocalDataContainer() {}
48 void LocalDataContainer::Init(CookiesTreeModel
* model
) {
53 DCHECK(cookie_helper_
.get());
54 cookie_helper_
->StartFetching(
55 base::Bind(&LocalDataContainer::OnCookiesModelInfoLoaded
,
56 weak_ptr_factory_
.GetWeakPtr()));
58 if (database_helper_
.get()) {
60 database_helper_
->StartFetching(
61 base::Bind(&LocalDataContainer::OnDatabaseModelInfoLoaded
,
62 weak_ptr_factory_
.GetWeakPtr()));
65 if (local_storage_helper_
.get()) {
67 local_storage_helper_
->StartFetching(
68 base::Bind(&LocalDataContainer::OnLocalStorageModelInfoLoaded
,
69 weak_ptr_factory_
.GetWeakPtr()));
72 if (session_storage_helper_
.get()) {
74 session_storage_helper_
->StartFetching(
75 base::Bind(&LocalDataContainer::OnSessionStorageModelInfoLoaded
,
76 weak_ptr_factory_
.GetWeakPtr()));
79 // TODO(michaeln): When all of the UI implementations have been updated, make
80 // this a required parameter.
81 if (appcache_helper_
.get()) {
83 appcache_helper_
->StartFetching(
84 base::Bind(&LocalDataContainer::OnAppCacheModelInfoLoaded
,
85 weak_ptr_factory_
.GetWeakPtr()));
88 if (indexed_db_helper_
.get()) {
90 indexed_db_helper_
->StartFetching(
91 base::Bind(&LocalDataContainer::OnIndexedDBModelInfoLoaded
,
92 weak_ptr_factory_
.GetWeakPtr()));
95 if (file_system_helper_
.get()) {
97 file_system_helper_
->StartFetching(
98 base::Bind(&LocalDataContainer::OnFileSystemModelInfoLoaded
,
99 weak_ptr_factory_
.GetWeakPtr()));
102 if (quota_helper_
.get()) {
104 quota_helper_
->StartFetching(
105 base::Bind(&LocalDataContainer::OnQuotaModelInfoLoaded
,
106 weak_ptr_factory_
.GetWeakPtr()));
109 if (channel_id_helper_
.get()) {
111 channel_id_helper_
->StartFetching(
112 base::Bind(&LocalDataContainer::OnChannelIDModelInfoLoaded
,
113 weak_ptr_factory_
.GetWeakPtr()));
116 if (service_worker_helper_
.get()) {
118 service_worker_helper_
->StartFetching(
119 base::Bind(&LocalDataContainer::OnServiceWorkerModelInfoLoaded
,
120 weak_ptr_factory_
.GetWeakPtr()));
123 if (flash_lso_helper_
.get()) {
125 flash_lso_helper_
->StartFetching(
126 base::Bind(&LocalDataContainer::OnFlashLSOInfoLoaded
,
127 weak_ptr_factory_
.GetWeakPtr()));
130 model_
->SetBatchExpectation(batches_started_
, true);
133 void LocalDataContainer::OnAppCacheModelInfoLoaded() {
134 using content::AppCacheInfo
;
135 using content::AppCacheInfoCollection
;
136 using content::AppCacheInfoVector
;
137 typedef std::map
<GURL
, AppCacheInfoVector
> InfoByOrigin
;
139 scoped_refptr
<AppCacheInfoCollection
> appcache_info
=
140 appcache_helper_
->info_collection();
141 if (!appcache_info
.get() || appcache_info
->infos_by_origin
.empty()) {
142 // This batch has been canceled, so let the model know it won't be arriving.
143 model_
->SetBatchExpectation(--batches_started_
, false);
147 for (InfoByOrigin::const_iterator origin
=
148 appcache_info
->infos_by_origin
.begin();
149 origin
!= appcache_info
->infos_by_origin
.end(); ++origin
) {
150 std::list
<AppCacheInfo
>& info_list
= appcache_info_
[origin
->first
];
152 info_list
.begin(), origin
->second
.begin(), origin
->second
.end());
155 model_
->PopulateAppCacheInfo(this);
158 void LocalDataContainer::OnCookiesModelInfoLoaded(
159 const net::CookieList
& cookie_list
) {
160 cookie_list_
.insert(cookie_list_
.begin(),
164 model_
->PopulateCookieInfo(this);
167 void LocalDataContainer::OnDatabaseModelInfoLoaded(
168 const DatabaseInfoList
& database_info
) {
169 database_info_list_
= database_info
;
171 model_
->PopulateDatabaseInfo(this);
174 void LocalDataContainer::OnLocalStorageModelInfoLoaded(
175 const LocalStorageInfoList
& local_storage_info
) {
176 local_storage_info_list_
= local_storage_info
;
178 model_
->PopulateLocalStorageInfo(this);
181 void LocalDataContainer::OnSessionStorageModelInfoLoaded(
182 const LocalStorageInfoList
& session_storage_info
) {
183 session_storage_info_list_
= session_storage_info
;
185 model_
->PopulateSessionStorageInfo(this);
188 void LocalDataContainer::OnIndexedDBModelInfoLoaded(
189 const IndexedDBInfoList
& indexed_db_info
) {
190 indexed_db_info_list_
= indexed_db_info
;
192 model_
->PopulateIndexedDBInfo(this);
195 void LocalDataContainer::OnFileSystemModelInfoLoaded(
196 const FileSystemInfoList
& file_system_info
) {
197 file_system_info_list_
= file_system_info
;
199 model_
->PopulateFileSystemInfo(this);
202 void LocalDataContainer::OnQuotaModelInfoLoaded(
203 const QuotaInfoList
& quota_info
) {
204 quota_info_list_
= quota_info
;
206 model_
->PopulateQuotaInfo(this);
209 void LocalDataContainer::OnChannelIDModelInfoLoaded(
210 const ChannelIDList
& channel_id_list
) {
211 channel_id_list_
= channel_id_list
;
213 model_
->PopulateChannelIDInfo(this);
216 void LocalDataContainer::OnServiceWorkerModelInfoLoaded(
217 const ServiceWorkerUsageInfoList
& service_worker_info
) {
218 service_worker_info_list_
= service_worker_info
;
220 model_
->PopulateServiceWorkerUsageInfo(this);
223 void LocalDataContainer::OnFlashLSOInfoLoaded(
224 const FlashLSODomainList
& domains
) {
225 flash_lso_domain_list_
= domains
;
227 model_
->PopulateFlashLSOInfo(this);