| OLD | NEW |
| 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/cookies_tree_model_util.h" | 5 #include "chrome/browser/ui/webui/cookies_tree_model_util.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 if (iter != node_map_.end()) | 83 if (iter != node_map_.end()) |
| 84 return base::IntToString(iter->second); | 84 return base::IntToString(iter->second); |
| 85 | 85 |
| 86 int32_t new_id = id_map_.Add(node); | 86 int32_t new_id = id_map_.Add(node); |
| 87 node_map_[node] = new_id; | 87 node_map_[node] = new_id; |
| 88 return base::IntToString(new_id); | 88 return base::IntToString(new_id); |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary( | 91 bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary( |
| 92 const CookieTreeNode& node, | 92 const CookieTreeNode& node, |
| 93 bool include_quota_nodes, |
| 93 base::DictionaryValue* dict) { | 94 base::DictionaryValue* dict) { |
| 94 // Use node's address as an id for WebUI to look it up. | 95 // Use node's address as an id for WebUI to look it up. |
| 95 dict->SetString(kKeyId, GetTreeNodeId(&node)); | 96 dict->SetString(kKeyId, GetTreeNodeId(&node)); |
| 96 dict->SetString(kKeyTitle, node.GetTitle()); | 97 dict->SetString(kKeyTitle, node.GetTitle()); |
| 97 dict->SetBoolean(kKeyHasChildren, !node.empty()); | 98 dict->SetBoolean(kKeyHasChildren, !node.empty()); |
| 98 | 99 |
| 99 switch (node.GetDetailedInfo().node_type) { | 100 switch (node.GetDetailedInfo().node_type) { |
| 100 case CookieTreeNode::DetailedInfo::TYPE_HOST: { | 101 case CookieTreeNode::DetailedInfo::TYPE_HOST: { |
| 101 dict->SetString(kKeyType, "origin"); | 102 dict->SetString(kKeyType, "origin"); |
| 102 #if defined(OS_MACOSX) | 103 #if defined(OS_MACOSX) |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 : l10n_util::GetStringUTF8(IDS_COOKIES_FILE_SYSTEM_USAGE_NONE)); | 210 : l10n_util::GetStringUTF8(IDS_COOKIES_FILE_SYSTEM_USAGE_NONE)); |
| 210 dict->SetString( | 211 dict->SetString( |
| 211 kKeyTemporary, | 212 kKeyTemporary, |
| 212 base::ContainsKey(file_system_info.usage_map, kTemp) | 213 base::ContainsKey(file_system_info.usage_map, kTemp) |
| 213 ? base::UTF16ToUTF8(ui::FormatBytes( | 214 ? base::UTF16ToUTF8(ui::FormatBytes( |
| 214 file_system_info.usage_map.find(kTemp)->second)) | 215 file_system_info.usage_map.find(kTemp)->second)) |
| 215 : l10n_util::GetStringUTF8(IDS_COOKIES_FILE_SYSTEM_USAGE_NONE)); | 216 : l10n_util::GetStringUTF8(IDS_COOKIES_FILE_SYSTEM_USAGE_NONE)); |
| 216 break; | 217 break; |
| 217 } | 218 } |
| 218 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: { | 219 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: { |
| 220 if (!include_quota_nodes) |
| 221 return false; |
| 222 |
| 219 dict->SetString(kKeyType, "quota"); | 223 dict->SetString(kKeyType, "quota"); |
| 220 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON"); | 224 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON"); |
| 221 | 225 |
| 222 const BrowsingDataQuotaHelper::QuotaInfo& quota_info = | 226 const BrowsingDataQuotaHelper::QuotaInfo& quota_info = |
| 223 *node.GetDetailedInfo().quota_info; | 227 *node.GetDetailedInfo().quota_info; |
| 224 if (quota_info.temporary_usage + quota_info.persistent_usage <= | 228 if (quota_info.temporary_usage + quota_info.persistent_usage <= |
| 225 kNegligibleUsage) | 229 kNegligibleUsage) |
| 226 return false; | 230 return false; |
| 227 | 231 |
| 228 dict->SetString(kKeyOrigin, quota_info.host); | 232 dict->SetString(kKeyOrigin, quota_info.host); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 dict->Set(kKeyAppsProtectingThis, app_infos); | 322 dict->Set(kKeyAppsProtectingThis, app_infos); |
| 319 } | 323 } |
| 320 #endif | 324 #endif |
| 321 | 325 |
| 322 return true; | 326 return true; |
| 323 } | 327 } |
| 324 | 328 |
| 325 void CookiesTreeModelUtil::GetChildNodeList(const CookieTreeNode* parent, | 329 void CookiesTreeModelUtil::GetChildNodeList(const CookieTreeNode* parent, |
| 326 int start, | 330 int start, |
| 327 int count, | 331 int count, |
| 332 bool include_quota_nodes, |
| 328 base::ListValue* nodes) { | 333 base::ListValue* nodes) { |
| 329 for (int i = 0; i < count; ++i) { | 334 for (int i = 0; i < count; ++i) { |
| 330 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 335 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 331 const CookieTreeNode* child = parent->GetChild(start + i); | 336 const CookieTreeNode* child = parent->GetChild(start + i); |
| 332 if (GetCookieTreeNodeDictionary(*child, dict.get())) | 337 if (GetCookieTreeNodeDictionary(*child, include_quota_nodes, dict.get())) |
| 333 nodes->Append(std::move(dict)); | 338 nodes->Append(std::move(dict)); |
| 334 } | 339 } |
| 335 } | 340 } |
| 336 | 341 |
| 337 const CookieTreeNode* CookiesTreeModelUtil::GetTreeNodeFromPath( | 342 const CookieTreeNode* CookiesTreeModelUtil::GetTreeNodeFromPath( |
| 338 const CookieTreeNode* root, | 343 const CookieTreeNode* root, |
| 339 const std::string& path) { | 344 const std::string& path) { |
| 340 const CookieTreeNode* child = NULL; | 345 const CookieTreeNode* child = NULL; |
| 341 const CookieTreeNode* parent = root; | 346 const CookieTreeNode* parent = root; |
| 342 int child_index = -1; | 347 int child_index = -1; |
| 343 | 348 |
| 344 // Validate the tree path and get the node pointer. | 349 // Validate the tree path and get the node pointer. |
| 345 for (const base::StringPiece& cur_node : base::SplitStringPiece( | 350 for (const base::StringPiece& cur_node : base::SplitStringPiece( |
| 346 path, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { | 351 path, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 347 int32_t node_id = 0; | 352 int32_t node_id = 0; |
| 348 if (!base::StringToInt(cur_node, &node_id)) | 353 if (!base::StringToInt(cur_node, &node_id)) |
| 349 break; | 354 break; |
| 350 | 355 |
| 351 child = id_map_.Lookup(node_id); | 356 child = id_map_.Lookup(node_id); |
| 352 child_index = parent->GetIndexOf(child); | 357 child_index = parent->GetIndexOf(child); |
| 353 if (child_index == -1) | 358 if (child_index == -1) |
| 354 break; | 359 break; |
| 355 | 360 |
| 356 parent = child; | 361 parent = child; |
| 357 } | 362 } |
| 358 | 363 |
| 359 return child_index >= 0 ? child : NULL; | 364 return child_index >= 0 ? child : NULL; |
| 360 } | 365 } |
| OLD | NEW |