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

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

Issue 1410643007: URLRequestJob: change ReadRawData contract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address michaeln's comment 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 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 result) {
62 if (bytes_read < 0) { 61 status_ = result <= 0 ? COMPLETED : STARTED;
63 status_ = COMPLETED; 62
64 NotifyDone(net::URLRequestStatus( 63 // Map errors to net::ERR_FAILED.
65 net::URLRequestStatus::FromError(net::ERR_FAILED))); 64 if (result < 0)
66 net::URLRequestJob::NotifyReadComplete(0); 65 result = net::ERR_FAILED;
67 } else if (bytes_read == 0) { 66
68 status_ = COMPLETED; 67 ReadRawDataComplete(result);
69 NotifyDone(net::URLRequestStatus());
70 net::URLRequestJob::NotifyReadComplete(bytes_read);
71 } else {
72 status_ = STARTED;
73 SetStatus(net::URLRequestStatus());
74 net::URLRequestJob::NotifyReadComplete(bytes_read);
75 }
76 } 68 }
77 69
78 private: 70 private:
79 ~TestURLRequestJob() override { 71 ~TestURLRequestJob() override {
80 CHECK(g_current_job == this); 72 CHECK(g_current_job == this);
81 g_current_job = nullptr; 73 g_current_job = nullptr;
82 } 74 }
83 75
84 Status status_; 76 Status status_;
85 int buf_size_; 77 int buf_size_;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 257
266 EXPECT_TRUE(IsUrlLoaderValid()); 258 EXPECT_TRUE(IsUrlLoaderValid());
267 259
268 g_current_job->NotifyReadComplete(-1); 260 g_current_job->NotifyReadComplete(-1);
269 base::RunLoop().RunUntilIdle(); 261 base::RunLoop().RunUntilIdle();
270 262
271 EXPECT_FALSE(IsUrlLoaderValid()); 263 EXPECT_FALSE(IsUrlLoaderValid());
272 } 264 }
273 265
274 } // namespace mojo 266 } // 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