OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/local_data_container.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/memory/linked_ptr.h" | |
9 #include "chrome/browser/browsing_data_cookie_helper.h" | |
10 #include "chrome/browser/browsing_data_server_bound_cert_helper.h" | |
11 #include "chrome/browser/content_settings/cookie_settings.h" | |
12 #include "chrome/browser/cookies_tree_model.h" | |
13 #include "net/cookies/canonical_cookie.h" | |
14 | |
15 /////////////////////////////////////////////////////////////////////////////// | |
16 // LocalDataContainer, public: | |
17 | |
18 LocalDataContainer::LocalDataContainer( | |
19 const std::string& app_name, | |
20 const std::string& app_id, | |
21 BrowsingDataCookieHelper* cookie_helper, | |
22 BrowsingDataDatabaseHelper* database_helper, | |
23 BrowsingDataLocalStorageHelper* local_storage_helper, | |
24 BrowsingDataLocalStorageHelper* session_storage_helper, | |
25 BrowsingDataAppCacheHelper* appcache_helper, | |
26 BrowsingDataIndexedDBHelper* indexed_db_helper, | |
27 BrowsingDataFileSystemHelper* file_system_helper, | |
28 BrowsingDataQuotaHelper* quota_helper, | |
29 BrowsingDataServerBoundCertHelper* server_bound_cert_helper) | |
30 : app_name_(app_name), | |
31 app_id_(app_id), | |
32 appcache_helper_(appcache_helper), | |
33 cookie_helper_(cookie_helper), | |
34 database_helper_(database_helper), | |
35 local_storage_helper_(local_storage_helper), | |
36 session_storage_helper_(session_storage_helper), | |
37 indexed_db_helper_(indexed_db_helper), | |
38 file_system_helper_(file_system_helper), | |
39 quota_helper_(quota_helper), | |
40 server_bound_cert_helper_(server_bound_cert_helper), | |
41 model_(NULL), | |
42 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {} | |
43 | |
44 LocalDataContainer::~LocalDataContainer() {} | |
45 | |
46 void LocalDataContainer::Init(CookiesTreeModel* model) { | |
47 DCHECK(!model_); | |
48 model_ = model; | |
49 | |
50 DCHECK(cookie_helper_); | |
51 cookie_helper_->StartFetching( | |
52 base::Bind(&LocalDataContainer::OnCookiesModelInfoLoaded, | |
53 weak_ptr_factory_.GetWeakPtr())); | |
54 | |
55 if (database_helper_) { | |
56 database_helper_->StartFetching( | |
57 base::Bind(&LocalDataContainer::OnDatabaseModelInfoLoaded, | |
58 weak_ptr_factory_.GetWeakPtr())); | |
59 } | |
60 | |
61 if (local_storage_helper_) { | |
62 local_storage_helper_->StartFetching( | |
63 base::Bind(&LocalDataContainer::OnLocalStorageModelInfoLoaded, | |
64 weak_ptr_factory_.GetWeakPtr())); | |
65 } | |
66 | |
67 if (session_storage_helper_) { | |
68 session_storage_helper_->StartFetching( | |
69 base::Bind(&LocalDataContainer::OnSessionStorageModelInfoLoaded, | |
70 weak_ptr_factory_.GetWeakPtr())); | |
71 } | |
72 | |
73 // TODO(michaeln): When all of the UI implementations have been updated, make | |
74 // this a required parameter. | |
75 if (appcache_helper_) { | |
76 appcache_helper_->StartFetching( | |
77 base::Bind(&LocalDataContainer::OnAppCacheModelInfoLoaded, | |
78 weak_ptr_factory_.GetWeakPtr())); | |
79 } | |
80 | |
81 if (indexed_db_helper_) { | |
82 indexed_db_helper_->StartFetching( | |
83 base::Bind(&LocalDataContainer::OnIndexedDBModelInfoLoaded, | |
84 weak_ptr_factory_.GetWeakPtr())); | |
85 } | |
86 | |
87 if (file_system_helper_) { | |
88 file_system_helper_->StartFetching( | |
89 base::Bind(&LocalDataContainer::OnFileSystemModelInfoLoaded, | |
90 weak_ptr_factory_.GetWeakPtr())); | |
91 } | |
92 | |
93 if (quota_helper_) { | |
94 quota_helper_->StartFetching( | |
95 base::Bind(&LocalDataContainer::OnQuotaModelInfoLoaded, | |
96 weak_ptr_factory_.GetWeakPtr())); | |
97 } | |
98 | |
99 if (server_bound_cert_helper_) { | |
100 server_bound_cert_helper_->StartFetching( | |
101 base::Bind(&LocalDataContainer::OnServerBoundCertModelInfoLoaded, | |
102 weak_ptr_factory_.GetWeakPtr())); | |
103 } | |
104 } | |
105 | |
106 void LocalDataContainer::OnAppCacheModelInfoLoaded() { | |
107 using appcache::AppCacheInfo; | |
108 using appcache::AppCacheInfoCollection; | |
109 using appcache::AppCacheInfoVector; | |
110 typedef std::map<GURL, AppCacheInfoVector> InfoByOrigin; | |
111 | |
112 scoped_refptr<AppCacheInfoCollection> appcache_info = | |
113 appcache_helper_->info_collection(); | |
114 if (!appcache_info || appcache_info->infos_by_origin.empty()) | |
115 return; | |
116 | |
117 for (InfoByOrigin::const_iterator origin = | |
118 appcache_info->infos_by_origin.begin(); | |
119 origin != appcache_info->infos_by_origin.end(); ++origin) { | |
120 std::list<AppCacheInfo>& info_list = appcache_info_[origin->first]; | |
121 info_list.insert( | |
122 info_list.begin(), origin->second.begin(), origin->second.end()); | |
123 } | |
124 | |
125 model_->PopulateAppCacheInfo(this); | |
126 } | |
127 | |
128 void LocalDataContainer::OnCookiesModelInfoLoaded( | |
129 const net::CookieList& cookie_list) { | |
130 cookie_list_.insert(cookie_list_.begin(), | |
131 cookie_list.begin(), | |
132 cookie_list.end()); | |
133 DCHECK(model_); | |
134 model_->PopulateCookieInfo(this); | |
135 } | |
136 | |
137 void LocalDataContainer::OnDatabaseModelInfoLoaded( | |
138 const DatabaseInfoList& database_info) { | |
139 database_info_list_ = database_info; | |
140 DCHECK(model_); | |
141 model_->PopulateDatabaseInfo(this); | |
142 } | |
143 | |
144 void LocalDataContainer::OnLocalStorageModelInfoLoaded( | |
145 const LocalStorageInfoList& local_storage_info) { | |
146 local_storage_info_list_ = local_storage_info; | |
147 DCHECK(model_); | |
148 model_->PopulateLocalStorageInfo(this); | |
149 } | |
150 | |
151 void LocalDataContainer::OnSessionStorageModelInfoLoaded( | |
152 const LocalStorageInfoList& session_storage_info) { | |
153 session_storage_info_list_ = session_storage_info; | |
154 DCHECK(model_); | |
155 model_->PopulateSessionStorageInfo(this); | |
156 } | |
157 | |
158 void LocalDataContainer::OnIndexedDBModelInfoLoaded( | |
159 const IndexedDBInfoList& indexed_db_info) { | |
160 indexed_db_info_list_ = indexed_db_info; | |
161 DCHECK(model_); | |
162 model_->PopulateIndexedDBInfo(this); | |
163 } | |
164 | |
165 void LocalDataContainer::OnFileSystemModelInfoLoaded( | |
166 const FileSystemInfoList& file_system_info) { | |
167 file_system_info_list_ = file_system_info; | |
168 DCHECK(model_); | |
169 model_->PopulateFileSystemInfo(this); | |
170 } | |
171 | |
172 void LocalDataContainer::OnQuotaModelInfoLoaded( | |
173 const QuotaInfoList& quota_info) { | |
174 quota_info_list_ = quota_info; | |
175 DCHECK(model_); | |
176 model_->PopulateQuotaInfo(this); | |
177 } | |
178 | |
179 void LocalDataContainer::OnServerBoundCertModelInfoLoaded( | |
180 const ServerBoundCertList& cert_list) { | |
181 server_bound_cert_list_ = cert_list; | |
182 DCHECK(model_); | |
183 model_->PopulateServerBoundCertInfo(this); | |
184 } | |
OLD | NEW |