Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / net / quic / quic_write_blocked_list.h
index 3848b08..cddd58f 100644 (file)
@@ -5,6 +5,8 @@
 #ifndef NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_
 #define NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_
 
+#include <set>
+
 #include "net/base/net_export.h"
 #include "net/quic/quic_protocol.h"
 #include "net/spdy/write_blocked_list.h"
@@ -47,33 +49,44 @@ class NET_EXPORT_PRIVATE QuicWriteBlockedList {
     if (crypto_stream_blocked_) {
       crypto_stream_blocked_ = false;
       return kCryptoStreamId;
-    } else if (headers_stream_blocked_) {
+    }
+
+    if (headers_stream_blocked_) {
       headers_stream_blocked_ = false;
       return kHeadersStreamId;
-    } else {
-      SpdyPriority priority =
-          base_write_blocked_list_.GetHighestPriorityWriteBlockedList();
-      return base_write_blocked_list_.PopFront(priority);
     }
+
+    SpdyPriority priority =
+        base_write_blocked_list_.GetHighestPriorityWriteBlockedList();
+    QuicStreamId id = base_write_blocked_list_.PopFront(priority);
+    blocked_streams_.erase(id);
+    return id;
   }
 
-  // TODO(avd) Remove version argument when QUIC_VERSION_12 is deprecated.
-  void PushBack(QuicStreamId stream_id,
-                QuicPriority priority,
-                QuicVersion version) {
+  void PushBack(QuicStreamId stream_id, QuicPriority priority) {
     if (stream_id == kCryptoStreamId) {
       DCHECK_EQ(kHighestPriority, priority);
       // TODO(avd) Add DCHECK(!crypto_stream_blocked_)
       crypto_stream_blocked_ = true;
-    } else if (version > QUIC_VERSION_12 &&
-               stream_id == kHeadersStreamId) {
+      return;
+    }
+
+    if (stream_id == kHeadersStreamId) {
       DCHECK_EQ(kHighestPriority, priority);
       // TODO(avd) Add DCHECK(!headers_stream_blocked_);
       headers_stream_blocked_ = true;
-    } else {
-      base_write_blocked_list_.PushBack(
-          stream_id, static_cast<SpdyPriority>(priority));
+      return;
+    }
+
+    if (blocked_streams_.find(stream_id) != blocked_streams_.end()) {
+      DVLOG(1) << "Stream " << stream_id << " already in write blocked list.";
+      return;
     }
+
+    base_write_blocked_list_.PushBack(
+        stream_id, static_cast<SpdyPriority>(priority));
+    blocked_streams_.insert(stream_id);
+    return;
   }
 
  private:
@@ -81,6 +94,11 @@ class NET_EXPORT_PRIVATE QuicWriteBlockedList {
   bool crypto_stream_blocked_;
   bool headers_stream_blocked_;
 
+  // Keep track of write blocked streams in a set for faster membership checking
+  // than iterating over the base_write_blocked_list_. The contents of this set
+  // should mirror the contents of base_write_blocked_list_.
+  std::set<QuicStreamId> blocked_streams_;
+
   DISALLOW_COPY_AND_ASSIGN(QuicWriteBlockedList);
 };