| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <stack> | 5 #include <stack> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 else | 165 else |
| 166 MessageLoop::current()->PostTask(FROM_HERE, task.release()); | 166 MessageLoop::current()->PostTask(FROM_HERE, task.release()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 // Wrappers to call AppCacheResponseReader/Writer Read and Write methods | 169 // Wrappers to call AppCacheResponseReader/Writer Read and Write methods |
| 170 | 170 |
| 171 void WriteBasicResponse() { | 171 void WriteBasicResponse() { |
| 172 static const char kHttpHeaders[] = | 172 static const char kHttpHeaders[] = |
| 173 "HTTP/1.0 200 OK\0Content-Length: 5\0\0"; | 173 "HTTP/1.0 200 OK\0Content-Length: 5\0\0"; |
| 174 static const char* kHttpBody = "Hello"; | 174 static const char* kHttpBody = "Hello"; |
| 175 scoped_refptr<IOBuffer> body = new WrappedIOBuffer(kHttpBody); | 175 scoped_refptr<IOBuffer> body(new WrappedIOBuffer(kHttpBody)); |
| 176 std::string raw_headers(kHttpHeaders, arraysize(kHttpHeaders)); | 176 std::string raw_headers(kHttpHeaders, arraysize(kHttpHeaders)); |
| 177 WriteResponse(MakeHttpResponseInfo(raw_headers), body, strlen(kHttpBody)); | 177 WriteResponse(MakeHttpResponseInfo(raw_headers), body, strlen(kHttpBody)); |
| 178 } | 178 } |
| 179 | 179 |
| 180 int basic_response_size() { return 5; } // should match kHttpBody above | 180 int basic_response_size() { return 5; } // should match kHttpBody above |
| 181 | 181 |
| 182 void WriteResponse(net::HttpResponseInfo* head, | 182 void WriteResponse(net::HttpResponseInfo* head, |
| 183 IOBuffer* body, int body_len) { | 183 IOBuffer* body, int body_len) { |
| 184 DCHECK(body); | 184 DCHECK(body); |
| 185 scoped_refptr<IOBuffer> body_ref(body); | 185 scoped_refptr<IOBuffer> body_ref(body); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); | 449 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); |
| 450 written_response_id_ = writer_->response_id(); | 450 written_response_id_ = writer_->response_id(); |
| 451 for (int i = 0; i < kNumBlocks; ++i) { | 451 for (int i = 0; i < kNumBlocks; ++i) { |
| 452 PushNextTask(NewRunnableMethod( | 452 PushNextTask(NewRunnableMethod( |
| 453 this, &AppCacheResponseTest::WriteOneBlock, kNumBlocks - i)); | 453 this, &AppCacheResponseTest::WriteOneBlock, kNumBlocks - i)); |
| 454 } | 454 } |
| 455 ScheduleNextTask(); | 455 ScheduleNextTask(); |
| 456 } | 456 } |
| 457 | 457 |
| 458 void WriteOneBlock(int block_number) { | 458 void WriteOneBlock(int block_number) { |
| 459 scoped_refptr<IOBuffer> io_buffer = | 459 scoped_refptr<IOBuffer> io_buffer( |
| 460 new IOBuffer(kBlockSize); | 460 new IOBuffer(kBlockSize)); |
| 461 FillData(block_number, io_buffer->data(), kBlockSize); | 461 FillData(block_number, io_buffer->data(), kBlockSize); |
| 462 WriteResponseBody(io_buffer, kBlockSize); | 462 WriteResponseBody(io_buffer, kBlockSize); |
| 463 } | 463 } |
| 464 | 464 |
| 465 void ReadInBlocks() { | 465 void ReadInBlocks() { |
| 466 writer_.reset(); | 466 writer_.reset(); |
| 467 reader_.reset(service_->storage()->CreateResponseReader( | 467 reader_.reset(service_->storage()->CreateResponseReader( |
| 468 GURL(), written_response_id_)); | 468 GURL(), written_response_id_)); |
| 469 for (int i = 0; i < kNumBlocks; ++i) { | 469 for (int i = 0; i < kNumBlocks; ++i) { |
| 470 PushNextTask(NewRunnableMethod( | 470 PushNextTask(NewRunnableMethod( |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 | 715 |
| 716 TEST_F(AppCacheResponseTest, DeleteWithIOPending) { | 716 TEST_F(AppCacheResponseTest, DeleteWithIOPending) { |
| 717 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithIOPending); | 717 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithIOPending); |
| 718 } | 718 } |
| 719 | 719 |
| 720 } // namespace appcache | 720 } // namespace appcache |
| 721 | 721 |
| 722 // AppCacheResponseTest is expected to always live longer than the | 722 // AppCacheResponseTest is expected to always live longer than the |
| 723 // runnable methods. This lets us call NewRunnableMethod on its instances. | 723 // runnable methods. This lets us call NewRunnableMethod on its instances. |
| 724 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheResponseTest); | 724 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheResponseTest); |
| OLD | NEW |