Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 { | 59 { |
| 60 // This must be called only after m_event is signalled. | 60 // This must be called only after m_event is signalled. |
| 61 MutexLocker lock(m_lock); | 61 MutexLocker lock(m_lock); |
| 62 ASSERT(m_done); | 62 ASSERT(m_done); |
| 63 for (size_t i = 0; i < m_clientTasks.size(); ++i) | 63 for (size_t i = 0; i < m_clientTasks.size(); ++i) |
| 64 (*m_clientTasks[i])(); | 64 (*m_clientTasks[i])(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void WorkerLoaderClientBridgeSyncHelper::didSendData(unsigned long long bytesSen t, unsigned long long totalBytesToBeSent) | 67 void WorkerLoaderClientBridgeSyncHelper::didSendData(unsigned long long bytesSen t, unsigned long long totalBytesToBeSent) |
| 68 { | 68 { |
| 69 ASSERT(!m_done); | |
| 70 if (m_done) | |
| 71 return; | |
|
kinuko
2015/02/03 02:35:36
nit: I am kind of supportive for this style, but c
hiroshige
2015/02/03 08:19:44
Hmm.
Then, how about use RELEASE_ASSERT here and o
kinuko
2015/02/03 08:51:22
That works for me, assuming that leaving a thread-
hiroshige
2015/02/03 09:21:14
Done.
| |
| 72 | |
| 69 MutexLocker lock(m_lock); | 73 MutexLocker lock(m_lock); |
| 70 ASSERT(isMainThread()); | 74 ASSERT(isMainThread()); |
| 71 m_clientTasks.append(bind(&ThreadableLoaderClient::didSendData, &m_client, b ytesSent, totalBytesToBeSent)); | 75 m_clientTasks.append(bind(&ThreadableLoaderClient::didSendData, &m_client, b ytesSent, totalBytesToBeSent)); |
| 72 } | 76 } |
| 73 | 77 |
| 74 static void didReceiveResponseAdapter(ThreadableLoaderClient* client, unsigned l ong identifier, PassOwnPtr<CrossThreadResourceResponseData> responseData, PassOw nPtr<WebDataConsumerHandle> handle) | 78 static void didReceiveResponseAdapter(ThreadableLoaderClient* client, unsigned l ong identifier, PassOwnPtr<CrossThreadResourceResponseData> responseData, PassOw nPtr<WebDataConsumerHandle> handle) |
| 75 { | 79 { |
| 76 OwnPtr<ResourceResponse> response(ResourceResponse::adopt(responseData)); | 80 OwnPtr<ResourceResponse> response(ResourceResponse::adopt(responseData)); |
| 77 client->didReceiveResponse(identifier, *response, handle); | 81 client->didReceiveResponse(identifier, *response, handle); |
| 78 } | 82 } |
| 79 | 83 |
| 80 void WorkerLoaderClientBridgeSyncHelper::didReceiveResponse(unsigned long identi fier, const ResourceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle ) | 84 void WorkerLoaderClientBridgeSyncHelper::didReceiveResponse(unsigned long identi fier, const ResourceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle ) |
| 81 { | 85 { |
| 86 ASSERT(!m_done); | |
| 87 if (m_done) | |
| 88 return; | |
| 89 | |
| 82 MutexLocker lock(m_lock); | 90 MutexLocker lock(m_lock); |
| 83 ASSERT(isMainThread()); | 91 ASSERT(isMainThread()); |
| 84 m_clientTasks.append(bind(&didReceiveResponseAdapter, &m_client, identifier, response.copyData(), handle)); | 92 m_clientTasks.append(bind(&didReceiveResponseAdapter, &m_client, identifier, response.copyData(), handle)); |
| 85 } | 93 } |
| 86 | 94 |
| 87 void WorkerLoaderClientBridgeSyncHelper::didReceiveData(const char* data, unsign ed dataLength) | 95 void WorkerLoaderClientBridgeSyncHelper::didReceiveData(const char* data, unsign ed dataLength) |
| 88 { | 96 { |
| 97 ASSERT(!m_done); | |
| 98 if (m_done) | |
| 99 return; | |
| 100 | |
| 89 MutexLocker lock(m_lock); | 101 MutexLocker lock(m_lock); |
| 90 ASSERT(isMainThread()); | 102 ASSERT(isMainThread()); |
| 91 Vector<char>* buffer = new Vector<char>(dataLength); | 103 Vector<char>* buffer = new Vector<char>(dataLength); |
| 92 memcpy(buffer->data(), data, dataLength); | 104 memcpy(buffer->data(), data, dataLength); |
| 93 m_receivedData.append(buffer); | 105 m_receivedData.append(buffer); |
| 94 m_clientTasks.append(bind(&ThreadableLoaderClient::didReceiveData, &m_client , static_cast<const char*>(buffer->data()), dataLength)); | 106 m_clientTasks.append(bind(&ThreadableLoaderClient::didReceiveData, &m_client , static_cast<const char*>(buffer->data()), dataLength)); |
| 95 } | 107 } |
| 96 | 108 |
| 97 void WorkerLoaderClientBridgeSyncHelper::didDownloadData(int dataLength) | 109 void WorkerLoaderClientBridgeSyncHelper::didDownloadData(int dataLength) |
| 98 { | 110 { |
| 111 ASSERT(!m_done); | |
| 112 if (m_done) | |
| 113 return; | |
| 114 | |
| 99 MutexLocker lock(m_lock); | 115 MutexLocker lock(m_lock); |
| 100 ASSERT(isMainThread()); | 116 ASSERT(isMainThread()); |
| 101 m_clientTasks.append(bind(&ThreadableLoaderClient::didDownloadData, &m_clien t, dataLength)); | 117 m_clientTasks.append(bind(&ThreadableLoaderClient::didDownloadData, &m_clien t, dataLength)); |
| 102 } | 118 } |
| 103 | 119 |
| 104 void WorkerLoaderClientBridgeSyncHelper::didReceiveCachedMetadata(const char* da ta, int dataLength) | 120 void WorkerLoaderClientBridgeSyncHelper::didReceiveCachedMetadata(const char* da ta, int dataLength) |
| 105 { | 121 { |
| 122 ASSERT(!m_done); | |
| 123 if (m_done) | |
| 124 return; | |
| 125 | |
| 106 MutexLocker lock(m_lock); | 126 MutexLocker lock(m_lock); |
| 107 ASSERT(isMainThread()); | 127 ASSERT(isMainThread()); |
| 108 Vector<char>* buffer = new Vector<char>(dataLength); | 128 Vector<char>* buffer = new Vector<char>(dataLength); |
| 109 memcpy(buffer->data(), data, dataLength); | 129 memcpy(buffer->data(), data, dataLength); |
| 110 m_receivedData.append(buffer); | 130 m_receivedData.append(buffer); |
| 111 m_clientTasks.append(bind(&ThreadableLoaderClient::didReceiveCachedMetadata, &m_client, static_cast<const char*>(buffer->data()), dataLength)); | 131 m_clientTasks.append(bind(&ThreadableLoaderClient::didReceiveCachedMetadata, &m_client, static_cast<const char*>(buffer->data()), dataLength)); |
| 112 } | 132 } |
| 113 | 133 |
| 114 void WorkerLoaderClientBridgeSyncHelper::didFinishLoading(unsigned long identifi er, double finishTime) | 134 void WorkerLoaderClientBridgeSyncHelper::didFinishLoading(unsigned long identifi er, double finishTime) |
| 115 { | 135 { |
| 136 ASSERT(!m_done); | |
| 137 if (m_done) | |
| 138 return; | |
| 139 | |
| 116 MutexLocker lock(m_lock); | 140 MutexLocker lock(m_lock); |
| 117 ASSERT(isMainThread()); | 141 ASSERT(isMainThread()); |
| 118 m_clientTasks.append(bind(&ThreadableLoaderClient::didFinishLoading, &m_clie nt, identifier, finishTime)); | 142 m_clientTasks.append(bind(&ThreadableLoaderClient::didFinishLoading, &m_clie nt, identifier, finishTime)); |
| 119 m_done = true; | 143 m_done = true; |
| 120 m_event->signal(); | 144 m_event->signal(); |
| 121 } | 145 } |
| 122 | 146 |
| 123 void WorkerLoaderClientBridgeSyncHelper::didFail(const ResourceError& error) | 147 void WorkerLoaderClientBridgeSyncHelper::didFail(const ResourceError& error) |
| 124 { | 148 { |
| 149 ASSERT(!m_done); | |
| 150 if (m_done) | |
| 151 return; | |
| 152 | |
| 125 MutexLocker lock(m_lock); | 153 MutexLocker lock(m_lock); |
| 126 ASSERT(isMainThread()); | 154 ASSERT(isMainThread()); |
| 127 m_clientTasks.append(bind(&ThreadableLoaderClient::didFail, &m_client, error .copy())); | 155 m_clientTasks.append(bind(&ThreadableLoaderClient::didFail, &m_client, error .copy())); |
| 128 m_done = true; | 156 m_done = true; |
| 129 m_event->signal(); | 157 m_event->signal(); |
| 130 } | 158 } |
| 131 | 159 |
| 132 void WorkerLoaderClientBridgeSyncHelper::didFailAccessControlCheck(const Resourc eError& error) | 160 void WorkerLoaderClientBridgeSyncHelper::didFailAccessControlCheck(const Resourc eError& error) |
| 133 { | 161 { |
| 162 ASSERT(!m_done); | |
| 163 if (m_done) | |
| 164 return; | |
| 165 | |
| 134 MutexLocker lock(m_lock); | 166 MutexLocker lock(m_lock); |
| 135 ASSERT(isMainThread()); | 167 ASSERT(isMainThread()); |
| 136 m_clientTasks.append(bind(&ThreadableLoaderClient::didFailAccessControlCheck , &m_client, error.copy())); | 168 m_clientTasks.append(bind(&ThreadableLoaderClient::didFailAccessControlCheck , &m_client, error.copy())); |
| 137 m_done = true; | 169 m_done = true; |
| 138 m_event->signal(); | 170 m_event->signal(); |
| 139 } | 171 } |
| 140 | 172 |
| 141 void WorkerLoaderClientBridgeSyncHelper::didFailRedirectCheck() | 173 void WorkerLoaderClientBridgeSyncHelper::didFailRedirectCheck() |
| 142 { | 174 { |
| 175 ASSERT(!m_done); | |
| 176 if (m_done) | |
| 177 return; | |
| 178 | |
| 143 MutexLocker lock(m_lock); | 179 MutexLocker lock(m_lock); |
| 144 ASSERT(isMainThread()); | 180 ASSERT(isMainThread()); |
| 145 m_clientTasks.append(bind(&ThreadableLoaderClient::didFailRedirectCheck, &m_ client)); | 181 m_clientTasks.append(bind(&ThreadableLoaderClient::didFailRedirectCheck, &m_ client)); |
| 146 m_done = true; | 182 m_done = true; |
| 147 m_event->signal(); | 183 m_event->signal(); |
| 148 } | 184 } |
| 149 | 185 |
| 150 WorkerLoaderClientBridgeSyncHelper::WorkerLoaderClientBridgeSyncHelper(Threadabl eLoaderClient& client, PassOwnPtr<blink::WebWaitableEvent> event) | 186 WorkerLoaderClientBridgeSyncHelper::WorkerLoaderClientBridgeSyncHelper(Threadabl eLoaderClient& client, PassOwnPtr<blink::WebWaitableEvent> event) |
| 151 : m_done(false) | 187 : m_done(false) |
| 152 , m_client(client) | 188 , m_client(client) |
| 153 , m_event(event) | 189 , m_event(event) |
| 154 { | 190 { |
| 155 ASSERT(m_event); | 191 ASSERT(m_event); |
| 156 } | 192 } |
| 157 | 193 |
| 158 } // namespace blink | 194 } // namespace blink |
| OLD | NEW |