Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / browsing_data / local_data_container.cc
blobd1189dcff6b9f83e5129f6510d6ac4d452e10901
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 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) {
47 DCHECK(!model_);
48 model_ = model;
50 batches_started_ = 1;
51 DCHECK(cookie_helper_.get());
52 cookie_helper_->StartFetching(
53 base::Bind(&LocalDataContainer::OnCookiesModelInfoLoaded,
54 weak_ptr_factory_.GetWeakPtr()));
56 if (database_helper_.get()) {
57 batches_started_++;
58 database_helper_->StartFetching(
59 base::Bind(&LocalDataContainer::OnDatabaseModelInfoLoaded,
60 weak_ptr_factory_.GetWeakPtr()));
63 if (local_storage_helper_.get()) {
64 batches_started_++;
65 local_storage_helper_->StartFetching(
66 base::Bind(&LocalDataContainer::OnLocalStorageModelInfoLoaded,
67 weak_ptr_factory_.GetWeakPtr()));
70 if (session_storage_helper_.get()) {
71 batches_started_++;
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()) {
80 batches_started_++;
81 appcache_helper_->StartFetching(
82 base::Bind(&LocalDataContainer::OnAppCacheModelInfoLoaded,
83 weak_ptr_factory_.GetWeakPtr()));
86 if (indexed_db_helper_.get()) {
87 batches_started_++;
88 indexed_db_helper_->StartFetching(
89 base::Bind(&LocalDataContainer::OnIndexedDBModelInfoLoaded,
90 weak_ptr_factory_.GetWeakPtr()));
93 if (file_system_helper_.get()) {
94 batches_started_++;
95 file_system_helper_->StartFetching(
96 base::Bind(&LocalDataContainer::OnFileSystemModelInfoLoaded,
97 weak_ptr_factory_.GetWeakPtr()));
100 if (quota_helper_.get()) {
101 batches_started_++;
102 quota_helper_->StartFetching(
103 base::Bind(&LocalDataContainer::OnQuotaModelInfoLoaded,
104 weak_ptr_factory_.GetWeakPtr()));
107 if (channel_id_helper_.get()) {
108 batches_started_++;
109 channel_id_helper_->StartFetching(
110 base::Bind(&LocalDataContainer::OnChannelIDModelInfoLoaded,
111 weak_ptr_factory_.GetWeakPtr()));
114 if (service_worker_helper_.get()) {
115 batches_started_++;
116 service_worker_helper_->StartFetching(
117 base::Bind(&LocalDataContainer::OnServiceWorkerModelInfoLoaded,
118 weak_ptr_factory_.GetWeakPtr()));
121 if (cache_storage_helper_.get()) {
122 batches_started_++;
123 cache_storage_helper_->StartFetching(
124 base::Bind(&LocalDataContainer::OnCacheStorageModelInfoLoaded,
125 weak_ptr_factory_.GetWeakPtr()));
128 if (flash_lso_helper_.get()) {
129 batches_started_++;
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);
147 return;
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(),
162 cookie_list.begin(),
163 cookie_list.end());
164 DCHECK(model_);
165 model_->PopulateCookieInfo(this);
168 void LocalDataContainer::OnDatabaseModelInfoLoaded(
169 const DatabaseInfoList& database_info) {
170 database_info_list_ = database_info;
171 DCHECK(model_);
172 model_->PopulateDatabaseInfo(this);
175 void LocalDataContainer::OnLocalStorageModelInfoLoaded(
176 const LocalStorageInfoList& local_storage_info) {
177 local_storage_info_list_ = local_storage_info;
178 DCHECK(model_);
179 model_->PopulateLocalStorageInfo(this);
182 void LocalDataContainer::OnSessionStorageModelInfoLoaded(
183 const LocalStorageInfoList& session_storage_info) {
184 session_storage_info_list_ = session_storage_info;
185 DCHECK(model_);
186 model_->PopulateSessionStorageInfo(this);
189 void LocalDataContainer::OnIndexedDBModelInfoLoaded(
190 const IndexedDBInfoList& indexed_db_info) {
191 indexed_db_info_list_ = indexed_db_info;
192 DCHECK(model_);
193 model_->PopulateIndexedDBInfo(this);
196 void LocalDataContainer::OnFileSystemModelInfoLoaded(
197 const FileSystemInfoList& file_system_info) {
198 file_system_info_list_ = file_system_info;
199 DCHECK(model_);
200 model_->PopulateFileSystemInfo(this);
203 void LocalDataContainer::OnQuotaModelInfoLoaded(
204 const QuotaInfoList& quota_info) {
205 quota_info_list_ = quota_info;
206 DCHECK(model_);
207 model_->PopulateQuotaInfo(this);
210 void LocalDataContainer::OnChannelIDModelInfoLoaded(
211 const ChannelIDList& channel_id_list) {
212 channel_id_list_ = channel_id_list;
213 DCHECK(model_);
214 model_->PopulateChannelIDInfo(this);
217 void LocalDataContainer::OnServiceWorkerModelInfoLoaded(
218 const ServiceWorkerUsageInfoList& service_worker_info) {
219 service_worker_info_list_ = service_worker_info;
220 DCHECK(model_);
221 model_->PopulateServiceWorkerUsageInfo(this);
224 void LocalDataContainer::OnCacheStorageModelInfoLoaded(
225 const CacheStorageUsageInfoList& cache_storage_info) {
226 cache_storage_info_list_ = cache_storage_info;
227 DCHECK(model_);
228 model_->PopulateCacheStorageUsageInfo(this);
231 void LocalDataContainer::OnFlashLSOInfoLoaded(
232 const FlashLSODomainList& domains) {
233 flash_lso_domain_list_ = domains;
234 DCHECK(model_);
235 model_->PopulateFlashLSOInfo(this);