Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / browsing_data / local_data_container.cc
blobfc82df8868e7ab55bd8233d0420dc5ea0fd565e5
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 model_(NULL),
41 batches_started_(0),
42 weak_ptr_factory_(this) {
45 LocalDataContainer::~LocalDataContainer() {}
47 void LocalDataContainer::Init(CookiesTreeModel* model) {
48 DCHECK(!model_);
49 model_ = model;
51 batches_started_ = 1;
52 DCHECK(cookie_helper_.get());
53 cookie_helper_->StartFetching(
54 base::Bind(&LocalDataContainer::OnCookiesModelInfoLoaded,
55 weak_ptr_factory_.GetWeakPtr()));
57 if (database_helper_.get()) {
58 batches_started_++;
59 database_helper_->StartFetching(
60 base::Bind(&LocalDataContainer::OnDatabaseModelInfoLoaded,
61 weak_ptr_factory_.GetWeakPtr()));
64 if (local_storage_helper_.get()) {
65 batches_started_++;
66 local_storage_helper_->StartFetching(
67 base::Bind(&LocalDataContainer::OnLocalStorageModelInfoLoaded,
68 weak_ptr_factory_.GetWeakPtr()));
71 if (session_storage_helper_.get()) {
72 batches_started_++;
73 session_storage_helper_->StartFetching(
74 base::Bind(&LocalDataContainer::OnSessionStorageModelInfoLoaded,
75 weak_ptr_factory_.GetWeakPtr()));
78 // TODO(michaeln): When all of the UI implementations have been updated, make
79 // this a required parameter.
80 if (appcache_helper_.get()) {
81 batches_started_++;
82 appcache_helper_->StartFetching(
83 base::Bind(&LocalDataContainer::OnAppCacheModelInfoLoaded,
84 weak_ptr_factory_.GetWeakPtr()));
87 if (indexed_db_helper_.get()) {
88 batches_started_++;
89 indexed_db_helper_->StartFetching(
90 base::Bind(&LocalDataContainer::OnIndexedDBModelInfoLoaded,
91 weak_ptr_factory_.GetWeakPtr()));
94 if (file_system_helper_.get()) {
95 batches_started_++;
96 file_system_helper_->StartFetching(
97 base::Bind(&LocalDataContainer::OnFileSystemModelInfoLoaded,
98 weak_ptr_factory_.GetWeakPtr()));
101 if (quota_helper_.get()) {
102 batches_started_++;
103 quota_helper_->StartFetching(
104 base::Bind(&LocalDataContainer::OnQuotaModelInfoLoaded,
105 weak_ptr_factory_.GetWeakPtr()));
108 if (channel_id_helper_.get()) {
109 batches_started_++;
110 channel_id_helper_->StartFetching(
111 base::Bind(&LocalDataContainer::OnChannelIDModelInfoLoaded,
112 weak_ptr_factory_.GetWeakPtr()));
115 if (service_worker_helper_.get()) {
116 batches_started_++;
117 service_worker_helper_->StartFetching(
118 base::Bind(&LocalDataContainer::OnServiceWorkerModelInfoLoaded,
119 weak_ptr_factory_.GetWeakPtr()));
122 if (flash_lso_helper_.get()) {
123 batches_started_++;
124 flash_lso_helper_->StartFetching(
125 base::Bind(&LocalDataContainer::OnFlashLSOInfoLoaded,
126 weak_ptr_factory_.GetWeakPtr()));
129 model_->SetBatchExpectation(batches_started_, true);
132 void LocalDataContainer::OnAppCacheModelInfoLoaded() {
133 using content::AppCacheInfo;
134 using content::AppCacheInfoCollection;
135 using content::AppCacheInfoVector;
136 typedef std::map<GURL, AppCacheInfoVector> InfoByOrigin;
138 scoped_refptr<AppCacheInfoCollection> appcache_info =
139 appcache_helper_->info_collection();
140 if (!appcache_info.get() || appcache_info->infos_by_origin.empty()) {
141 // This batch has been canceled, so let the model know it won't be arriving.
142 model_->SetBatchExpectation(--batches_started_, false);
143 return;
146 for (InfoByOrigin::const_iterator origin =
147 appcache_info->infos_by_origin.begin();
148 origin != appcache_info->infos_by_origin.end(); ++origin) {
149 std::list<AppCacheInfo>& info_list = appcache_info_[origin->first];
150 info_list.insert(
151 info_list.begin(), origin->second.begin(), origin->second.end());
154 model_->PopulateAppCacheInfo(this);
157 void LocalDataContainer::OnCookiesModelInfoLoaded(
158 const net::CookieList& cookie_list) {
159 cookie_list_.insert(cookie_list_.begin(),
160 cookie_list.begin(),
161 cookie_list.end());
162 DCHECK(model_);
163 model_->PopulateCookieInfo(this);
166 void LocalDataContainer::OnDatabaseModelInfoLoaded(
167 const DatabaseInfoList& database_info) {
168 database_info_list_ = database_info;
169 DCHECK(model_);
170 model_->PopulateDatabaseInfo(this);
173 void LocalDataContainer::OnLocalStorageModelInfoLoaded(
174 const LocalStorageInfoList& local_storage_info) {
175 local_storage_info_list_ = local_storage_info;
176 DCHECK(model_);
177 model_->PopulateLocalStorageInfo(this);
180 void LocalDataContainer::OnSessionStorageModelInfoLoaded(
181 const LocalStorageInfoList& session_storage_info) {
182 session_storage_info_list_ = session_storage_info;
183 DCHECK(model_);
184 model_->PopulateSessionStorageInfo(this);
187 void LocalDataContainer::OnIndexedDBModelInfoLoaded(
188 const IndexedDBInfoList& indexed_db_info) {
189 indexed_db_info_list_ = indexed_db_info;
190 DCHECK(model_);
191 model_->PopulateIndexedDBInfo(this);
194 void LocalDataContainer::OnFileSystemModelInfoLoaded(
195 const FileSystemInfoList& file_system_info) {
196 file_system_info_list_ = file_system_info;
197 DCHECK(model_);
198 model_->PopulateFileSystemInfo(this);
201 void LocalDataContainer::OnQuotaModelInfoLoaded(
202 const QuotaInfoList& quota_info) {
203 quota_info_list_ = quota_info;
204 DCHECK(model_);
205 model_->PopulateQuotaInfo(this);
208 void LocalDataContainer::OnChannelIDModelInfoLoaded(
209 const ChannelIDList& channel_id_list) {
210 channel_id_list_ = channel_id_list;
211 DCHECK(model_);
212 model_->PopulateChannelIDInfo(this);
215 void LocalDataContainer::OnServiceWorkerModelInfoLoaded(
216 const ServiceWorkerUsageInfoList& service_worker_info) {
217 service_worker_info_list_ = service_worker_info;
218 DCHECK(model_);
219 model_->PopulateServiceWorkerUsageInfo(this);
222 void LocalDataContainer::OnFlashLSOInfoLoaded(
223 const FlashLSODomainList& domains) {
224 flash_lso_domain_list_ = domains;
225 DCHECK(model_);
226 model_->PopulateFlashLSOInfo(this);