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

Unified Diff: net/socket_stream/socket_stream_throttle.cc

Issue 342052: Implement websocket throttling. (Closed)
Patch Set: Fix tyoshino's comment Created 11 years, 1 month 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/socket_stream/socket_stream_throttle.h ('k') | net/websockets/websocket_throttle.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket_stream/socket_stream_throttle.cc
diff --git a/net/socket_stream/socket_stream_throttle.cc b/net/socket_stream/socket_stream_throttle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6a1d20df692bd315d4b0c892672280e87a15946b
--- /dev/null
+++ b/net/socket_stream/socket_stream_throttle.cc
@@ -0,0 +1,80 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "net/socket_stream/socket_stream_throttle.h"
+
+#include "base/hash_tables.h"
+#include "base/singleton.h"
+#include "net/base/completion_callback.h"
+#include "net/socket_stream/socket_stream.h"
+
+namespace net {
+
+// Default SocketStreamThrottle. No throttling. Used for unknown URL scheme.
+class DefaultSocketStreamThrottle : public SocketStreamThrottle {
+ private:
+ DefaultSocketStreamThrottle() {}
+ virtual ~DefaultSocketStreamThrottle() {}
+ friend struct DefaultSingletonTraits<DefaultSocketStreamThrottle>;
+
+ DISALLOW_COPY_AND_ASSIGN(DefaultSocketStreamThrottle);
+};
+
+class SocketStreamThrottleRegistry {
+ public:
+ SocketStreamThrottle* GetSocketStreamThrottleForScheme(
+ const std::string& scheme);
+
+ void RegisterSocketStreamThrottle(
+ const std::string& scheme, SocketStreamThrottle* throttle);
+
+ private:
+ typedef base::hash_map<std::string, SocketStreamThrottle*> ThrottleMap;
+
+ SocketStreamThrottleRegistry() {}
+ ~SocketStreamThrottleRegistry() {}
+ friend struct DefaultSingletonTraits<SocketStreamThrottleRegistry>;
+
+ ThrottleMap throttles_;
+
+ DISALLOW_COPY_AND_ASSIGN(SocketStreamThrottleRegistry);
+};
+
+SocketStreamThrottle*
+SocketStreamThrottleRegistry::GetSocketStreamThrottleForScheme(
+ const std::string& scheme) {
+ ThrottleMap::const_iterator found = throttles_.find(scheme);
+ if (found == throttles_.end()) {
+ SocketStreamThrottle* throttle =
+ Singleton<DefaultSocketStreamThrottle>::get();
+ throttles_[scheme] = throttle;
+ return throttle;
+ }
+ return found->second;
+}
+
+void SocketStreamThrottleRegistry::RegisterSocketStreamThrottle(
+ const std::string& scheme, SocketStreamThrottle* throttle) {
+ throttles_[scheme] = throttle;
+}
+
+/* static */
+SocketStreamThrottle* SocketStreamThrottle::GetSocketStreamThrottleForScheme(
+ const std::string& scheme) {
+ SocketStreamThrottleRegistry* registry =
+ Singleton<SocketStreamThrottleRegistry>::get();
+ return registry->GetSocketStreamThrottleForScheme(scheme);
+}
+
+/* static */
+void SocketStreamThrottle::RegisterSocketStreamThrottle(
+ const std::string& scheme, SocketStreamThrottle* throttle) {
+ SocketStreamThrottleRegistry* registry =
+ Singleton<SocketStreamThrottleRegistry>::get();
+ registry->RegisterSocketStreamThrottle(scheme, throttle);
+}
+
+} // namespace net
« no previous file with comments | « net/socket_stream/socket_stream_throttle.h ('k') | net/websockets/websocket_throttle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698