Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: chrome/browser/ui/webui/options2/cookies_view_handler2.cc

Issue 10536017: Refactoring CookiesTreeModel to support multiple data sources. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moving from wstring to string16. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options2/cookies_view_handler2.h" 5 #include "chrome/browser/ui/webui/options2/cookies_view_handler2.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/extension_set.h"
11 #include "chrome/browser/browsing_data_appcache_helper.h" 13 #include "chrome/browser/browsing_data_appcache_helper.h"
12 #include "chrome/browser/browsing_data_cookie_helper.h" 14 #include "chrome/browser/browsing_data_cookie_helper.h"
13 #include "chrome/browser/browsing_data_database_helper.h" 15 #include "chrome/browser/browsing_data_database_helper.h"
14 #include "chrome/browser/browsing_data_file_system_helper.h" 16 #include "chrome/browser/browsing_data_file_system_helper.h"
15 #include "chrome/browser/browsing_data_indexed_db_helper.h" 17 #include "chrome/browser/browsing_data_indexed_db_helper.h"
16 #include "chrome/browser/browsing_data_local_storage_helper.h" 18 #include "chrome/browser/browsing_data_local_storage_helper.h"
17 #include "chrome/browser/browsing_data_quota_helper.h" 19 #include "chrome/browser/browsing_data_quota_helper.h"
18 #include "chrome/browser/browsing_data_server_bound_cert_helper.h" 20 #include "chrome/browser/browsing_data_server_bound_cert_helper.h"
21 #include "chrome/browser/extensions/extension_service.h"
19 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/webui/cookies_tree_model_util.h" 23 #include "chrome/browser/ui/webui/cookies_tree_model_util.h"
21 #include "content/public/browser/web_ui.h" 24 #include "content/public/browser/web_ui.h"
22 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
23 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
24 27
25 namespace options2 { 28 namespace options2 {
26 29
27 CookiesViewHandler::CookiesViewHandler() : batch_update_(false) { 30 CookiesViewHandler::CookiesViewHandler() : batch_update_(false) {
28 } 31 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 109 }
107 110
108 void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model, 111 void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model,
109 ui::TreeModelNode* parent, 112 ui::TreeModelNode* parent,
110 int start, 113 int start,
111 int count) { 114 int count) {
112 // Skip if there is a batch update in progress. 115 // Skip if there is a batch update in progress.
113 if (batch_update_) 116 if (batch_update_)
114 return; 117 return;
115 118
119 LOG(ERROR) << "TreeNodesAdded: " << start << "|" << count;
markusheintz_ 2012/06/18 16:52:41 Please remove this line.
nasko 2012/06/18 19:59:14 Done.
120
116 CookieTreeNode* parent_node = cookies_tree_model_->AsNode(parent); 121 CookieTreeNode* parent_node = cookies_tree_model_->AsNode(parent);
117 122
118 ListValue* children = new ListValue; 123 ListValue* children = new ListValue;
119 cookies_tree_model_util::GetChildNodeList(parent_node, start, count, 124 cookies_tree_model_util::GetChildNodeList(parent_node, start, count,
120 children); 125 children);
121 126
122 ListValue args; 127 ListValue args;
123 args.Append(parent == cookies_tree_model_->GetRoot() ? 128 args.Append(parent == cookies_tree_model_->GetRoot() ?
124 Value::CreateNullValue() : 129 Value::CreateNullValue() :
125 Value::CreateStringValue( 130 Value::CreateStringValue(
126 cookies_tree_model_util::GetTreeNodeId(parent_node))); 131 cookies_tree_model_util::GetTreeNodeId(parent_node)));
127 args.Append(Value::CreateIntegerValue(start)); 132 args.Append(Value::CreateIntegerValue(start));
128 args.Append(children); 133 args.Append(children);
134
135 LOG(ERROR) << "TreeNodesAdded: " <<
markusheintz_ 2012/06/18 16:52:41 Please remove these lines
nasko 2012/06/18 19:59:14 Done.
136 cookies_tree_model_util::GetTreeNodeId(parent_node) << " -> " <<
137 parent_node->child_count();
138
129 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemAdded", args); 139 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemAdded", args);
130 } 140 }
131 141
132 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, 142 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model,
133 ui::TreeModelNode* parent, 143 ui::TreeModelNode* parent,
134 int start, 144 int start,
135 int count) { 145 int count) {
136 // Skip if there is a batch update in progress. 146 // Skip if there is a batch update in progress.
137 if (batch_update_) 147 if (batch_update_)
138 return; 148 return;
139 149
150 LOG(ERROR) << "TreeNodesRemoved: " << start << "|" << count;
markusheintz_ 2012/06/18 16:52:41 Please rm
nasko 2012/06/18 19:59:14 Done.
151
140 ListValue args; 152 ListValue args;
141 args.Append(parent == cookies_tree_model_->GetRoot() ? 153 args.Append(parent == cookies_tree_model_->GetRoot() ?
142 Value::CreateNullValue() : 154 Value::CreateNullValue() :
143 Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId( 155 Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId(
144 cookies_tree_model_->AsNode(parent)))); 156 cookies_tree_model_->AsNode(parent))));
145 args.Append(Value::CreateIntegerValue(start)); 157 args.Append(Value::CreateIntegerValue(start));
146 args.Append(Value::CreateIntegerValue(count)); 158 args.Append(Value::CreateIntegerValue(count));
147 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemRemoved", args); 159 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemRemoved", args);
148 } 160 }
149 161
150 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { 162 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) {
151 DCHECK(!batch_update_); // There should be no nested batch begin. 163 DCHECK(!batch_update_); // There should be no nested batch begin.
152 batch_update_ = true; 164 batch_update_ = true;
165 LOG(ERROR) << "TreeModelBeginBatch";
markusheintz_ 2012/06/18 16:52:41 Please rm.
nasko 2012/06/18 19:59:14 Done.
153 } 166 }
154 167
155 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) { 168 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) {
156 DCHECK(batch_update_); 169 DCHECK(batch_update_);
157 batch_update_ = false; 170 batch_update_ = false;
158 171
172 LOG(ERROR) << "TreeModelEndBatch";
markusheintz_ 2012/06/18 16:52:41 Please rm.
nasko 2012/06/18 19:59:14 Done.
159 SendChildren(cookies_tree_model_->GetRoot()); 173 SendChildren(cookies_tree_model_->GetRoot());
160 } 174 }
161 175
162 void CookiesViewHandler::EnsureCookiesTreeModelCreated() { 176 void CookiesViewHandler::EnsureCookiesTreeModelCreated() {
163 if (!cookies_tree_model_.get()) { 177 if (!cookies_tree_model_.get()) {
164 Profile* profile = Profile::FromWebUI(web_ui()); 178 Profile* profile = Profile::FromWebUI(web_ui());
165 cookies_tree_model_.reset(new CookiesTreeModel( 179 string16 name = ASCIIToUTF16("Browser-wide");
markusheintz_ 2012/06/18 16:52:41 You use "Site-Data" as name in other places. Pleas
nasko 2012/06/18 19:59:14 In the other cases, it is UI only for a single sit
markusheintz_ 2012/06/19 20:01:34 I think it is fine to use "Site-data", since we al
180 string16 browser_id;
181
182 ContainerMap apps_map;
183 LocalDataContainer* container;
184
185 container = new LocalDataContainer(
markusheintz_ 2012/06/18 16:52:41 nit: I think you can just say: apps_map[browser_id
nasko 2012/06/18 19:59:14 Done.
186 name, browser_id,
166 new BrowsingDataCookieHelper(profile->GetRequestContext()), 187 new BrowsingDataCookieHelper(profile->GetRequestContext()),
167 new BrowsingDataDatabaseHelper(profile), 188 new BrowsingDataDatabaseHelper(profile),
168 new BrowsingDataLocalStorageHelper(profile), 189 new BrowsingDataLocalStorageHelper(profile),
169 NULL, 190 NULL,
170 new BrowsingDataAppCacheHelper(profile), 191 new BrowsingDataAppCacheHelper(profile),
171 BrowsingDataIndexedDBHelper::Create(profile), 192 BrowsingDataIndexedDBHelper::Create(profile),
172 BrowsingDataFileSystemHelper::Create(profile), 193 BrowsingDataFileSystemHelper::Create(profile),
173 BrowsingDataQuotaHelper::Create(profile), 194 BrowsingDataQuotaHelper::Create(profile),
174 BrowsingDataServerBoundCertHelper::Create(profile), 195 BrowsingDataServerBoundCertHelper::Create(profile));
175 false)); 196 apps_map[browser_id] = container;
197
198 const ExtensionService* service = profile->GetExtensionService();
199 if (service) {
200 string16 id;
markusheintz_ 2012/06/18 16:52:41 nit: I think you call this app_id every where else
nasko 2012/06/18 19:59:14 Done.
201 const ExtensionSet* extensions = service->extensions();
202 for (ExtensionSet::const_iterator it = extensions->begin();
203 it != extensions->end(); ++it) {
markusheintz_ 2012/06/18 16:52:41 Indent one space.
nasko 2012/06/18 19:59:14 Done.
204 if ((*it)->is_storage_isolated()) {
205 net::URLRequestContextGetter* context_getter =
206 profile->GetRequestContextForIsolatedApp((*it)->id());
207 name = ASCIIToUTF16((*it)->name());
208 id = ASCIIToUTF16((*it)->id());
209 container = new LocalDataContainer(
markusheintz_ 2012/06/18 16:52:41 nit: Same as above: I think you can just say: app
nasko 2012/06/18 19:59:14 Done.
210 name, id,
211 new BrowsingDataCookieHelper(context_getter),
212 new BrowsingDataDatabaseHelper(profile),
213 new BrowsingDataLocalStorageHelper(profile),
214 NULL,
215 new BrowsingDataAppCacheHelper(profile),
216 BrowsingDataIndexedDBHelper::Create(profile),
217 BrowsingDataFileSystemHelper::Create(profile),
218 BrowsingDataQuotaHelper::Create(profile),
219 BrowsingDataServerBoundCertHelper::Create(profile));
220 apps_map[id] = container;
221 }
222 }
223 }
224 cookies_tree_model_.reset(new CookiesTreeModel(apps_map, false));
176 cookies_tree_model_->AddCookiesTreeObserver(this); 225 cookies_tree_model_->AddCookiesTreeObserver(this);
177 } 226 }
178 } 227 }
179 228
180 void CookiesViewHandler::UpdateSearchResults(const ListValue* args) { 229 void CookiesViewHandler::UpdateSearchResults(const ListValue* args) {
181 std::string query; 230 string16 query;
182 if (!args->GetString(0, &query)) { 231 if (!args->GetString(0, &query)) {
183 return; 232 return;
184 } 233 }
185 234
186 EnsureCookiesTreeModelCreated(); 235 EnsureCookiesTreeModelCreated();
187 236
188 cookies_tree_model_->UpdateSearchResults(UTF8ToWide(query)); 237 LOG(ERROR) << "UpdateSearchResults";
markusheintz_ 2012/06/18 16:52:41 Please rm.
nasko 2012/06/18 19:59:14 Done.
238
239 cookies_tree_model_->UpdateSearchResults(query);
189 } 240 }
190 241
191 void CookiesViewHandler::RemoveAll(const ListValue* args) { 242 void CookiesViewHandler::RemoveAll(const ListValue* args) {
192 EnsureCookiesTreeModelCreated(); 243 EnsureCookiesTreeModelCreated();
193 cookies_tree_model_->DeleteAllStoredObjects(); 244 LOG(ERROR) << "RemoveAll";
markusheintz_ 2012/06/18 16:52:41 Please rm.
nasko 2012/06/18 19:59:14 Done.
245 // TODO(nasko): This will only remove the browser stored data, not the
246 // isolated apps data. This is fine for now, but should be changed based
247 // on the new isolated storage UI.
248 cookies_tree_model_->DeleteStoredObjectsForApp(string16());
194 } 249 }
195 250
196 void CookiesViewHandler::Remove(const ListValue* args) { 251 void CookiesViewHandler::Remove(const ListValue* args) {
197 std::string node_path; 252 std::string node_path;
198 if (!args->GetString(0, &node_path)) { 253 if (!args->GetString(0, &node_path)) {
199 return; 254 return;
200 } 255 }
201 256
202 EnsureCookiesTreeModelCreated(); 257 EnsureCookiesTreeModelCreated();
203 258
204 CookieTreeNode* node = cookies_tree_model_util::GetTreeNodeFromPath( 259 CookieTreeNode* node = cookies_tree_model_util::GetTreeNodeFromPath(
205 cookies_tree_model_->GetRoot(), node_path); 260 cookies_tree_model_->GetRoot(), node_path);
261 LOG(ERROR) << "RemoveChildren: " << node_path << "|" << node;
markusheintz_ 2012/06/18 16:52:41 Please rm.
nasko 2012/06/18 19:59:14 Done.
206 if (node) 262 if (node)
207 cookies_tree_model_->DeleteCookieNode(node); 263 cookies_tree_model_->DeleteCookieNode(node);
208 } 264 }
209 265
210 void CookiesViewHandler::LoadChildren(const ListValue* args) { 266 void CookiesViewHandler::LoadChildren(const ListValue* args) {
211 std::string node_path; 267 std::string node_path;
212 if (!args->GetString(0, &node_path)) { 268 if (!args->GetString(0, &node_path)) {
213 return; 269 return;
214 } 270 }
215 271
216 EnsureCookiesTreeModelCreated(); 272 EnsureCookiesTreeModelCreated();
217 273
218 CookieTreeNode* node = cookies_tree_model_util::GetTreeNodeFromPath( 274 CookieTreeNode* node = cookies_tree_model_util::GetTreeNodeFromPath(
219 cookies_tree_model_->GetRoot(), node_path); 275 cookies_tree_model_->GetRoot(), node_path);
276
277 LOG(ERROR) << "LoadChildren: " << node_path << "|" << node;
markusheintz_ 2012/06/18 16:52:41 Please rm.
nasko 2012/06/18 19:59:14 Done.
278
220 if (node) 279 if (node)
221 SendChildren(node); 280 SendChildren(node);
222 } 281 }
223 282
224 void CookiesViewHandler::SendChildren(CookieTreeNode* parent) { 283 void CookiesViewHandler::SendChildren(CookieTreeNode* parent) {
225 ListValue* children = new ListValue; 284 ListValue* children = new ListValue;
226 cookies_tree_model_util::GetChildNodeList(parent, 0, parent->child_count(), 285 cookies_tree_model_util::GetChildNodeList(parent, 0, parent->child_count(),
227 children); 286 children);
228 287
288 LOG(ERROR) << "SendChildren: " <<
markusheintz_ 2012/06/18 16:52:41 Please rm.
nasko 2012/06/18 19:59:14 Done.
289 cookies_tree_model_util::GetTreeNodeId(parent) << " -> " <<
290 parent->child_count();
291
229 ListValue args; 292 ListValue args;
230 args.Append(parent == cookies_tree_model_->GetRoot() ? 293 args.Append(parent == cookies_tree_model_->GetRoot() ?
231 Value::CreateNullValue() : 294 Value::CreateNullValue() :
232 Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId(parent))); 295 Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId(parent)));
233 args.Append(children); 296 args.Append(children);
234 297
235 web_ui()->CallJavascriptFunction("CookiesView.loadChildren", args); 298 web_ui()->CallJavascriptFunction("CookiesView.loadChildren", args);
236 } 299 }
237 300
238 } // namespace options2 301 } // namespace options2
OLDNEW
« chrome/browser/cookies_tree_model.cc ('K') | « chrome/browser/ui/webui/cookies_tree_model_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698