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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/CompositeDataConsumerHandle.cpp

Issue 2181213003: Use DCHECK instead of ASSERT in DataConsumerHandle-related stuff (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@data_consumer_handle_unique_ptr
Patch Set: rebase Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "modules/fetch/CompositeDataConsumerHandle.h" 5 #include "modules/fetch/CompositeDataConsumerHandle.h"
6 6
7 #include "platform/CrossThreadFunctional.h" 7 #include "platform/CrossThreadFunctional.h"
8 #include "public/platform/Platform.h" 8 #include "public/platform/Platform.h"
9 #include "public/platform/WebTaskRunner.h" 9 #include "public/platform/WebTaskRunner.h"
10 #include "public/platform/WebThread.h" 10 #include "public/platform/WebThread.h"
(...skipping 19 matching lines...) Expand all
30 private: 30 private:
31 RefPtr<Context> m_context; 31 RefPtr<Context> m_context;
32 }; 32 };
33 33
34 class CompositeDataConsumerHandle::Context final : public ThreadSafeRefCounted<C ontext> { 34 class CompositeDataConsumerHandle::Context final : public ThreadSafeRefCounted<C ontext> {
35 public: 35 public:
36 using Token = unsigned; 36 using Token = unsigned;
37 static PassRefPtr<Context> create(std::unique_ptr<WebDataConsumerHandle> han dle) { return adoptRef(new Context(std::move(handle))); } 37 static PassRefPtr<Context> create(std::unique_ptr<WebDataConsumerHandle> han dle) { return adoptRef(new Context(std::move(handle))); }
38 ~Context() 38 ~Context()
39 { 39 {
40 ASSERT(!m_readerThread); 40 DCHECK(!m_readerThread);
41 ASSERT(!m_reader); 41 DCHECK(!m_reader);
42 ASSERT(!m_client); 42 DCHECK(!m_client);
43 } 43 }
44 std::unique_ptr<ReaderImpl> obtainReader(Client* client) 44 std::unique_ptr<ReaderImpl> obtainReader(Client* client)
45 { 45 {
46 MutexLocker locker(m_mutex); 46 MutexLocker locker(m_mutex);
47 ASSERT(!m_readerThread); 47 DCHECK(!m_readerThread);
48 ASSERT(!m_reader); 48 DCHECK(!m_reader);
49 ASSERT(!m_client); 49 DCHECK(!m_client);
50 ++m_token; 50 ++m_token;
51 m_client = client; 51 m_client = client;
52 m_readerThread = Platform::current()->currentThread(); 52 m_readerThread = Platform::current()->currentThread();
53 m_reader = m_handle->obtainReader(m_client); 53 m_reader = m_handle->obtainReader(m_client);
54 return wrapUnique(new ReaderImpl(this)); 54 return wrapUnique(new ReaderImpl(this));
55 } 55 }
56 void detachReader() 56 void detachReader()
57 { 57 {
58 MutexLocker locker(m_mutex); 58 MutexLocker locker(m_mutex);
59 ASSERT(m_readerThread); 59 DCHECK(m_readerThread);
60 ASSERT(m_readerThread->isCurrentThread()); 60 DCHECK(m_readerThread->isCurrentThread());
61 ASSERT(m_reader); 61 DCHECK(m_reader);
62 ASSERT(!m_isInTwoPhaseRead); 62 DCHECK(!m_isInTwoPhaseRead);
63 ASSERT(!m_isUpdateWaitingForEndRead); 63 DCHECK(!m_isUpdateWaitingForEndRead);
64 ++m_token; 64 ++m_token;
65 m_reader = nullptr; 65 m_reader = nullptr;
66 m_readerThread = nullptr; 66 m_readerThread = nullptr;
67 m_client = nullptr; 67 m_client = nullptr;
68 } 68 }
69 void update(std::unique_ptr<WebDataConsumerHandle> handle) 69 void update(std::unique_ptr<WebDataConsumerHandle> handle)
70 { 70 {
71 MutexLocker locker(m_mutex); 71 MutexLocker locker(m_mutex);
72 m_handle = std::move(handle); 72 m_handle = std::move(handle);
73 if (!m_readerThread) { 73 if (!m_readerThread) {
74 // There is no reader. 74 // There is no reader.
75 return; 75 return;
76 } 76 }
77 ++m_token; 77 ++m_token;
78 updateReaderNoLock(m_token); 78 updateReaderNoLock(m_token);
79 } 79 }
80 80
81 Result read(void* data, size_t size, Flags flags, size_t* readSize) 81 Result read(void* data, size_t size, Flags flags, size_t* readSize)
82 { 82 {
83 ASSERT(m_readerThread && m_readerThread->isCurrentThread()); 83 DCHECK(m_readerThread && m_readerThread->isCurrentThread());
84 return m_reader->read(data, size, flags, readSize); 84 return m_reader->read(data, size, flags, readSize);
85 } 85 }
86 Result beginRead(const void** buffer, Flags flags, size_t* available) 86 Result beginRead(const void** buffer, Flags flags, size_t* available)
87 { 87 {
88 ASSERT(m_readerThread && m_readerThread->isCurrentThread()); 88 DCHECK(m_readerThread && m_readerThread->isCurrentThread());
89 ASSERT(!m_isInTwoPhaseRead); 89 DCHECK(!m_isInTwoPhaseRead);
90 Result r = m_reader->beginRead(buffer, flags, available); 90 Result r = m_reader->beginRead(buffer, flags, available);
91 m_isInTwoPhaseRead = (r == Ok); 91 m_isInTwoPhaseRead = (r == Ok);
92 return r; 92 return r;
93 } 93 }
94 Result endRead(size_t readSize) 94 Result endRead(size_t readSize)
95 { 95 {
96 ASSERT(m_readerThread && m_readerThread->isCurrentThread()); 96 DCHECK(m_readerThread && m_readerThread->isCurrentThread());
97 ASSERT(m_isInTwoPhaseRead); 97 DCHECK(m_isInTwoPhaseRead);
98 Result r = m_reader->endRead(readSize); 98 Result r = m_reader->endRead(readSize);
99 m_isInTwoPhaseRead = false; 99 m_isInTwoPhaseRead = false;
100 if (m_isUpdateWaitingForEndRead) { 100 if (m_isUpdateWaitingForEndRead) {
101 // We need this lock to access |m_handle|. 101 // We need this lock to access |m_handle|.
102 MutexLocker locker(m_mutex); 102 MutexLocker locker(m_mutex);
103 m_reader = nullptr; 103 m_reader = nullptr;
104 m_reader = m_handle->obtainReader(m_client); 104 m_reader = m_handle->obtainReader(m_client);
105 m_isUpdateWaitingForEndRead = false; 105 m_isUpdateWaitingForEndRead = false;
106 } 106 }
107 return r; 107 return r;
(...skipping 13 matching lines...) Expand all
121 { 121 {
122 MutexLocker locker(m_mutex); 122 MutexLocker locker(m_mutex);
123 updateReaderNoLock(token); 123 updateReaderNoLock(token);
124 } 124 }
125 void updateReaderNoLock(Token token) 125 void updateReaderNoLock(Token token)
126 { 126 {
127 if (token != m_token) { 127 if (token != m_token) {
128 // This request is not fresh. Ignore it. 128 // This request is not fresh. Ignore it.
129 return; 129 return;
130 } 130 }
131 ASSERT(m_readerThread); 131 DCHECK(m_readerThread);
132 ASSERT(m_reader); 132 DCHECK(m_reader);
133 if (m_readerThread->isCurrentThread()) { 133 if (m_readerThread->isCurrentThread()) {
134 if (m_isInTwoPhaseRead) { 134 if (m_isInTwoPhaseRead) {
135 // We are waiting for the two-phase read completion. 135 // We are waiting for the two-phase read completion.
136 m_isUpdateWaitingForEndRead = true; 136 m_isUpdateWaitingForEndRead = true;
137 return; 137 return;
138 } 138 }
139 // Unregister the old one, then register the new one. 139 // Unregister the old one, then register the new one.
140 m_reader = nullptr; 140 m_reader = nullptr;
141 m_reader = m_handle->obtainReader(m_client); 141 m_reader = m_handle->obtainReader(m_client);
142 return; 142 return;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return m_context->beginRead(buffer, flags, available); 179 return m_context->beginRead(buffer, flags, available);
180 } 180 }
181 181
182 Result CompositeDataConsumerHandle::ReaderImpl::endRead(size_t readSize) 182 Result CompositeDataConsumerHandle::ReaderImpl::endRead(size_t readSize)
183 { 183 {
184 return m_context->endRead(readSize); 184 return m_context->endRead(readSize);
185 } 185 }
186 186
187 CompositeDataConsumerHandle::Updater::Updater(PassRefPtr<Context> context) 187 CompositeDataConsumerHandle::Updater::Updater(PassRefPtr<Context> context)
188 : m_context(context) 188 : m_context(context)
189 #if ENABLE(ASSERT) 189 #if DCHECK_IS_ON()
190 , m_thread(Platform::current()->currentThread()) 190 , m_thread(Platform::current()->currentThread())
191 #endif 191 #endif
192 { 192 {
193 } 193 }
194 194
195 CompositeDataConsumerHandle::Updater::~Updater() {} 195 CompositeDataConsumerHandle::Updater::~Updater() {}
196 196
197 void CompositeDataConsumerHandle::Updater::update(std::unique_ptr<WebDataConsume rHandle> handle) 197 void CompositeDataConsumerHandle::Updater::update(std::unique_ptr<WebDataConsume rHandle> handle)
198 { 198 {
199 ASSERT(handle); 199 DCHECK(handle);
200 ASSERT(m_thread->isCurrentThread()); 200 #if DCHECK_IS_ON()
201 DCHECK(m_thread->isCurrentThread());
202 #endif
201 m_context->update(std::move(handle)); 203 m_context->update(std::move(handle));
202 } 204 }
203 205
204 CompositeDataConsumerHandle::CompositeDataConsumerHandle(std::unique_ptr<WebData ConsumerHandle> handle, Updater** updater) 206 CompositeDataConsumerHandle::CompositeDataConsumerHandle(std::unique_ptr<WebData ConsumerHandle> handle, Updater** updater)
205 : m_context(Context::create(std::move(handle))) 207 : m_context(Context::create(std::move(handle)))
206 { 208 {
207 *updater = new Updater(m_context); 209 *updater = new Updater(m_context);
208 } 210 }
209 211
210 CompositeDataConsumerHandle::~CompositeDataConsumerHandle() { } 212 CompositeDataConsumerHandle::~CompositeDataConsumerHandle() { }
211 213
212 WebDataConsumerHandle::Reader* CompositeDataConsumerHandle::obtainReaderInternal (Client* client) 214 WebDataConsumerHandle::Reader* CompositeDataConsumerHandle::obtainReaderInternal (Client* client)
213 { 215 {
214 return m_context->obtainReader(client).release(); 216 return m_context->obtainReader(client).release();
215 } 217 }
216 218
217 } // namespace blink 219 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698