rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DOWNLOAD_ACTION_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DOWNLOAD_ACTION_H__ |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 7 | |
| 8 | #include <sys/types.h> |
| 9 | #include <sys/stat.h> |
| 10 | #include <fcntl.h> |
| 11 | |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 12 | #include <string> |
| 13 | |
| 14 | #include <curl/curl.h> |
| 15 | |
| 16 | #include "base/scoped_ptr.h" |
| 17 | #include "update_engine/action.h" |
| 18 | #include "update_engine/decompressing_file_writer.h" |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 19 | #include "update_engine/delta_performer.h" |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 20 | #include "update_engine/file_writer.h" |
| 21 | #include "update_engine/http_fetcher.h" |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 22 | #include "update_engine/install_plan.h" |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 23 | #include "update_engine/omaha_hash_calculator.h" |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 24 | #include "update_engine/split_file_writer.h" |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 25 | |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 26 | // The Download Action downloads a specified url to disk. The url should |
| 27 | // point to either a full or delta update. If a full update, the file will |
| 28 | // be piped into a SplitFileWriter, which will direct it to the kernel |
| 29 | // and rootfs partitions. If it's a delta update, the destination kernel |
| 30 | // and rootfs should already contain the source-version that this delta |
| 31 | // update goes from. In this case, the update will be piped into a |
| 32 | // DeltaPerformer that will apply the delta to the disk. |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 33 | |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 34 | namespace chromeos_update_engine { |
| 35 | |
| 36 | class DownloadAction; |
| 37 | class NoneType; |
| 38 | |
| 39 | template<> |
| 40 | class ActionTraits<DownloadAction> { |
| 41 | public: |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 42 | // Takes and returns an InstallPlan |
| 43 | typedef InstallPlan InputObjectType; |
| 44 | typedef InstallPlan OutputObjectType; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | class DownloadAction : public Action<DownloadAction>, |
| 48 | public HttpFetcherDelegate { |
| 49 | public: |
| 50 | // Takes ownership of the passed in HttpFetcher. Useful for testing. |
| 51 | // A good calling pattern is: |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 52 | // DownloadAction(new WhateverHttpFetcher); |
| 53 | DownloadAction(HttpFetcher* http_fetcher); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 54 | virtual ~DownloadAction(); |
| 55 | typedef ActionTraits<DownloadAction>::InputObjectType InputObjectType; |
| 56 | typedef ActionTraits<DownloadAction>::OutputObjectType OutputObjectType; |
| 57 | void PerformAction(); |
| 58 | void TerminateProcessing(); |
| 59 | |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 60 | // Testing |
| 61 | void SetTestFileWriter(FileWriter* writer) { |
| 62 | writer_ = writer; |
| 63 | } |
| 64 | |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 65 | // Debugging/logging |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 66 | static std::string StaticType() { return "DownloadAction"; } |
| 67 | std::string Type() const { return StaticType(); } |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 68 | |
| 69 | // Delegate methods (see http_fetcher.h) |
| 70 | virtual void ReceivedBytes(HttpFetcher *fetcher, |
| 71 | const char* bytes, int length); |
| 72 | virtual void TransferComplete(HttpFetcher *fetcher, bool successful); |
| 73 | |
| 74 | private: |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 75 | // The InstallPlan passed in |
| 76 | InstallPlan install_plan_; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 77 | |
| 78 | // The FileWriter that downloaded data should be written to. It will |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 79 | // either point to *decompressing_file_writer_ or *delta_performer_. |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 80 | FileWriter* writer_; |
| 81 | |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 82 | // These are used for full updates: |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 83 | scoped_ptr<GzipDecompressingFileWriter> decompressing_file_writer_; |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 84 | scoped_ptr<SplitFileWriter> split_file_writer_; |
| 85 | scoped_ptr<DirectFileWriter> kernel_file_writer_; |
| 86 | scoped_ptr<DirectFileWriter> rootfs_file_writer_; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 87 | |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 88 | // Used to apply a delta update: |
| 89 | scoped_ptr<DeltaPerformer> delta_performer_; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 90 | |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 91 | // Pointer to the HttpFetcher that does the http work. |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 92 | scoped_ptr<HttpFetcher> http_fetcher_; |
| 93 | |
| 94 | // Used to find the hash of the bytes downloaded |
| 95 | OmahaHashCalculator omaha_hash_calculator_; |
| 96 | DISALLOW_COPY_AND_ASSIGN(DownloadAction); |
| 97 | }; |
| 98 | |
| 99 | // We want to be sure that we're compiled with large file support on linux, |
| 100 | // just in case we find ourselves downloading large images. |
| 101 | COMPILE_ASSERT(8 == sizeof(off_t), off_t_not_64_bit); |
| 102 | |
| 103 | } // namespace chromeos_update_engine |
| 104 | |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 105 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DOWNLOAD_ACTION_H__ |