OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
6 * @fileoverview Queue of pending requests from an origin. | 6 * @fileoverview Queue of pending requests from an origin. |
7 * | 7 * |
8 */ | 8 */ |
9 'use strict'; | 9 'use strict'; |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 * Inserts this token into the queue. | 78 * Inserts this token into the queue. |
79 * @param {RequestToken} token Queue token | 79 * @param {RequestToken} token Queue token |
80 * @private | 80 * @private |
81 */ | 81 */ |
82 RequestQueue.prototype.insertToken_ = function(token) { | 82 RequestQueue.prototype.insertToken_ = function(token) { |
83 console.log(UTIL_fmt('token ' + this.id_ + ' inserted')); | 83 console.log(UTIL_fmt('token ' + this.id_ + ' inserted')); |
84 if (this.head_ === null) { | 84 if (this.head_ === null) { |
85 this.head_ = token; | 85 this.head_ = token; |
86 this.tail_ = token; | 86 this.tail_ = token; |
87 } else { | 87 } else { |
88 if (!this.tail_) throw 'Non-empty list missing tail'; | 88 if (!this.tail_) |
| 89 throw 'Non-empty list missing tail'; |
89 this.tail_.next = token; | 90 this.tail_.next = token; |
90 token.prev = this.tail_; | 91 token.prev = this.tail_; |
91 this.tail_ = token; | 92 this.tail_ = token; |
92 } | 93 } |
93 }; | 94 }; |
94 | 95 |
95 /** | 96 /** |
96 * Removes this token from the queue. | 97 * Removes this token from the queue. |
97 * @param {RequestToken} token Queue token | 98 * @param {RequestToken} token Queue token |
98 * @private | 99 * @private |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 176 |
176 /** | 177 /** |
177 * Queues this request, and, if it's the first request, begins work on it. | 178 * Queues this request, and, if it's the first request, begins work on it. |
178 * @param {string} appId Application Id | 179 * @param {string} appId Application Id |
179 * @param {string} origin Request origin | 180 * @param {string} origin Request origin |
180 * @param {function(QueuedRequestToken)} beginCb Called when work begins on this | 181 * @param {function(QueuedRequestToken)} beginCb Called when work begins on this |
181 * request. | 182 * request. |
182 * @param {Countdown} timer Countdown timer | 183 * @param {Countdown} timer Countdown timer |
183 * @return {QueuedRequestToken} A token for the request. | 184 * @return {QueuedRequestToken} A token for the request. |
184 */ | 185 */ |
185 OriginKeyedRequestQueue.prototype.queueRequest = | 186 OriginKeyedRequestQueue.prototype.queueRequest = function( |
186 function(appId, origin, beginCb, timer) { | 187 appId, origin, beginCb, timer) { |
187 var key = appId + ' ' + origin; | 188 var key = appId + ' ' + origin; |
188 if (!this.requests_.hasOwnProperty(key)) { | 189 if (!this.requests_.hasOwnProperty(key)) { |
189 this.requests_[key] = new RequestQueue(this.sysTimer_); | 190 this.requests_[key] = new RequestQueue(this.sysTimer_); |
190 } | 191 } |
191 var queue = this.requests_[key]; | 192 var queue = this.requests_[key]; |
192 return queue.queueRequest(beginCb, timer); | 193 return queue.queueRequest(beginCb, timer); |
193 }; | 194 }; |
OLD | NEW |