OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 "update_engine/download_action.h" | 5 #include "update_engine/download_action.h" |
6 #include <errno.h> | 6 #include <errno.h> |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 #include <glib.h> | 10 #include <glib.h> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 if (!install_plan_.is_full_update) { | 67 if (!install_plan_.is_full_update) { |
68 if (!delta_performer_->OpenKernel( | 68 if (!delta_performer_->OpenKernel( |
69 install_plan_.kernel_install_path.c_str())) { | 69 install_plan_.kernel_install_path.c_str())) { |
70 LOG(ERROR) << "Unable to open kernel file " | 70 LOG(ERROR) << "Unable to open kernel file " |
71 << install_plan_.kernel_install_path.c_str(); | 71 << install_plan_.kernel_install_path.c_str(); |
72 writer_->Close(); | 72 writer_->Close(); |
73 processor_->ActionComplete(this, kActionCodeKernelDeviceOpenError); | 73 processor_->ActionComplete(this, kActionCodeKernelDeviceOpenError); |
74 return; | 74 return; |
75 } | 75 } |
76 } | 76 } |
| 77 if (delegate_) { |
| 78 delegate_->SetDownloadStatus(true); // Set to active. |
| 79 } |
77 http_fetcher_->BeginTransfer(install_plan_.download_url); | 80 http_fetcher_->BeginTransfer(install_plan_.download_url); |
78 } | 81 } |
79 | 82 |
80 void DownloadAction::TerminateProcessing() { | 83 void DownloadAction::TerminateProcessing() { |
81 CHECK(writer_); | 84 CHECK(writer_); |
82 CHECK_EQ(writer_->Close(), 0); | 85 CHECK_EQ(writer_->Close(), 0); |
83 writer_ = NULL; | 86 writer_ = NULL; |
84 http_fetcher_->TerminateTransfer(); | 87 http_fetcher_->TerminateTransfer(); |
| 88 if (delegate_) { |
| 89 delegate_->SetDownloadStatus(false); // Set to inactive. |
| 90 } |
85 } | 91 } |
86 | 92 |
87 void DownloadAction::ReceivedBytes(HttpFetcher *fetcher, | 93 void DownloadAction::ReceivedBytes(HttpFetcher *fetcher, |
88 const char* bytes, | 94 const char* bytes, |
89 int length) { | 95 int length) { |
90 bytes_received_ += length; | 96 bytes_received_ += length; |
91 if (delegate_) | 97 if (delegate_) |
92 delegate_->BytesReceived(bytes_received_, install_plan_.size); | 98 delegate_->BytesReceived(bytes_received_, install_plan_.size); |
93 int rc = writer_->Write(bytes, length); | 99 int rc = writer_->Write(bytes, length); |
94 TEST_AND_RETURN(rc >= 0); | 100 TEST_AND_RETURN(rc >= 0); |
(...skipping 14 matching lines...) Expand all Loading... |
109 | 115 |
110 LOG(INFO) << "FlushLinuxCaches done."; | 116 LOG(INFO) << "FlushLinuxCaches done."; |
111 } | 117 } |
112 } | 118 } |
113 | 119 |
114 void DownloadAction::TransferComplete(HttpFetcher *fetcher, bool successful) { | 120 void DownloadAction::TransferComplete(HttpFetcher *fetcher, bool successful) { |
115 if (writer_) { | 121 if (writer_) { |
116 CHECK_EQ(writer_->Close(), 0) << errno; | 122 CHECK_EQ(writer_->Close(), 0) << errno; |
117 writer_ = NULL; | 123 writer_ = NULL; |
118 } | 124 } |
| 125 if (delegate_) { |
| 126 delegate_->SetDownloadStatus(false); // Set to inactive. |
| 127 } |
119 ActionExitCode code = | 128 ActionExitCode code = |
120 successful ? kActionCodeSuccess : kActionCodeDownloadTransferError; | 129 successful ? kActionCodeSuccess : kActionCodeDownloadTransferError; |
121 if (code == kActionCodeSuccess) { | 130 if (code == kActionCodeSuccess) { |
122 // Make sure hash is correct | 131 // Make sure hash is correct |
123 omaha_hash_calculator_.Finalize(); | 132 omaha_hash_calculator_.Finalize(); |
124 if (omaha_hash_calculator_.hash() != install_plan_.download_hash) { | 133 if (omaha_hash_calculator_.hash() != install_plan_.download_hash) { |
125 LOG(ERROR) << "Download of " << install_plan_.download_url | 134 LOG(ERROR) << "Download of " << install_plan_.download_url |
126 << " failed. Expect hash " << install_plan_.download_hash | 135 << " failed. Expect hash " << install_plan_.download_hash |
127 << " but got hash " << omaha_hash_calculator_.hash(); | 136 << " but got hash " << omaha_hash_calculator_.hash(); |
128 code = kActionCodeDownloadHashMismatchError; | 137 code = kActionCodeDownloadHashMismatchError; |
129 } | 138 } |
130 } | 139 } |
131 | 140 |
132 FlushLinuxCaches(); | 141 FlushLinuxCaches(); |
133 | 142 |
134 // Write the path to the output pipe if we're successful. | 143 // Write the path to the output pipe if we're successful. |
135 if (code == kActionCodeSuccess && HasOutputPipe()) | 144 if (code == kActionCodeSuccess && HasOutputPipe()) |
136 SetOutputObject(GetInputObject()); | 145 SetOutputObject(GetInputObject()); |
137 processor_->ActionComplete(this, code); | 146 processor_->ActionComplete(this, code); |
138 } | 147 } |
139 | 148 |
140 }; // namespace {} | 149 }; // namespace {} |
OLD | NEW |