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 "net/cookies/canonical_cookie.h"
14 ///////////////////////////////////////////////////////////////////////////////
15 // LocalDataContainer, public:
17 LocalDataContainer::LocalDataContainer(
18 BrowsingDataCookieHelper
* cookie_helper
,
19 BrowsingDataDatabaseHelper
* database_helper
,
20 BrowsingDataLocalStorageHelper
* local_storage_helper
,
21 BrowsingDataLocalStorageHelper
* session_storage_helper
,
22 BrowsingDataAppCacheHelper
* appcache_helper
,
23 BrowsingDataIndexedDBHelper
* indexed_db_helper
,
24 BrowsingDataFileSystemHelper
* file_system_helper
,
25 BrowsingDataQuotaHelper
* quota_helper
,
26 BrowsingDataChannelIDHelper
* channel_id_helper
,
27 BrowsingDataServiceWorkerHelper
* service_worker_helper
,
28 BrowsingDataCacheStorageHelper
* cache_storage_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 cache_storage_helper_(cache_storage_helper
),
41 flash_lso_helper_(flash_lso_helper
),
42 weak_ptr_factory_(this) {}
44 LocalDataContainer::~LocalDataContainer() {}
46 void LocalDataContainer::Init(CookiesTreeModel
* model
) {
51 DCHECK(cookie_helper_
.get());
52 cookie_helper_
->StartFetching(
53 base::Bind(&LocalDataContainer::OnCookiesModelInfoLoaded
,
54 weak_ptr_factory_
.GetWeakPtr()));
56 if (database_helper_
.get()) {
58 database_helper_
->StartFetching(
59 base::Bind(&LocalDataContainer::OnDatabaseModelInfoLoaded
,
60 weak_ptr_factory_
.GetWeakPtr()));
63 if (local_storage_helper_
.get()) {
65 local_storage_helper_
->StartFetching(
66 base::Bind(&LocalDataContainer::OnLocalStorageModelInfoLoaded
,
67 weak_ptr_factory_
.GetWeakPtr()));
70 if (session_storage_helper_
.get()) {
72 session_storage_helper_
->StartFetching(
73 base::Bind(&LocalDataContainer::OnSessionStorageModelInfoLoaded
,
74 weak_ptr_factory_
.GetWeakPtr()));
77 // TODO(michaeln): When all of the UI implementations have been updated, make
78 // this a required parameter.
79 if (appcache_helper_
.get()) {
81 appcache_helper_
->StartFetching(
82 base::Bind(&LocalDataContainer::OnAppCacheModelInfoLoaded
,
83 weak_ptr_factory_
.GetWeakPtr()));
86 if (indexed_db_helper_
.get()) {
88 indexed_db_helper_
->StartFetching(
89 base::Bind(&LocalDataContainer::OnIndexedDBModelInfoLoaded
,
90 weak_ptr_factory_
.GetWeakPtr()));
93 if (file_system_helper_
.get()) {
95 file_system_helper_
->StartFetching(
96 base::Bind(&LocalDataContainer::OnFileSystemModelInfoLoaded
,
97 weak_ptr_factory_
.GetWeakPtr()));
100 if (quota_helper_
.get()) {
102 quota_helper_
->StartFetching(
103 base::Bind(&LocalDataContainer::OnQuotaModelInfoLoaded
,
104 weak_ptr_factory_
.GetWeakPtr()));
107 if (channel_id_helper_
.get()) {
109 channel_id_helper_
->StartFetching(
110 base::Bind(&LocalDataContainer::OnChannelIDModelInfoLoaded
,
111 weak_ptr_factory_
.GetWeakPtr()));
114 if (service_worker_helper_
.get()) {
116 service_worker_helper_
->StartFetching(
117 base::Bind(&LocalDataContainer::OnServiceWorkerModelInfoLoaded
,
118 weak_ptr_factory_
.GetWeakPtr()));
121 if (cache_storage_helper_
.get()) {
123 cache_storage_helper_
->StartFetching(
124 base::Bind(&LocalDataContainer::OnCacheStorageModelInfoLoaded
,
125 weak_ptr_factory_
.GetWeakPtr()));
128 if (flash_lso_helper_
.get()) {
130 flash_lso_helper_
->StartFetching(
131 base::Bind(&LocalDataContainer::OnFlashLSOInfoLoaded
,
132 weak_ptr_factory_
.GetWeakPtr()));
135 model_
->SetBatchExpectation(batches_started_
, true);
138 void LocalDataContainer::OnAppCacheModelInfoLoaded(
139 scoped_refptr
<content::AppCacheInfoCollection
> appcache_info
) {
140 using content::AppCacheInfo
;
141 using content::AppCacheInfoCollection
;
142 using content::AppCacheInfoVector
;
144 if (!appcache_info
.get() || appcache_info
->infos_by_origin
.empty()) {
145 // This batch has been canceled, so let the model know it won't be arriving.
146 model_
->SetBatchExpectation(--batches_started_
, false);
150 for (const auto& origin
: appcache_info
->infos_by_origin
) {
151 std::list
<AppCacheInfo
>& info_list
= appcache_info_
[origin
.first
];
152 info_list
.insert(info_list
.begin(), origin
.second
.begin(),
153 origin
.second
.end());
156 model_
->PopulateAppCacheInfo(this);
159 void LocalDataContainer::OnCookiesModelInfoLoaded(
160 const net::CookieList
& cookie_list
) {
161 cookie_list_
.insert(cookie_list_
.begin(),
165 model_
->PopulateCookieInfo(this);
168 void LocalDataContainer::OnDatabaseModelInfoLoaded(
169 const DatabaseInfoList
& database_info
) {
170 database_info_list_
= database_info
;
172 model_
->PopulateDatabaseInfo(this);
175 void LocalDataContainer::OnLocalStorageModelInfoLoaded(
176 const LocalStorageInfoList
& local_storage_info
) {
177 local_storage_info_list_
= local_storage_info
;
179 model_
->PopulateLocalStorageInfo(this);
182 void LocalDataContainer::OnSessionStorageModelInfoLoaded(
183 const LocalStorageInfoList
& session_storage_info
) {
184 session_storage_info_list_
= session_storage_info
;
186 model_
->PopulateSessionStorageInfo(this);
189 void LocalDataContainer::OnIndexedDBModelInfoLoaded(
190 const IndexedDBInfoList
& indexed_db_info
) {
191 indexed_db_info_list_
= indexed_db_info
;
193 model_
->PopulateIndexedDBInfo(this);
196 void LocalDataContainer::OnFileSystemModelInfoLoaded(
197 const FileSystemInfoList
& file_system_info
) {
198 file_system_info_list_
= file_system_info
;
200 model_
->PopulateFileSystemInfo(this);
203 void LocalDataContainer::OnQuotaModelInfoLoaded(
204 const QuotaInfoList
& quota_info
) {
205 quota_info_list_
= quota_info
;
207 model_
->PopulateQuotaInfo(this);
210 void LocalDataContainer::OnChannelIDModelInfoLoaded(
211 const ChannelIDList
& channel_id_list
) {
212 channel_id_list_
= channel_id_list
;
214 model_
->PopulateChannelIDInfo(this);
217 void LocalDataContainer::OnServiceWorkerModelInfoLoaded(
218 const ServiceWorkerUsageInfoList
& service_worker_info
) {
219 service_worker_info_list_
= service_worker_info
;
221 model_
->PopulateServiceWorkerUsageInfo(this);
224 void LocalDataContainer::OnCacheStorageModelInfoLoaded(
225 const CacheStorageUsageInfoList
& cache_storage_info
) {
226 cache_storage_info_list_
= cache_storage_info
;
228 model_
->PopulateCacheStorageUsageInfo(this);
231 void LocalDataContainer::OnFlashLSOInfoLoaded(
232 const FlashLSODomainList
& domains
) {
233 flash_lso_domain_list_
= domains
;
235 model_
->PopulateFlashLSOInfo(this);