| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 private: | 128 private: |
| 129 explicit ThrottlingController(ExecutionContext& context) | 129 explicit ThrottlingController(ExecutionContext& context) |
| 130 : Supplement<ExecutionContext>(context), | 130 : Supplement<ExecutionContext>(context), |
| 131 m_maxRunningReaders(kMaxOutstandingRequestsPerThread) {} | 131 m_maxRunningReaders(kMaxOutstandingRequestsPerThread) {} |
| 132 | 132 |
| 133 void pushReader(FileReader* reader) { | 133 void pushReader(FileReader* reader) { |
| 134 if (m_pendingReaders.isEmpty() && | 134 if (m_pendingReaders.isEmpty() && |
| 135 m_runningReaders.size() < m_maxRunningReaders) { | 135 m_runningReaders.size() < m_maxRunningReaders) { |
| 136 reader->executePendingRead(); | 136 reader->executePendingRead(); |
| 137 ASSERT(!m_runningReaders.contains(reader)); | 137 ASSERT(!m_runningReaders.contains(reader)); |
| 138 m_runningReaders.add(reader); | 138 m_runningReaders.insert(reader); |
| 139 return; | 139 return; |
| 140 } | 140 } |
| 141 m_pendingReaders.append(reader); | 141 m_pendingReaders.append(reader); |
| 142 executeReaders(); | 142 executeReaders(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 FinishReaderType removeReader(FileReader* reader) { | 145 FinishReaderType removeReader(FileReader* reader) { |
| 146 FileReaderHashSet::const_iterator hashIter = m_runningReaders.find(reader); | 146 FileReaderHashSet::const_iterator hashIter = m_runningReaders.find(reader); |
| 147 if (hashIter != m_runningReaders.end()) { | 147 if (hashIter != m_runningReaders.end()) { |
| 148 m_runningReaders.remove(hashIter); | 148 m_runningReaders.remove(hashIter); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 163 if (nextStep == RunPendingReaders) | 163 if (nextStep == RunPendingReaders) |
| 164 executeReaders(); | 164 executeReaders(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void executeReaders() { | 167 void executeReaders() { |
| 168 while (m_runningReaders.size() < m_maxRunningReaders) { | 168 while (m_runningReaders.size() < m_maxRunningReaders) { |
| 169 if (m_pendingReaders.isEmpty()) | 169 if (m_pendingReaders.isEmpty()) |
| 170 return; | 170 return; |
| 171 FileReader* reader = m_pendingReaders.takeFirst(); | 171 FileReader* reader = m_pendingReaders.takeFirst(); |
| 172 reader->executePendingRead(); | 172 reader->executePendingRead(); |
| 173 m_runningReaders.add(reader); | 173 m_runningReaders.insert(reader); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 static const char* supplementName() { | 177 static const char* supplementName() { |
| 178 return "FileReaderThrottlingController"; | 178 return "FileReaderThrottlingController"; |
| 179 } | 179 } |
| 180 | 180 |
| 181 const size_t m_maxRunningReaders; | 181 const size_t m_maxRunningReaders; |
| 182 | 182 |
| 183 using FileReaderDeque = HeapDeque<Member<FileReader>>; | 183 using FileReaderDeque = HeapDeque<Member<FileReader>>; |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 ProgressEvent::create(type, false, m_loader->bytesLoaded(), 0)); | 469 ProgressEvent::create(type, false, m_loader->bytesLoaded(), 0)); |
| 470 } | 470 } |
| 471 | 471 |
| 472 DEFINE_TRACE(FileReader) { | 472 DEFINE_TRACE(FileReader) { |
| 473 visitor->trace(m_error); | 473 visitor->trace(m_error); |
| 474 EventTargetWithInlineData::trace(visitor); | 474 EventTargetWithInlineData::trace(visitor); |
| 475 ContextLifecycleObserver::trace(visitor); | 475 ContextLifecycleObserver::trace(visitor); |
| 476 } | 476 } |
| 477 | 477 |
| 478 } // namespace blink | 478 } // namespace blink |
| OLD | NEW |