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

Side by Side Diff: chrome/browser/browsing_data/cookies_tree_model.cc

Issue 1408063003: Cleanup and optimizing switch using fall through. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing nit. Created 5 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/browsing_data/cookies_tree_model.h" 5 #include "chrome/browser/browsing_data/cookies_tree_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 replacements.ClearPort(); 126 replacements.ClearPort();
127 if (url.SchemeIsCryptographic()) 127 if (url.SchemeIsCryptographic())
128 replacements.SetScheme("http", url::Component(0, 4)); 128 replacements.SetScheme("http", url::Component(0, 4));
129 129
130 return url.GetOrigin().ReplaceComponents(replacements); 130 return url.GetOrigin().ReplaceComponents(replacements);
131 } 131 }
132 132
133 #if defined(ENABLE_EXTENSIONS) 133 #if defined(ENABLE_EXTENSIONS)
134 bool TypeIsProtected(CookieTreeNode::DetailedInfo::NodeType type) { 134 bool TypeIsProtected(CookieTreeNode::DetailedInfo::NodeType type) {
135 switch (type) { 135 switch (type) {
136 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: 136 // Fall through each below cases to return true.
137 return false;
138 case CookieTreeNode::DetailedInfo::TYPE_DATABASE: 137 case CookieTreeNode::DetailedInfo::TYPE_DATABASE:
139 return true;
140 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: 138 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE:
141 return true;
142 case CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE: 139 case CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE:
143 return true;
144 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE: 140 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE:
145 return true;
146 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: 141 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB:
147 return true;
148 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: 142 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM:
149 return true;
150 case CookieTreeNode::DetailedInfo::TYPE_QUOTA:
151 return false;
152 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID:
153 return false;
154 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: 143 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER:
155 return true;
156 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE: 144 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE:
157 return true; 145 return true;
146
147 // Fall through each below cases to return false.
148 case CookieTreeNode::DetailedInfo::TYPE_COOKIE:
149 case CookieTreeNode::DetailedInfo::TYPE_QUOTA:
150 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID:
158 case CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO: 151 case CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO:
159 return false; 152 return false;
160 default: 153 default:
161 break; 154 break;
162 } 155 }
163 return false; 156 return false;
164 } 157 }
165 #endif 158 #endif
166 159
167 // This function returns the local data container associated with a leaf tree 160 // This function returns the local data container associated with a leaf tree
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 287
295 void CookieTreeNode::DeleteStoredObjects() { 288 void CookieTreeNode::DeleteStoredObjects() {
296 std::for_each(children().begin(), 289 std::for_each(children().begin(),
297 children().end(), 290 children().end(),
298 std::mem_fun(&CookieTreeNode::DeleteStoredObjects)); 291 std::mem_fun(&CookieTreeNode::DeleteStoredObjects));
299 } 292 }
300 293
301 CookiesTreeModel* CookieTreeNode::GetModel() const { 294 CookiesTreeModel* CookieTreeNode::GetModel() const {
302 if (parent()) 295 if (parent())
303 return parent()->GetModel(); 296 return parent()->GetModel();
304 else 297 return nullptr;
305 return nullptr;
306 } 298 }
307 299
308 /////////////////////////////////////////////////////////////////////////////// 300 ///////////////////////////////////////////////////////////////////////////////
309 // CookieTreeCookieNode, public: 301 // CookieTreeCookieNode, public:
310 302
311 CookieTreeCookieNode::CookieTreeCookieNode( 303 CookieTreeCookieNode::CookieTreeCookieNode(
312 std::list<net::CanonicalCookie>::iterator cookie) 304 std::list<net::CanonicalCookie>::iterator cookie)
313 : CookieTreeNode(base::UTF8ToUTF16(cookie->Name())), 305 : CookieTreeNode(base::UTF8ToUTF16(cookie->Name())),
314 cookie_(cookie) { 306 cookie_(cookie) {
315 } 307 }
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 } 1016 }
1025 1017
1026 // Returns the index of the icon to use for |node|. Return -1 to use the 1018 // Returns the index of the icon to use for |node|. Return -1 to use the
1027 // default icon. The index is relative to the list of icons returned from 1019 // default icon. The index is relative to the list of icons returned from
1028 // GetIcons. 1020 // GetIcons.
1029 int CookiesTreeModel::GetIconIndex(ui::TreeModelNode* node) { 1021 int CookiesTreeModel::GetIconIndex(ui::TreeModelNode* node) {
1030 CookieTreeNode* ct_node = static_cast<CookieTreeNode*>(node); 1022 CookieTreeNode* ct_node = static_cast<CookieTreeNode*>(node);
1031 switch (ct_node->GetDetailedInfo().node_type) { 1023 switch (ct_node->GetDetailedInfo().node_type) {
1032 case CookieTreeNode::DetailedInfo::TYPE_HOST: 1024 case CookieTreeNode::DetailedInfo::TYPE_HOST:
1033 return ORIGIN; 1025 return ORIGIN;
1026
1027 // Fall through each below cases to return COOKIE.
1034 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: 1028 case CookieTreeNode::DetailedInfo::TYPE_COOKIE:
1029 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID:
1035 return COOKIE; 1030 return COOKIE;
1031
1032 // Fall through each below cases to return DATABASE.
1036 case CookieTreeNode::DetailedInfo::TYPE_DATABASE: 1033 case CookieTreeNode::DetailedInfo::TYPE_DATABASE:
1034 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE:
1035 case CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE:
1036 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE:
1037 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB:
1038 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM:
1039 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER:
1040 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE:
1037 return DATABASE; 1041 return DATABASE;
1038 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE:
1039 return DATABASE; // close enough
1040 case CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE:
1041 return DATABASE; // ditto
1042 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE:
1043 return DATABASE; // ditto
1044 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB:
1045 return DATABASE; // ditto
1046 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM:
1047 return DATABASE; // ditto
1048 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: 1042 case CookieTreeNode::DetailedInfo::TYPE_QUOTA:
1049 return -1; 1043 return -1;
1050 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID:
1051 return COOKIE; // It's kinda like a cookie?
1052 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER:
1053 return DATABASE; // Just like appcache
1054 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE:
1055 return DATABASE; // ditto
1056 default: 1044 default:
1057 break; 1045 break;
1058 } 1046 }
1059 return -1; 1047 return -1;
1060 } 1048 }
1061 1049
1062 void CookiesTreeModel::DeleteAllStoredObjects() { 1050 void CookiesTreeModel::DeleteAllStoredObjects() {
1063 NotifyObserverBeginBatch(); 1051 NotifyObserverBeginBatch();
1064 CookieTreeNode* root = GetRoot(); 1052 CookieTreeNode* root = GetRoot();
1065 root->DeleteStoredObjects(); 1053 root->DeleteStoredObjects();
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 void CookiesTreeModel::MaybeNotifyBatchesEnded() { 1543 void CookiesTreeModel::MaybeNotifyBatchesEnded() {
1556 // Only notify the observers if this is the outermost call to EndBatch() if 1544 // Only notify the observers if this is the outermost call to EndBatch() if
1557 // called in a nested manner. 1545 // called in a nested manner.
1558 if (batches_ended_ == batches_started_ && 1546 if (batches_ended_ == batches_started_ &&
1559 batches_seen_ == batches_expected_) { 1547 batches_seen_ == batches_expected_) {
1560 FOR_EACH_OBSERVER(Observer, 1548 FOR_EACH_OBSERVER(Observer,
1561 cookies_observer_list_, 1549 cookies_observer_list_,
1562 TreeModelEndBatch(this)); 1550 TreeModelEndBatch(this));
1563 } 1551 }
1564 } 1552 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698