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

Side by Side Diff: chrome/browser/ui/webui/cookies_tree_model_util.cc

Issue 7387007: Adding usage and quota entry to chrome://settings/cookies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed leak suppressions. Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/i18n/time_formatting.h" 7 #include "base/i18n/time_formatting.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/string_split.h" 9 #include "base/string_split.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 23 matching lines...) Expand all
34 static const char kKeyManifest[] = "manifest"; 34 static const char kKeyManifest[] = "manifest";
35 35
36 static const char kKeyAccessed[] = "accessed"; 36 static const char kKeyAccessed[] = "accessed";
37 static const char kKeyCreated[] = "created"; 37 static const char kKeyCreated[] = "created";
38 static const char kKeyExpires[] = "expires"; 38 static const char kKeyExpires[] = "expires";
39 static const char kKeyModified[] = "modified"; 39 static const char kKeyModified[] = "modified";
40 40
41 static const char kKeyPersistent[] = "persistent"; 41 static const char kKeyPersistent[] = "persistent";
42 static const char kKeyTemporary[] = "temporary"; 42 static const char kKeyTemporary[] = "temporary";
43 43
44 static const char kKeyTotalUsage[] = "totalUsage";
45 static const char kKeyTemporaryUsage[] = "temporaryUsage";
46 static const char kKeyPersistentUsage[] = "persistentUsage";
47 static const char kKeyPersistentQuota[] = "persistentQuota";
48
49 static const int64 kNegligibleUsage = 1024; // 1KiB
50
44 // Encodes a pointer value into a hex string. 51 // Encodes a pointer value into a hex string.
45 std::string PointerToHexString(const void* pointer) { 52 std::string PointerToHexString(const void* pointer) {
46 return base::HexEncode(&pointer, sizeof(pointer)); 53 return base::HexEncode(&pointer, sizeof(pointer));
47 } 54 }
48 55
49 // Decodes a pointer from a hex string. 56 // Decodes a pointer from a hex string.
50 void* HexStringToPointer(const std::string& str) { 57 void* HexStringToPointer(const std::string& str) {
51 std::vector<uint8> buffer; 58 std::vector<uint8> buffer;
52 if (!base::HexStringToBytes(str, &buffer) || 59 if (!base::HexStringToBytes(str, &buffer) ||
53 buffer.size() != sizeof(void*)) { 60 buffer.size() != sizeof(void*)) {
54 return NULL; 61 return NULL;
55 } 62 }
56 63
57 return *reinterpret_cast<void**>(&buffer[0]); 64 return *reinterpret_cast<void**>(&buffer[0]);
58 } 65 }
59 66
60 } // namespace 67 } // namespace
61 68
62 namespace cookies_tree_model_util { 69 namespace cookies_tree_model_util {
63 70
64 std::string GetTreeNodeId(CookieTreeNode* node) { 71 std::string GetTreeNodeId(CookieTreeNode* node) {
65 return PointerToHexString(node); 72 return PointerToHexString(node);
66 } 73 }
67 74
68 void GetCookieTreeNodeDictionary(const CookieTreeNode& node, 75 bool GetCookieTreeNodeDictionary(const CookieTreeNode& node,
69 DictionaryValue* dict) { 76 DictionaryValue* dict) {
70 // Use node's address as an id for WebUI to look it up. 77 // Use node's address as an id for WebUI to look it up.
71 dict->SetString(kKeyId, PointerToHexString(&node)); 78 dict->SetString(kKeyId, PointerToHexString(&node));
72 dict->SetString(kKeyTitle, node.GetTitle()); 79 dict->SetString(kKeyTitle, node.GetTitle());
73 dict->SetBoolean(kKeyHasChildren, !node.empty()); 80 dict->SetBoolean(kKeyHasChildren, !node.empty());
74 81
75 switch (node.GetDetailedInfo().node_type) { 82 switch (node.GetDetailedInfo().node_type) {
76 case CookieTreeNode::DetailedInfo::TYPE_ORIGIN: { 83 case CookieTreeNode::DetailedInfo::TYPE_ORIGIN: {
77 dict->SetString(kKeyType, "origin"); 84 dict->SetString(kKeyType, "origin");
78 #if defined(OS_MACOSX) 85 #if defined(OS_MACOSX)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 l10n_util::GetStringUTF8( 190 l10n_util::GetStringUTF8(
184 IDS_COOKIES_FILE_SYSTEM_USAGE_NONE)); 191 IDS_COOKIES_FILE_SYSTEM_USAGE_NONE));
185 dict->SetString(kKeyTemporary, 192 dict->SetString(kKeyTemporary,
186 file_system_info.has_temporary ? 193 file_system_info.has_temporary ?
187 UTF16ToUTF8(ui::FormatBytes( 194 UTF16ToUTF8(ui::FormatBytes(
188 file_system_info.usage_temporary)) : 195 file_system_info.usage_temporary)) :
189 l10n_util::GetStringUTF8( 196 l10n_util::GetStringUTF8(
190 IDS_COOKIES_FILE_SYSTEM_USAGE_NONE)); 197 IDS_COOKIES_FILE_SYSTEM_USAGE_NONE));
191 break; 198 break;
192 } 199 }
200 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: {
201 dict->SetString(kKeyType, "quota");
202 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON");
203
204 const BrowsingDataQuotaHelper::QuotaInfo& quota_info =
205 *node.GetDetailedInfo().quota_info;
206 if (quota_info.temporary_usage + quota_info.persistent_usage <=
207 kNegligibleUsage)
208 return false;
209
210 dict->SetString(kKeyOrigin, quota_info.host);
211 dict->SetString(kKeyTotalUsage,
212 UTF16ToUTF8(ui::FormatBytes(
213 quota_info.temporary_usage +
214 quota_info.persistent_usage)));
215 dict->SetString(kKeyTemporaryUsage,
216 UTF16ToUTF8(ui::FormatBytes(
217 quota_info.temporary_usage)));
218 dict->SetString(kKeyPersistentUsage,
219 UTF16ToUTF8(ui::FormatBytes(
220 quota_info.persistent_usage)));
221 break;
222 }
193 default: 223 default:
194 #if defined(OS_MACOSX) 224 #if defined(OS_MACOSX)
195 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER"); 225 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER");
196 #endif 226 #endif
197 break; 227 break;
198 } 228 }
229 return true;
199 } 230 }
200 231
201 void GetChildNodeList(CookieTreeNode* parent, int start, int count, 232 void GetChildNodeList(CookieTreeNode* parent, int start, int count,
202 ListValue* nodes) { 233 ListValue* nodes) {
203 for (int i = 0; i < count; ++i) { 234 for (int i = 0; i < count; ++i) {
204 DictionaryValue* dict = new DictionaryValue; 235 DictionaryValue* dict = new DictionaryValue;
205 CookieTreeNode* child = parent->GetChild(start + i); 236 CookieTreeNode* child = parent->GetChild(start + i);
206 GetCookieTreeNodeDictionary(*child, dict); 237 if (GetCookieTreeNodeDictionary(*child, dict))
207 nodes->Append(dict); 238 nodes->Append(dict);
239 else
240 delete dict;
208 } 241 }
209 } 242 }
210 243
211 CookieTreeNode* GetTreeNodeFromPath(CookieTreeNode* root, 244 CookieTreeNode* GetTreeNodeFromPath(CookieTreeNode* root,
212 const std::string& path) { 245 const std::string& path) {
213 std::vector<std::string> node_ids; 246 std::vector<std::string> node_ids;
214 base::SplitString(path, ',', &node_ids); 247 base::SplitString(path, ',', &node_ids);
215 248
216 CookieTreeNode* child = NULL; 249 CookieTreeNode* child = NULL;
217 CookieTreeNode* parent = root; 250 CookieTreeNode* parent = root;
218 int child_index = -1; 251 int child_index = -1;
219 252
220 // Validate the tree path and get the node pointer. 253 // Validate the tree path and get the node pointer.
221 for (size_t i = 0; i < node_ids.size(); ++i) { 254 for (size_t i = 0; i < node_ids.size(); ++i) {
222 child = reinterpret_cast<CookieTreeNode*>( 255 child = reinterpret_cast<CookieTreeNode*>(
223 HexStringToPointer(node_ids[i])); 256 HexStringToPointer(node_ids[i]));
224 257
225 child_index = parent->GetIndexOf(child); 258 child_index = parent->GetIndexOf(child);
226 if (child_index == -1) 259 if (child_index == -1)
227 break; 260 break;
228 261
229 parent = child; 262 parent = child;
230 } 263 }
231 264
232 return child_index >= 0 ? child : NULL; 265 return child_index >= 0 ? child : NULL;
233 } 266 }
234 267
235 } // namespace cookies_tree_model_util 268 } // namespace cookies_tree_model_util
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/cookies_tree_model_util.h ('k') | chrome/browser/ui/webui/options/cookies_view_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698