OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 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 DownloadAction::DownloadAction(HttpFetcher* http_fetcher) | 20 DownloadAction::DownloadAction(HttpFetcher* http_fetcher) |
21 : writer_(NULL), | 21 : writer_(NULL), |
22 http_fetcher_(http_fetcher) {} | 22 http_fetcher_(http_fetcher), |
| 23 delegate_(NULL), |
| 24 bytes_received_(0) {} |
23 | 25 |
24 DownloadAction::~DownloadAction() {} | 26 DownloadAction::~DownloadAction() {} |
25 | 27 |
26 void DownloadAction::PerformAction() { | 28 void DownloadAction::PerformAction() { |
27 http_fetcher_->set_delegate(this); | 29 http_fetcher_->set_delegate(this); |
28 | 30 |
29 // Get the InstallPlan and read it | 31 // Get the InstallPlan and read it |
30 CHECK(HasInputObject()); | 32 CHECK(HasInputObject()); |
31 install_plan_ = GetInputObject(); | 33 install_plan_ = GetInputObject(); |
| 34 bytes_received_ = 0; |
32 | 35 |
33 install_plan_.Dump(); | 36 install_plan_.Dump(); |
34 | 37 |
35 if (writer_) { | 38 if (writer_) { |
36 LOG(INFO) << "Using writer for test."; | 39 LOG(INFO) << "Using writer for test."; |
37 } else { | 40 } else { |
38 if (install_plan_.is_full_update) { | 41 if (install_plan_.is_full_update) { |
39 kernel_file_writer_.reset(new DirectFileWriter); | 42 kernel_file_writer_.reset(new DirectFileWriter); |
40 rootfs_file_writer_.reset(new DirectFileWriter); | 43 rootfs_file_writer_.reset(new DirectFileWriter); |
41 split_file_writer_.reset(new SplitFileWriter(kernel_file_writer_.get(), | 44 split_file_writer_.reset(new SplitFileWriter(kernel_file_writer_.get(), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 void DownloadAction::TerminateProcessing() { | 80 void DownloadAction::TerminateProcessing() { |
78 CHECK(writer_); | 81 CHECK(writer_); |
79 CHECK_EQ(writer_->Close(), 0); | 82 CHECK_EQ(writer_->Close(), 0); |
80 writer_ = NULL; | 83 writer_ = NULL; |
81 http_fetcher_->TerminateTransfer(); | 84 http_fetcher_->TerminateTransfer(); |
82 } | 85 } |
83 | 86 |
84 void DownloadAction::ReceivedBytes(HttpFetcher *fetcher, | 87 void DownloadAction::ReceivedBytes(HttpFetcher *fetcher, |
85 const char* bytes, | 88 const char* bytes, |
86 int length) { | 89 int length) { |
| 90 bytes_received_ += length; |
| 91 if (delegate_) |
| 92 delegate_->BytesReceived(bytes_received_, install_plan_.size); |
87 int rc = writer_->Write(bytes, length); | 93 int rc = writer_->Write(bytes, length); |
88 TEST_AND_RETURN(rc >= 0); | 94 TEST_AND_RETURN(rc >= 0); |
89 omaha_hash_calculator_.Update(bytes, length); | 95 omaha_hash_calculator_.Update(bytes, length); |
90 } | 96 } |
91 | 97 |
92 namespace { | 98 namespace { |
93 void FlushLinuxCaches() { | 99 void FlushLinuxCaches() { |
94 vector<string> command; | 100 vector<string> command; |
95 command.push_back("/bin/sync"); | 101 command.push_back("/bin/sync"); |
96 int rc; | 102 int rc; |
97 LOG(INFO) << "FlushLinuxCaches/sync..."; | 103 LOG(INFO) << "FlushLinuxCaches-sync..."; |
98 Subprocess::SynchronousExec(command, &rc); | 104 Subprocess::SynchronousExec(command, &rc); |
99 LOG(INFO) << "FlushLinuxCaches/drop_caches..."; | 105 LOG(INFO) << "FlushLinuxCaches-drop_caches..."; |
100 | 106 |
101 const char* const drop_cmd = "3\n"; | 107 const char* const drop_cmd = "3\n"; |
102 utils::WriteFile("/proc/sys/vm/drop_caches", drop_cmd, strlen(drop_cmd)); | 108 utils::WriteFile("/proc/sys/vm/drop_caches", drop_cmd, strlen(drop_cmd)); |
103 | 109 |
104 LOG(INFO) << "FlushLinuxCaches done."; | 110 LOG(INFO) << "FlushLinuxCaches done."; |
105 } | 111 } |
106 } | 112 } |
107 | 113 |
108 void DownloadAction::TransferComplete(HttpFetcher *fetcher, bool successful) { | 114 void DownloadAction::TransferComplete(HttpFetcher *fetcher, bool successful) { |
109 if (writer_) { | 115 if (writer_) { |
(...skipping 13 matching lines...) Expand all Loading... |
123 | 129 |
124 FlushLinuxCaches(); | 130 FlushLinuxCaches(); |
125 | 131 |
126 // Write the path to the output pipe if we're successful | 132 // Write the path to the output pipe if we're successful |
127 if (successful && HasOutputPipe()) | 133 if (successful && HasOutputPipe()) |
128 SetOutputObject(GetInputObject()); | 134 SetOutputObject(GetInputObject()); |
129 processor_->ActionComplete(this, successful); | 135 processor_->ActionComplete(this, successful); |
130 } | 136 } |
131 | 137 |
132 }; // namespace {} | 138 }; // namespace {} |
OLD | NEW |