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

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

Issue 1459333002: Revert "Reland: URLRequestJob: change ReadRawData contract" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 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 int ReadRawData(net::IOBuffer* buf, int buf_size) override { 52 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override {
53 status_ = READING; 53 status_ = READING;
54 buf_size_ = buf_size; 54 buf_size_ = buf_size;
55 return net::ERR_IO_PENDING; 55 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0));
56 return false;
56 } 57 }
57 58
58 void NotifyHeadersComplete() { net::URLRequestJob::NotifyHeadersComplete(); } 59 void NotifyHeadersComplete() { net::URLRequestJob::NotifyHeadersComplete(); }
59 60
60 void NotifyReadComplete(int bytes_read) { 61 void NotifyReadComplete(int bytes_read) {
61 if (bytes_read < 0) { 62 if (bytes_read < 0) {
62 // Map errors to net::ERR_FAILED. 63 NotifyDone(net::URLRequestStatus(
63 ReadRawDataComplete(net::ERR_FAILED); 64 net::URLRequestStatus::FromError(net::ERR_FAILED)));
65 net::URLRequestJob::NotifyReadComplete(0);
64 // Set this after calling ReadRawDataComplete since that ends up calling 66 // Set this after calling ReadRawDataComplete since that ends up calling
65 // ReadRawData. 67 // ReadRawData.
66 status_ = COMPLETED; 68 status_ = COMPLETED;
67 } else if (bytes_read == 0) { 69 } else if (bytes_read == 0) {
68 ReadRawDataComplete(bytes_read); 70 NotifyDone(net::URLRequestStatus());
71 net::URLRequestJob::NotifyReadComplete(bytes_read);
69 // Set this after calling ReadRawDataComplete since that ends up calling 72 // Set this after calling ReadRawDataComplete since that ends up calling
70 // ReadRawData. 73 // ReadRawData.
71 status_ = COMPLETED; 74 status_ = COMPLETED;
72 } else { 75 } else {
73 ReadRawDataComplete(bytes_read); 76 SetStatus(net::URLRequestStatus());
77 net::URLRequestJob::NotifyReadComplete(bytes_read);
74 // Set this after calling ReadRawDataComplete since that ends up calling 78 // Set this after calling ReadRawDataComplete since that ends up calling
75 // ReadRawData. 79 // ReadRawData.
76 status_ = STARTED; 80 status_ = STARTED;
77 } 81 }
78 } 82 }
79 83
80 private: 84 private:
81 ~TestURLRequestJob() override { 85 ~TestURLRequestJob() override {
82 CHECK(g_current_job == this); 86 CHECK(g_current_job == this);
83 g_current_job = nullptr; 87 g_current_job = nullptr;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 282
279 EXPECT_TRUE(IsUrlLoaderValid()); 283 EXPECT_TRUE(IsUrlLoaderValid());
280 284
281 g_current_job->NotifyReadComplete(-1); 285 g_current_job->NotifyReadComplete(-1);
282 286
283 while (IsUrlLoaderValid()) 287 while (IsUrlLoaderValid())
284 base::RunLoop().RunUntilIdle(); 288 base::RunLoop().RunUntilIdle();
285 } 289 }
286 290
287 } // namespace mojo 291 } // namespace mojo
OLDNEW
« no previous file with comments | « ios/web/webui/url_data_manager_ios_backend.cc ('k') | net/test/url_request/url_request_failed_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698