Extensions: Remove the legacy GetMessages/HasMessages
[chromium-blink-merge.git] / chrome / browser / browsing_data / local_data_container.cc
bloba2bcc705a1903f5b90b91bb5f6e9333b69f80d39
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"
7 #include "base/bind.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 BrowsingDataFlashLSOHelper* flash_lso_helper)
29 : appcache_helper_(appcache_helper),
30 cookie_helper_(cookie_helper),
31 database_helper_(database_helper),
32 local_storage_helper_(local_storage_helper),
33 session_storage_helper_(session_storage_helper),
34 indexed_db_helper_(indexed_db_helper),
35 file_system_helper_(file_system_helper),
36 quota_helper_(quota_helper),
37 channel_id_helper_(channel_id_helper),
38 service_worker_helper_(service_worker_helper),
39 flash_lso_helper_(flash_lso_helper),
40 weak_ptr_factory_(this) {}
42 LocalDataContainer::~LocalDataContainer() {}
44 void LocalDataContainer::Init(CookiesTreeModel* model) {
45 DCHECK(!model_);
46 model_ = model;
48 batches_started_ = 1;
49 DCHECK(cookie_helper_.get());
50 cookie_helper_->StartFetching(
51 base::Bind(&LocalDataContainer::OnCookiesModelInfoLoaded,
52 weak_ptr_factory_.GetWeakPtr()));
54 if (database_helper_.get()) {
55 batches_started_++;
56 database_helper_->StartFetching(
57 base::Bind(&LocalDataContainer::OnDatabaseModelInfoLoaded,
58 weak_ptr_factory_.GetWeakPtr()));
61 if (local_storage_helper_.get()) {
62 batches_started_++;
63 local_storage_helper_->StartFetching(
64 base::Bind(&LocalDataContainer::OnLocalStorageModelInfoLoaded,
65 weak_ptr_factory_.GetWeakPtr()));
68 if (session_storage_helper_.get()) {
69 batches_started_++;
70 session_storage_helper_->StartFetching(
71 base::Bind(&LocalDataContainer::OnSessionStorageModelInfoLoaded,
72 weak_ptr_factory_.GetWeakPtr()));
75 // TODO(michaeln): When all of the UI implementations have been updated, make
76 // this a required parameter.
77 if (appcache_helper_.get()) {
78 batches_started_++;
79 appcache_helper_->StartFetching(
80 base::Bind(&LocalDataContainer::OnAppCacheModelInfoLoaded,
81 weak_ptr_factory_.GetWeakPtr()));
84 if (indexed_db_helper_.get()) {
85 batches_started_++;
86 indexed_db_helper_->StartFetching(
87 base::Bind(&LocalDataContainer::OnIndexedDBModelInfoLoaded,
88 weak_ptr_factory_.GetWeakPtr()));
91 if (file_system_helper_.get()) {
92 batches_started_++;
93 file_system_helper_->StartFetching(
94 base::Bind(&LocalDataContainer::OnFileSystemModelInfoLoaded,
95 weak_ptr_factory_.GetWeakPtr()));
98 if (quota_helper_.get()) {
99 batches_started_++;
100 quota_helper_->StartFetching(
101 base::Bind(&LocalDataContainer::OnQuotaModelInfoLoaded,
102 weak_ptr_factory_.GetWeakPtr()));
105 if (channel_id_helper_.get()) {
106 batches_started_++;
107 channel_id_helper_->StartFetching(
108 base::Bind(&LocalDataContainer::OnChannelIDModelInfoLoaded,
109 weak_ptr_factory_.GetWeakPtr()));
112 if (service_worker_helper_.get()) {
113 batches_started_++;
114 service_worker_helper_->StartFetching(
115 base::Bind(&LocalDataContainer::OnServiceWorkerModelInfoLoaded,
116 weak_ptr_factory_.GetWeakPtr()));
119 if (flash_lso_helper_.get()) {
120 batches_started_++;
121 flash_lso_helper_->StartFetching(
122 base::Bind(&LocalDataContainer::OnFlashLSOInfoLoaded,
123 weak_ptr_factory_.GetWeakPtr()));
126 model_->SetBatchExpectation(batches_started_, true);
129 void LocalDataContainer::OnAppCacheModelInfoLoaded() {
130 using content::AppCacheInfo;
131 using content::AppCacheInfoCollection;
132 using content::AppCacheInfoVector;
134 scoped_refptr<AppCacheInfoCollection> appcache_info =
135 appcache_helper_->info_collection();
136 if (!appcache_info.get() || appcache_info->infos_by_origin.empty()) {
137 // This batch has been canceled, so let the model know it won't be arriving.
138 model_->SetBatchExpectation(--batches_started_, false);
139 return;
142 for (const auto& origin : appcache_info->infos_by_origin) {
143 std::list<AppCacheInfo>& info_list = appcache_info_[origin.first];
144 info_list.insert(info_list.begin(), origin.second.begin(),
145 origin.second.end());
148 model_->PopulateAppCacheInfo(this);
151 void LocalDataContainer::OnCookiesModelInfoLoaded(
152 const net::CookieList& cookie_list) {
153 cookie_list_.insert(cookie_list_.begin(),
154 cookie_list.begin(),
155 cookie_list.end());
156 DCHECK(model_);
157 model_->PopulateCookieInfo(this);
160 void LocalDataContainer::OnDatabaseModelInfoLoaded(
161 const DatabaseInfoList& database_info) {
162 database_info_list_ = database_info;
163 DCHECK(model_);
164 model_->PopulateDatabaseInfo(this);
167 void LocalDataContainer::OnLocalStorageModelInfoLoaded(
168 const LocalStorageInfoList& local_storage_info) {
169 local_storage_info_list_ = local_storage_info;
170 DCHECK(model_);
171 model_->PopulateLocalStorageInfo(this);
174 void LocalDataContainer::OnSessionStorageModelInfoLoaded(
175 const LocalStorageInfoList& session_storage_info) {
176 session_storage_info_list_ = session_storage_info;
177 DCHECK(model_);
178 model_->PopulateSessionStorageInfo(this);
181 void LocalDataContainer::OnIndexedDBModelInfoLoaded(
182 const IndexedDBInfoList& indexed_db_info) {
183 indexed_db_info_list_ = indexed_db_info;
184 DCHECK(model_);
185 model_->PopulateIndexedDBInfo(this);
188 void LocalDataContainer::OnFileSystemModelInfoLoaded(
189 const FileSystemInfoList& file_system_info) {
190 file_system_info_list_ = file_system_info;
191 DCHECK(model_);
192 model_->PopulateFileSystemInfo(this);
195 void LocalDataContainer::OnQuotaModelInfoLoaded(
196 const QuotaInfoList& quota_info) {
197 quota_info_list_ = quota_info;
198 DCHECK(model_);
199 model_->PopulateQuotaInfo(this);
202 void LocalDataContainer::OnChannelIDModelInfoLoaded(
203 const ChannelIDList& channel_id_list) {
204 channel_id_list_ = channel_id_list;
205 DCHECK(model_);
206 model_->PopulateChannelIDInfo(this);
209 void LocalDataContainer::OnServiceWorkerModelInfoLoaded(
210 const ServiceWorkerUsageInfoList& service_worker_info) {
211 service_worker_info_list_ = service_worker_info;
212 DCHECK(model_);
213 model_->PopulateServiceWorkerUsageInfo(this);
216 void LocalDataContainer::OnFlashLSOInfoLoaded(
217 const FlashLSODomainList& domains) {
218 flash_lso_domain_list_ = domains;
219 DCHECK(model_);
220 model_->PopulateFlashLSOInfo(this);