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> |
11 #include "update_engine/action_pipe.h" | 11 #include "update_engine/action_pipe.h" |
12 #include "update_engine/subprocess.h" | 12 #include "update_engine/subprocess.h" |
13 | 13 |
14 using std::min; | 14 using std::min; |
15 using std::string; | 15 using std::string; |
16 using std::vector; | 16 using std::vector; |
17 | 17 |
18 namespace chromeos_update_engine { | 18 namespace chromeos_update_engine { |
19 | 19 |
20 // Use a buffer to reduce the number of IOPS on SSD devices. | 20 // Use a buffer to reduce the number of IOPS on SSD devices. |
21 const size_t kFileWriterBufferSize = 128 * 1024; // 128 KiB | 21 const size_t kFileWriterBufferSize = 128 * 1024; // 128 KiB |
22 | 22 |
23 DownloadAction::DownloadAction(HttpFetcher* http_fetcher) | 23 DownloadAction::DownloadAction(PrefsInterface* prefs, |
24 : writer_(NULL), | 24 HttpFetcher* http_fetcher) |
| 25 : prefs_(prefs), |
| 26 writer_(NULL), |
25 http_fetcher_(http_fetcher), | 27 http_fetcher_(http_fetcher), |
26 delegate_(NULL), | 28 delegate_(NULL), |
27 bytes_received_(0) {} | 29 bytes_received_(0) {} |
28 | 30 |
29 DownloadAction::~DownloadAction() {} | 31 DownloadAction::~DownloadAction() {} |
30 | 32 |
31 void DownloadAction::PerformAction() { | 33 void DownloadAction::PerformAction() { |
32 http_fetcher_->set_delegate(this); | 34 http_fetcher_->set_delegate(this); |
33 | 35 |
34 // Get the InstallPlan and read it | 36 // Get the InstallPlan and read it |
(...skipping 19 matching lines...) Expand all Loading... |
54 new SplitFileWriter(kernel_buffered_file_writer_.get(), | 56 new SplitFileWriter(kernel_buffered_file_writer_.get(), |
55 rootfs_buffered_file_writer_.get())); | 57 rootfs_buffered_file_writer_.get())); |
56 split_file_writer_->SetFirstOpenArgs( | 58 split_file_writer_->SetFirstOpenArgs( |
57 install_plan_.kernel_install_path.c_str(), | 59 install_plan_.kernel_install_path.c_str(), |
58 O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, | 60 O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, |
59 0644); | 61 0644); |
60 decompressing_file_writer_.reset( | 62 decompressing_file_writer_.reset( |
61 new GzipDecompressingFileWriter(split_file_writer_.get())); | 63 new GzipDecompressingFileWriter(split_file_writer_.get())); |
62 writer_ = decompressing_file_writer_.get(); | 64 writer_ = decompressing_file_writer_.get(); |
63 } else { | 65 } else { |
64 delta_performer_.reset(new DeltaPerformer); | 66 delta_performer_.reset(new DeltaPerformer(prefs_)); |
65 writer_ = delta_performer_.get(); | 67 writer_ = delta_performer_.get(); |
66 } | 68 } |
67 } | 69 } |
68 int rc = writer_->Open(install_plan_.install_path.c_str(), | 70 int rc = writer_->Open(install_plan_.install_path.c_str(), |
69 O_TRUNC | O_WRONLY | O_CREAT | O_LARGEFILE, | 71 O_TRUNC | O_WRONLY | O_CREAT | O_LARGEFILE, |
70 0644); | 72 0644); |
71 if (rc < 0) { | 73 if (rc < 0) { |
72 LOG(ERROR) << "Unable to open output file " << install_plan_.install_path; | 74 LOG(ERROR) << "Unable to open output file " << install_plan_.install_path; |
73 // report error to processor | 75 // report error to processor |
74 processor_->ActionComplete(this, kActionCodeInstallDeviceOpenError); | 76 processor_->ActionComplete(this, kActionCodeInstallDeviceOpenError); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 162 |
161 FlushLinuxCaches(); | 163 FlushLinuxCaches(); |
162 | 164 |
163 // Write the path to the output pipe if we're successful. | 165 // Write the path to the output pipe if we're successful. |
164 if (code == kActionCodeSuccess && HasOutputPipe()) | 166 if (code == kActionCodeSuccess && HasOutputPipe()) |
165 SetOutputObject(GetInputObject()); | 167 SetOutputObject(GetInputObject()); |
166 processor_->ActionComplete(this, code); | 168 processor_->ActionComplete(this, code); |
167 } | 169 } |
168 | 170 |
169 }; // namespace {} | 171 }; // namespace {} |
OLD | NEW |