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

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

Issue 7491085: Revert 95607 - Adding usage entry to chrome://settings/cookies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
51 // Encodes a pointer value into a hex string. 44 // Encodes a pointer value into a hex string.
52 std::string PointerToHexString(const void* pointer) { 45 std::string PointerToHexString(const void* pointer) {
53 return base::HexEncode(&pointer, sizeof(pointer)); 46 return base::HexEncode(&pointer, sizeof(pointer));
54 } 47 }
55 48
56 // Decodes a pointer from a hex string. 49 // Decodes a pointer from a hex string.
57 void* HexStringToPointer(const std::string& str) { 50 void* HexStringToPointer(const std::string& str) {
58 std::vector<uint8> buffer; 51 std::vector<uint8> buffer;
59 if (!base::HexStringToBytes(str, &buffer) || 52 if (!base::HexStringToBytes(str, &buffer) ||
60 buffer.size() != sizeof(void*)) { 53 buffer.size() != sizeof(void*)) {
61 return NULL; 54 return NULL;
62 } 55 }
63 56
64 return *reinterpret_cast<void**>(&buffer[0]); 57 return *reinterpret_cast<void**>(&buffer[0]);
65 } 58 }
66 59
67 } // namespace 60 } // namespace
68 61
69 namespace cookies_tree_model_util { 62 namespace cookies_tree_model_util {
70 63
71 std::string GetTreeNodeId(CookieTreeNode* node) { 64 std::string GetTreeNodeId(CookieTreeNode* node) {
72 return PointerToHexString(node); 65 return PointerToHexString(node);
73 } 66 }
74 67
75 bool GetCookieTreeNodeDictionary(const CookieTreeNode& node, 68 void GetCookieTreeNodeDictionary(const CookieTreeNode& node,
76 DictionaryValue* dict) { 69 DictionaryValue* dict) {
77 // Use node's address as an id for WebUI to look it up. 70 // Use node's address as an id for WebUI to look it up.
78 dict->SetString(kKeyId, PointerToHexString(&node)); 71 dict->SetString(kKeyId, PointerToHexString(&node));
79 dict->SetString(kKeyTitle, node.GetTitle()); 72 dict->SetString(kKeyTitle, node.GetTitle());
80 dict->SetBoolean(kKeyHasChildren, !node.empty()); 73 dict->SetBoolean(kKeyHasChildren, !node.empty());
81 74
82 switch (node.GetDetailedInfo().node_type) { 75 switch (node.GetDetailedInfo().node_type) {
83 case CookieTreeNode::DetailedInfo::TYPE_ORIGIN: { 76 case CookieTreeNode::DetailedInfo::TYPE_ORIGIN: {
84 dict->SetString(kKeyType, "origin"); 77 dict->SetString(kKeyType, "origin");
85 #if defined(OS_MACOSX) 78 #if defined(OS_MACOSX)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 l10n_util::GetStringUTF8( 183 l10n_util::GetStringUTF8(
191 IDS_COOKIES_FILE_SYSTEM_USAGE_NONE)); 184 IDS_COOKIES_FILE_SYSTEM_USAGE_NONE));
192 dict->SetString(kKeyTemporary, 185 dict->SetString(kKeyTemporary,
193 file_system_info.has_temporary ? 186 file_system_info.has_temporary ?
194 UTF16ToUTF8(ui::FormatBytes( 187 UTF16ToUTF8(ui::FormatBytes(
195 file_system_info.usage_temporary)) : 188 file_system_info.usage_temporary)) :
196 l10n_util::GetStringUTF8( 189 l10n_util::GetStringUTF8(
197 IDS_COOKIES_FILE_SYSTEM_USAGE_NONE)); 190 IDS_COOKIES_FILE_SYSTEM_USAGE_NONE));
198 break; 191 break;
199 } 192 }
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 }
223 default: 193 default:
224 #if defined(OS_MACOSX) 194 #if defined(OS_MACOSX)
225 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER"); 195 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER");
226 #endif 196 #endif
227 break; 197 break;
228 } 198 }
229 return true;
230 } 199 }
231 200
232 void GetChildNodeList(CookieTreeNode* parent, int start, int count, 201 void GetChildNodeList(CookieTreeNode* parent, int start, int count,
233 ListValue* nodes) { 202 ListValue* nodes) {
234 for (int i = 0; i < count; ++i) { 203 for (int i = 0; i < count; ++i) {
235 DictionaryValue* dict = new DictionaryValue; 204 DictionaryValue* dict = new DictionaryValue;
236 CookieTreeNode* child = parent->GetChild(start + i); 205 CookieTreeNode* child = parent->GetChild(start + i);
237 if (GetCookieTreeNodeDictionary(*child, dict)) 206 GetCookieTreeNodeDictionary(*child, dict);
238 nodes->Append(dict); 207 nodes->Append(dict);
239 else
240 delete dict;
241 } 208 }
242 } 209 }
243 210
244 CookieTreeNode* GetTreeNodeFromPath(CookieTreeNode* root, 211 CookieTreeNode* GetTreeNodeFromPath(CookieTreeNode* root,
245 const std::string& path) { 212 const std::string& path) {
246 std::vector<std::string> node_ids; 213 std::vector<std::string> node_ids;
247 base::SplitString(path, ',', &node_ids); 214 base::SplitString(path, ',', &node_ids);
248 215
249 CookieTreeNode* child = NULL; 216 CookieTreeNode* child = NULL;
250 CookieTreeNode* parent = root; 217 CookieTreeNode* parent = root;
251 int child_index = -1; 218 int child_index = -1;
252 219
253 // Validate the tree path and get the node pointer. 220 // Validate the tree path and get the node pointer.
254 for (size_t i = 0; i < node_ids.size(); ++i) { 221 for (size_t i = 0; i < node_ids.size(); ++i) {
255 child = reinterpret_cast<CookieTreeNode*>( 222 child = reinterpret_cast<CookieTreeNode*>(
256 HexStringToPointer(node_ids[i])); 223 HexStringToPointer(node_ids[i]));
257 224
258 child_index = parent->GetIndexOf(child); 225 child_index = parent->GetIndexOf(child);
259 if (child_index == -1) 226 if (child_index == -1)
260 break; 227 break;
261 228
262 parent = child; 229 parent = child;
263 } 230 }
264 231
265 return child_index >= 0 ? child : NULL; 232 return child_index >= 0 ? child : NULL;
266 } 233 }
267 234
268 } // namespace cookies_tree_model_util 235 } // 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