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. |
| 21 const size_t kFileWriterBufferSize = 128 * 1024; // 128 KiB |
| 22 |
20 DownloadAction::DownloadAction(HttpFetcher* http_fetcher) | 23 DownloadAction::DownloadAction(HttpFetcher* http_fetcher) |
21 : writer_(NULL), | 24 : writer_(NULL), |
22 http_fetcher_(http_fetcher), | 25 http_fetcher_(http_fetcher), |
23 delegate_(NULL), | 26 delegate_(NULL), |
24 bytes_received_(0) {} | 27 bytes_received_(0) {} |
25 | 28 |
26 DownloadAction::~DownloadAction() {} | 29 DownloadAction::~DownloadAction() {} |
27 | 30 |
28 void DownloadAction::PerformAction() { | 31 void DownloadAction::PerformAction() { |
29 http_fetcher_->set_delegate(this); | 32 http_fetcher_->set_delegate(this); |
30 | 33 |
31 // Get the InstallPlan and read it | 34 // Get the InstallPlan and read it |
32 CHECK(HasInputObject()); | 35 CHECK(HasInputObject()); |
33 install_plan_ = GetInputObject(); | 36 install_plan_ = GetInputObject(); |
34 bytes_received_ = 0; | 37 bytes_received_ = 0; |
35 | 38 |
36 install_plan_.Dump(); | 39 install_plan_.Dump(); |
37 | 40 |
38 if (writer_) { | 41 if (writer_) { |
39 LOG(INFO) << "Using writer for test."; | 42 LOG(INFO) << "Using writer for test."; |
40 } else { | 43 } else { |
41 if (install_plan_.is_full_update) { | 44 if (install_plan_.is_full_update) { |
42 kernel_file_writer_.reset(new DirectFileWriter); | 45 kernel_file_writer_.reset(new DirectFileWriter); |
43 rootfs_file_writer_.reset(new DirectFileWriter); | 46 rootfs_file_writer_.reset(new DirectFileWriter); |
44 split_file_writer_.reset(new SplitFileWriter(kernel_file_writer_.get(), | 47 kernel_buffered_file_writer_.reset( |
45 rootfs_file_writer_.get())); | 48 new BufferedFileWriter(kernel_file_writer_.get(), |
| 49 kFileWriterBufferSize)); |
| 50 rootfs_buffered_file_writer_.reset( |
| 51 new BufferedFileWriter(rootfs_file_writer_.get(), |
| 52 kFileWriterBufferSize)); |
| 53 split_file_writer_.reset( |
| 54 new SplitFileWriter(kernel_buffered_file_writer_.get(), |
| 55 rootfs_buffered_file_writer_.get())); |
46 split_file_writer_->SetFirstOpenArgs( | 56 split_file_writer_->SetFirstOpenArgs( |
47 install_plan_.kernel_install_path.c_str(), | 57 install_plan_.kernel_install_path.c_str(), |
48 O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, | 58 O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, |
49 0644); | 59 0644); |
50 decompressing_file_writer_.reset( | 60 decompressing_file_writer_.reset( |
51 new GzipDecompressingFileWriter(split_file_writer_.get())); | 61 new GzipDecompressingFileWriter(split_file_writer_.get())); |
52 writer_ = decompressing_file_writer_.get(); | 62 writer_ = decompressing_file_writer_.get(); |
53 } else { | 63 } else { |
54 delta_performer_.reset(new DeltaPerformer); | 64 delta_performer_.reset(new DeltaPerformer); |
55 writer_ = delta_performer_.get(); | 65 writer_ = delta_performer_.get(); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 150 |
141 FlushLinuxCaches(); | 151 FlushLinuxCaches(); |
142 | 152 |
143 // Write the path to the output pipe if we're successful. | 153 // Write the path to the output pipe if we're successful. |
144 if (code == kActionCodeSuccess && HasOutputPipe()) | 154 if (code == kActionCodeSuccess && HasOutputPipe()) |
145 SetOutputObject(GetInputObject()); | 155 SetOutputObject(GetInputObject()); |
146 processor_->ActionComplete(this, code); | 156 processor_->ActionComplete(this, code); |
147 } | 157 } |
148 | 158 |
149 }; // namespace {} | 159 }; // namespace {} |
OLD | NEW |