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

Side by Side Diff: mojo/services/network/url_loader_impl_apptest.cc

Issue 1467603002: URLRequestJob: change ReadRawData contract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add done_reading_called_ to MockNetworkTransaction Created 5 years 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
« no previous file with comments | « ios/web/webui/url_data_manager_ios_backend.cc ('k') | net/http/http_transaction_test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/lazy_instance.h" 6 #include "base/lazy_instance.h"
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "mojo/application/public/cpp/application_test_base.h" 10 #include "mojo/application/public/cpp/application_test_base.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 CHECK(!g_current_job); 42 CHECK(!g_current_job);
43 g_current_job = this; 43 g_current_job = this;
44 } 44 }
45 45
46 Status status() { return status_; } 46 Status status() { return status_; }
47 47
48 int buf_size() { return buf_size_; } 48 int buf_size() { return buf_size_; }
49 49
50 void Start() override { status_ = STARTED; } 50 void Start() override { status_ = STARTED; }
51 51
52 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override { 52 int ReadRawData(net::IOBuffer* buf, int buf_size) override {
53 status_ = READING; 53 status_ = READING;
54 buf_size_ = buf_size; 54 buf_size_ = buf_size;
55 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); 55 return net::ERR_IO_PENDING;
56 return false;
57 } 56 }
58 57
59 void NotifyHeadersComplete() { net::URLRequestJob::NotifyHeadersComplete(); } 58 void NotifyHeadersComplete() { net::URLRequestJob::NotifyHeadersComplete(); }
60 59
61 void NotifyReadComplete(int bytes_read) { 60 void NotifyReadComplete(int bytes_read) {
62 if (bytes_read < 0) { 61 if (bytes_read < 0) {
63 NotifyDone(net::URLRequestStatus( 62 // Map errors to net::ERR_FAILED.
64 net::URLRequestStatus::FromError(net::ERR_FAILED))); 63 ReadRawDataComplete(net::ERR_FAILED);
65 net::URLRequestJob::NotifyReadComplete(0);
66 // Set this after calling ReadRawDataComplete since that ends up calling 64 // Set this after calling ReadRawDataComplete since that ends up calling
67 // ReadRawData. 65 // ReadRawData.
68 status_ = COMPLETED; 66 status_ = COMPLETED;
69 } else if (bytes_read == 0) { 67 } else if (bytes_read == 0) {
70 NotifyDone(net::URLRequestStatus()); 68 ReadRawDataComplete(bytes_read);
71 net::URLRequestJob::NotifyReadComplete(bytes_read);
72 // Set this after calling ReadRawDataComplete since that ends up calling 69 // Set this after calling ReadRawDataComplete since that ends up calling
73 // ReadRawData. 70 // ReadRawData.
74 status_ = COMPLETED; 71 status_ = COMPLETED;
75 } else { 72 } else {
76 SetStatus(net::URLRequestStatus()); 73 ReadRawDataComplete(bytes_read);
77 net::URLRequestJob::NotifyReadComplete(bytes_read);
78 // Set this after calling ReadRawDataComplete since that ends up calling 74 // Set this after calling ReadRawDataComplete since that ends up calling
79 // ReadRawData. 75 // ReadRawData.
80 status_ = STARTED; 76 status_ = STARTED;
81 } 77 }
82 } 78 }
83 79
84 private: 80 private:
85 ~TestURLRequestJob() override { 81 ~TestURLRequestJob() override {
86 CHECK(g_current_job == this); 82 CHECK(g_current_job == this);
87 g_current_job = nullptr; 83 g_current_job = nullptr;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 278
283 EXPECT_TRUE(IsUrlLoaderValid()); 279 EXPECT_TRUE(IsUrlLoaderValid());
284 280
285 g_current_job->NotifyReadComplete(-1); 281 g_current_job->NotifyReadComplete(-1);
286 282
287 while (IsUrlLoaderValid()) 283 while (IsUrlLoaderValid())
288 base::RunLoop().RunUntilIdle(); 284 base::RunLoop().RunUntilIdle();
289 } 285 }
290 286
291 } // namespace mojo 287 } // namespace mojo
OLDNEW
« no previous file with comments | « ios/web/webui/url_data_manager_ios_backend.cc ('k') | net/http/http_transaction_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698