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

Unified Diff: mock_http_fetcher.cc

Issue 4432002: AU: Separate error codes for different OmahaRequestAction failures. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: Created 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mock_http_fetcher.h ('k') | omaha_request_action.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mock_http_fetcher.cc
diff --git a/mock_http_fetcher.cc b/mock_http_fetcher.cc
index 2e1186529a8c72abc2b67e903ddf75fe01786020..eec550f6f49765af1d831b5d4388f322c205cc38 100644
--- a/mock_http_fetcher.cc
+++ b/mock_http_fetcher.cc
@@ -17,7 +17,11 @@ MockHttpFetcher::~MockHttpFetcher() {
}
void MockHttpFetcher::BeginTransfer(const std::string& url) {
- http_response_code_ = 0;
+ if (fail_transfer_ || data_.empty()) {
+ // No data to send, just notify of completion..
+ SignalTransferComplete();
+ return;
+ }
if (sent_size_ < data_.size())
SendData(true);
}
@@ -26,6 +30,11 @@ void MockHttpFetcher::BeginTransfer(const std::string& url) {
// and it needs to be deleted by the caller. If timeout_source_ is NULL
// when this function is called, this function will always return true.
bool MockHttpFetcher::SendData(bool skip_delivery) {
+ if (fail_transfer_) {
+ SignalTransferComplete();
+ return timeout_source_;
+ }
+
CHECK_LT(sent_size_, data_.size());
if (!skip_delivery) {
const size_t chunk_size = min(kMockHttpFetcherChunkSize,
@@ -36,8 +45,7 @@ bool MockHttpFetcher::SendData(bool skip_delivery) {
CHECK_LE(sent_size_, data_.size());
if (sent_size_ == data_.size()) {
// We've sent all the data. Notify of success.
- http_response_code_ = 200;
- delegate_->TransferComplete(this, true);
+ SignalTransferComplete();
}
}
@@ -101,4 +109,18 @@ void MockHttpFetcher::Unpause() {
}
}
+void MockHttpFetcher::FailTransfer(int http_response_code) {
+ fail_transfer_ = true;
+ http_response_code_ = http_response_code;
+}
+
+void MockHttpFetcher::SignalTransferComplete() {
+ // If the transfer has been failed, the HTTP response code should be set
+ // already.
+ if (!fail_transfer_) {
+ http_response_code_ = 200;
+ }
+ delegate_->TransferComplete(this, !fail_transfer_);
+}
+
} // namespace chromeos_update_engine
« no previous file with comments | « mock_http_fetcher.h ('k') | omaha_request_action.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698