Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / browsing_data / local_data_container.cc
bloba4e8058b9dd0ee8328a59ba3fbc6258c70ba33ef
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 "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),
41 model_(NULL),
42 weak_ptr_factory_(this) {
45 LocalDataContainer::~LocalDataContainer() {}
47 void LocalDataContainer::Init(CookiesTreeModel* model) {
48 DCHECK(!model_);
49 model_ = 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()) {
57 database_helper_->StartFetching(
58 base::Bind(&LocalDataContainer::OnDatabaseModelInfoLoaded,
59 weak_ptr_factory_.GetWeakPtr()));
62 if (local_storage_helper_.get()) {
63 local_storage_helper_->StartFetching(
64 base::Bind(&LocalDataContainer::OnLocalStorageModelInfoLoaded,
65 weak_ptr_factory_.GetWeakPtr()));
68 if (session_storage_helper_.get()) {
69 session_storage_helper_->StartFetching(
70 base::Bind(&LocalDataContainer::OnSessionStorageModelInfoLoaded,
71 weak_ptr_factory_.GetWeakPtr()));
74 // TODO(michaeln): When all of the UI implementations have been updated, make
75 // this a required parameter.
76 if (appcache_helper_.get()) {
77 appcache_helper_->StartFetching(
78 base::Bind(&LocalDataContainer::OnAppCacheModelInfoLoaded,
79 weak_ptr_factory_.GetWeakPtr()));
82 if (indexed_db_helper_.get()) {
83 indexed_db_helper_->StartFetching(
84 base::Bind(&LocalDataContainer::OnIndexedDBModelInfoLoaded,
85 weak_ptr_factory_.GetWeakPtr()));
88 if (file_system_helper_.get()) {
89 file_system_helper_->StartFetching(
90 base::Bind(&LocalDataContainer::OnFileSystemModelInfoLoaded,
91 weak_ptr_factory_.GetWeakPtr()));
94 if (quota_helper_.get()) {
95 quota_helper_->StartFetching(
96 base::Bind(&LocalDataContainer::OnQuotaModelInfoLoaded,
97 weak_ptr_factory_.GetWeakPtr()));
100 if (channel_id_helper_.get()) {
101 channel_id_helper_->StartFetching(
102 base::Bind(&LocalDataContainer::OnChannelIDModelInfoLoaded,
103 weak_ptr_factory_.GetWeakPtr()));
106 if (service_worker_helper_.get()) {
107 service_worker_helper_->StartFetching(
108 base::Bind(&LocalDataContainer::OnServiceWorkerModelInfoLoaded,
109 weak_ptr_factory_.GetWeakPtr()));
112 if (flash_lso_helper_.get()) {
113 flash_lso_helper_->StartFetching(
114 base::Bind(&LocalDataContainer::OnFlashLSOInfoLoaded,
115 weak_ptr_factory_.GetWeakPtr()));
119 void LocalDataContainer::OnAppCacheModelInfoLoaded() {
120 using content::AppCacheInfo;
121 using content::AppCacheInfoCollection;
122 using content::AppCacheInfoVector;
123 typedef std::map<GURL, AppCacheInfoVector> InfoByOrigin;
125 scoped_refptr<AppCacheInfoCollection> appcache_info =
126 appcache_helper_->info_collection();
127 if (!appcache_info.get() || appcache_info->infos_by_origin.empty())
128 return;
130 for (InfoByOrigin::const_iterator origin =
131 appcache_info->infos_by_origin.begin();
132 origin != appcache_info->infos_by_origin.end(); ++origin) {
133 std::list<AppCacheInfo>& info_list = appcache_info_[origin->first];
134 info_list.insert(
135 info_list.begin(), origin->second.begin(), origin->second.end());
138 model_->PopulateAppCacheInfo(this);
141 void LocalDataContainer::OnCookiesModelInfoLoaded(
142 const net::CookieList& cookie_list) {
143 cookie_list_.insert(cookie_list_.begin(),
144 cookie_list.begin(),
145 cookie_list.end());
146 DCHECK(model_);
147 model_->PopulateCookieInfo(this);
150 void LocalDataContainer::OnDatabaseModelInfoLoaded(
151 const DatabaseInfoList& database_info) {
152 database_info_list_ = database_info;
153 DCHECK(model_);
154 model_->PopulateDatabaseInfo(this);
157 void LocalDataContainer::OnLocalStorageModelInfoLoaded(
158 const LocalStorageInfoList& local_storage_info) {
159 local_storage_info_list_ = local_storage_info;
160 DCHECK(model_);
161 model_->PopulateLocalStorageInfo(this);
164 void LocalDataContainer::OnSessionStorageModelInfoLoaded(
165 const LocalStorageInfoList& session_storage_info) {
166 session_storage_info_list_ = session_storage_info;
167 DCHECK(model_);
168 model_->PopulateSessionStorageInfo(this);
171 void LocalDataContainer::OnIndexedDBModelInfoLoaded(
172 const IndexedDBInfoList& indexed_db_info) {
173 indexed_db_info_list_ = indexed_db_info;
174 DCHECK(model_);
175 model_->PopulateIndexedDBInfo(this);
178 void LocalDataContainer::OnFileSystemModelInfoLoaded(
179 const FileSystemInfoList& file_system_info) {
180 file_system_info_list_ = file_system_info;
181 DCHECK(model_);
182 model_->PopulateFileSystemInfo(this);
185 void LocalDataContainer::OnQuotaModelInfoLoaded(
186 const QuotaInfoList& quota_info) {
187 quota_info_list_ = quota_info;
188 DCHECK(model_);
189 model_->PopulateQuotaInfo(this);
192 void LocalDataContainer::OnChannelIDModelInfoLoaded(
193 const ChannelIDList& channel_id_list) {
194 channel_id_list_ = channel_id_list;
195 DCHECK(model_);
196 model_->PopulateChannelIDInfo(this);
199 void LocalDataContainer::OnServiceWorkerModelInfoLoaded(
200 const ServiceWorkerUsageInfoList& service_worker_info) {
201 service_worker_info_list_ = service_worker_info;
202 DCHECK(model_);
203 model_->PopulateServiceWorkerUsageInfo(this);
206 void LocalDataContainer::OnFlashLSOInfoLoaded(
207 const FlashLSODomainList& domains) {
208 flash_lso_domain_list_ = domains;
209 DCHECK(model_);
210 model_->PopulateFlashLSOInfo(this);