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

Unified Diff: net/websockets/websocket_throttle.cc

Issue 12033072: Include destination port for websocket throttling. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix things caught by toyoshim. Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/websockets/websocket_throttle.h ('k') | net/websockets/websocket_throttle_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/websockets/websocket_throttle.cc
diff --git a/net/websockets/websocket_throttle.cc b/net/websockets/websocket_throttle.cc
index 61b408621c05dbe0cced5d938b0b9469a52dca02..3b3a6ce55e15e79c9ac8beec738438f613e05587 100644
--- a/net/websockets/websocket_throttle.cc
+++ b/net/websockets/websocket_throttle.cc
@@ -4,10 +4,10 @@
#include "net/websockets/websocket_throttle.h"
+#include <algorithm>
+#include <set>
#include <string>
-#include "base/hash_tables.h"
-#include "base/memory/ref_counted.h"
#include "base/memory/singleton.h"
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
@@ -19,13 +19,6 @@
namespace net {
-static std::string IPEndPointToHashkey(const IPEndPoint& endpoint) {
- return base::StringPrintf("%d:%s",
- endpoint.GetFamily(),
- base::HexEncode(&endpoint.address()[0],
- endpoint.address().size()).c_str());
-}
-
WebSocketThrottle::WebSocketThrottle() {
}
@@ -42,70 +35,56 @@ WebSocketThrottle* WebSocketThrottle::GetInstance() {
void WebSocketThrottle::PutInQueue(WebSocketJob* job) {
queue_.push_back(job);
const AddressList& address_list = job->address_list();
- base::hash_set<std::string> address_set;
+ std::set<IPEndPoint> address_set;
for (AddressList::const_iterator addr_iter = address_list.begin();
addr_iter != address_list.end();
++addr_iter) {
- std::string addrkey = IPEndPointToHashkey(*addr_iter);
-
- // If |addrkey| is already processed, don't do it again.
- if (address_set.find(addrkey) != address_set.end())
+ const IPEndPoint& address = *addr_iter;
+ // If |address| is already processed, don't do it again.
+ if (!address_set.insert(address).second)
continue;
- address_set.insert(addrkey);
- ConnectingAddressMap::iterator iter = addr_map_.find(addrkey);
+ ConnectingAddressMap::iterator iter = addr_map_.find(address);
if (iter == addr_map_.end()) {
ConnectingQueue* queue = new ConnectingQueue();
queue->push_back(job);
- addr_map_[addrkey] = queue;
+ addr_map_[address] = queue;
} else {
iter->second->push_back(job);
job->SetWaiting();
- DVLOG(1) << "Waiting on " << addrkey;
+ DVLOG(1) << "Waiting on " << address.ToString();
}
}
}
void WebSocketThrottle::RemoveFromQueue(WebSocketJob* job) {
- bool in_queue = false;
- for (ConnectingQueue::iterator iter = queue_.begin();
- iter != queue_.end();
- ++iter) {
- if (*iter == job) {
- queue_.erase(iter);
- in_queue = true;
- break;
- }
- }
- if (!in_queue)
+ ConnectingQueue::iterator queue_iter =
+ std::find(queue_.begin(), queue_.end(), job);
+ if (queue_iter == queue_.end())
return;
+ queue_.erase(queue_iter);
const AddressList& address_list = job->address_list();
- base::hash_set<std::string> address_set;
+ std::set<IPEndPoint> address_set;
for (AddressList::const_iterator addr_iter = address_list.begin();
addr_iter != address_list.end();
++addr_iter) {
- std::string addrkey = IPEndPointToHashkey(*addr_iter);
- // If |addrkey| is already processed, don't do it again.
- if (address_set.find(addrkey) != address_set.end())
+ const IPEndPoint& address = *addr_iter;
+ // If |address| is already processed, don't do it again.
+ if (!address_set.insert(address).second)
continue;
- address_set.insert(addrkey);
- ConnectingAddressMap::iterator iter = addr_map_.find(addrkey);
- DCHECK(iter != addr_map_.end());
+ ConnectingAddressMap::iterator map_iter = addr_map_.find(address);
+ DCHECK(map_iter != addr_map_.end());
- ConnectingQueue* queue = iter->second;
- // Job may not be front of queue when job is closed early while waiting.
- for (ConnectingQueue::iterator iter = queue->begin();
- iter != queue->end();
- ++iter) {
- if (*iter == job) {
- queue->erase(iter);
- break;
- }
- }
+ ConnectingQueue* queue = map_iter->second;
+ // Job may not be front of queue if the socket is closed while waiting.
+ ConnectingQueue::iterator address_queue_iter =
+ std::find(queue->begin(), queue->end(), job);
+ if (address_queue_iter != queue->end())
+ queue->erase(address_queue_iter);
if (queue->empty()) {
delete queue;
- addr_map_.erase(iter);
+ addr_map_.erase(map_iter);
}
}
}
@@ -123,10 +102,10 @@ void WebSocketThrottle::WakeupSocketIfNecessary() {
for (AddressList::const_iterator addr_iter = address_list.begin();
addr_iter != address_list.end();
++addr_iter) {
- std::string addrkey = IPEndPointToHashkey(*addr_iter);
- ConnectingAddressMap::iterator iter = addr_map_.find(addrkey);
- DCHECK(iter != addr_map_.end());
- ConnectingQueue* queue = iter->second;
+ const IPEndPoint& address = *addr_iter;
+ ConnectingAddressMap::iterator map_iter = addr_map_.find(address);
+ DCHECK(map_iter != addr_map_.end());
+ ConnectingQueue* queue = map_iter->second;
if (job != queue->front()) {
should_wakeup = false;
break;
« no previous file with comments | « net/websockets/websocket_throttle.h ('k') | net/websockets/websocket_throttle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698