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

Side by Side Diff: components/safe_browsing_db/remote_database_manager.cc

Issue 2838163002: Use base::flat_set<> rather than std::set<> for ResourceType set (Closed)
Patch Set: Created 3 years, 8 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 | « components/safe_browsing_db/remote_database_manager.h ('k') | 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/safe_browsing_db/remote_database_manager.h" 5 #include "components/safe_browsing_db/remote_database_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // CancelCheck() will delete *this. 92 // CancelCheck() will delete *this.
93 db_manager_->CancelCheck(client_); 93 db_manager_->CancelCheck(client_);
94 } 94 }
95 95
96 // 96 //
97 // RemoteSafeBrowsingDatabaseManager methods 97 // RemoteSafeBrowsingDatabaseManager methods
98 // 98 //
99 99
100 // TODO(nparker): Add more tests for this class 100 // TODO(nparker): Add more tests for this class
101 RemoteSafeBrowsingDatabaseManager::RemoteSafeBrowsingDatabaseManager() { 101 RemoteSafeBrowsingDatabaseManager::RemoteSafeBrowsingDatabaseManager() {
102 // Adding one element at a time to a base::flat_set is inefficient. Creating
103 // the list of elements in a vector first avoids extra allocations.
104 std::vector<content::ResourceType> types_to_check;
Nathan Parker 2017/04/25 15:23:14 This seems seems like overkill for 18 elements tha
Adam Rice 2017/04/26 05:18:27 I've tried adding directly to the set in patch set
102 // Decide which resource types to check. These two are the minimum. 105 // Decide which resource types to check. These two are the minimum.
103 resource_types_to_check_.insert(content::RESOURCE_TYPE_MAIN_FRAME); 106 types_to_check.push_back(content::RESOURCE_TYPE_MAIN_FRAME);
104 resource_types_to_check_.insert(content::RESOURCE_TYPE_SUB_FRAME); 107 types_to_check.push_back(content::RESOURCE_TYPE_SUB_FRAME);
105 108
106 // The param is expected to be a comma-separated list of ints 109 // The param is expected to be a comma-separated list of ints
107 // corresponding to the enum types. We're keeping this finch 110 // corresponding to the enum types. We're keeping this finch
108 // control around so we can add back types if they later become dangerous. 111 // control around so we can add back types if they later become dangerous.
109 const std::string ints_str = variations::GetVariationParamValue( 112 const std::string ints_str = variations::GetVariationParamValue(
110 kAndroidFieldExperiment, kAndroidTypesToCheckParam); 113 kAndroidFieldExperiment, kAndroidTypesToCheckParam);
111 if (ints_str.empty()) { 114 if (ints_str.empty()) {
112 // By default, we check all types except a few. 115 // By default, we check all types except a few.
113 static_assert(content::RESOURCE_TYPE_LAST_TYPE == 116 static_assert(content::RESOURCE_TYPE_LAST_TYPE ==
114 content::RESOURCE_TYPE_PLUGIN_RESOURCE + 1, 117 content::RESOURCE_TYPE_PLUGIN_RESOURCE + 1,
115 "Decide if new resource type should be skipped on mobile."); 118 "Decide if new resource type should be skipped on mobile.");
116 for (int t_int = 0; t_int < content::RESOURCE_TYPE_LAST_TYPE; t_int++) { 119 for (int t_int = 0; t_int < content::RESOURCE_TYPE_LAST_TYPE; t_int++) {
117 content::ResourceType t = static_cast<content::ResourceType>(t_int); 120 content::ResourceType t = static_cast<content::ResourceType>(t_int);
118 switch (t) { 121 switch (t) {
119 case content::RESOURCE_TYPE_STYLESHEET: 122 case content::RESOURCE_TYPE_STYLESHEET:
120 case content::RESOURCE_TYPE_IMAGE: 123 case content::RESOURCE_TYPE_IMAGE:
121 case content::RESOURCE_TYPE_FONT_RESOURCE: 124 case content::RESOURCE_TYPE_FONT_RESOURCE:
122 case content::RESOURCE_TYPE_FAVICON: 125 case content::RESOURCE_TYPE_FAVICON:
123 break; 126 break;
124 default: 127 default:
125 resource_types_to_check_.insert(t); 128 types_to_check.push_back(t);
126 } 129 }
127 } 130 }
128 } else { 131 } else {
129 // Use the finch param. 132 // Use the finch param.
130 for (const std::string& val_str : base::SplitString( 133 for (const std::string& val_str : base::SplitString(
131 ints_str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { 134 ints_str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
132 int i; 135 int i;
133 if (base::StringToInt(val_str, &i) && i >= 0 && 136 if (base::StringToInt(val_str, &i) && i >= 0 &&
134 i < content::RESOURCE_TYPE_LAST_TYPE) { 137 i < content::RESOURCE_TYPE_LAST_TYPE) {
135 resource_types_to_check_.insert(static_cast<content::ResourceType>(i)); 138 types_to_check.push_back(static_cast<content::ResourceType>(i));
136 } 139 }
137 } 140 }
138 } 141 }
142 base::flat_set<content::ResourceType> resource_types_to_check_temporary(
143 std::move(types_to_check), base::KEEP_FIRST_OF_DUPES);
144 resource_types_to_check_.swap(resource_types_to_check_temporary);
139 } 145 }
140 146
141 RemoteSafeBrowsingDatabaseManager::~RemoteSafeBrowsingDatabaseManager() { 147 RemoteSafeBrowsingDatabaseManager::~RemoteSafeBrowsingDatabaseManager() {
142 DCHECK(!enabled_); 148 DCHECK(!enabled_);
143 } 149 }
144 150
145 void RemoteSafeBrowsingDatabaseManager::CancelCheck(Client* client) { 151 void RemoteSafeBrowsingDatabaseManager::CancelCheck(Client* client) {
146 DCHECK_CURRENTLY_ON(BrowserThread::IO); 152 DCHECK_CURRENTLY_ON(BrowserThread::IO);
147 DCHECK(enabled_); 153 DCHECK(enabled_);
148 for (auto itr = current_requests_.begin(); itr != current_requests_.end(); 154 for (auto itr = current_requests_.begin(); itr != current_requests_.end();
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 for (auto* req : to_callback) { 306 for (auto* req : to_callback) {
301 DVLOG(1) << "Stopping: Invoking unfinished req for URL " << req->url(); 307 DVLOG(1) << "Stopping: Invoking unfinished req for URL " << req->url();
302 req->OnRequestDone(SB_THREAT_TYPE_SAFE, ThreatMetadata()); 308 req->OnRequestDone(SB_THREAT_TYPE_SAFE, ThreatMetadata());
303 } 309 }
304 enabled_ = false; 310 enabled_ = false;
305 311
306 SafeBrowsingDatabaseManager::StopOnIOThread(shutdown); 312 SafeBrowsingDatabaseManager::StopOnIOThread(shutdown);
307 } 313 }
308 314
309 } // namespace safe_browsing 315 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/remote_database_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698