Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: src/platform/update_engine/download_action.h

Issue 1694025: AU: Update Downloader to support our image formats. (Closed) Base URL: ssh://git@chromiumos-git/chromeos
Patch Set: fixes for review Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/platform/update_engine/download_action.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DOWNLOAD_ACTION_H__ 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DOWNLOAD_ACTION_H__
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DOWNLOAD_ACTION_H__ 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DOWNLOAD_ACTION_H__
7 7
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <fcntl.h> 10 #include <fcntl.h>
11 11
12 #include <string> 12 #include <string>
13 13
14 #include <curl/curl.h> 14 #include <curl/curl.h>
15 15
16 #include "base/scoped_ptr.h" 16 #include "base/scoped_ptr.h"
17 #include "update_engine/action.h" 17 #include "update_engine/action.h"
18 #include "update_engine/decompressing_file_writer.h" 18 #include "update_engine/decompressing_file_writer.h"
19 #include "update_engine/delta_performer.h"
19 #include "update_engine/file_writer.h" 20 #include "update_engine/file_writer.h"
20 #include "update_engine/http_fetcher.h" 21 #include "update_engine/http_fetcher.h"
21 #include "update_engine/install_plan.h" 22 #include "update_engine/install_plan.h"
22 #include "update_engine/omaha_hash_calculator.h" 23 #include "update_engine/omaha_hash_calculator.h"
24 #include "update_engine/split_file_writer.h"
23 25
24 // The Download Action downloads a requested url to a specified path on disk. 26 // The Download Action downloads a specified url to disk. The url should
25 // The url and output path are determined by the InstallPlan passed in. 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.
26 33
27 namespace chromeos_update_engine { 34 namespace chromeos_update_engine {
28 35
29 class DownloadAction; 36 class DownloadAction;
30 class NoneType; 37 class NoneType;
31 38
32 template<> 39 template<>
33 class ActionTraits<DownloadAction> { 40 class ActionTraits<DownloadAction> {
34 public: 41 public:
35 // Takes and returns an InstallPlan 42 // Takes and returns an InstallPlan
36 typedef InstallPlan InputObjectType; 43 typedef InstallPlan InputObjectType;
37 typedef InstallPlan OutputObjectType; 44 typedef InstallPlan OutputObjectType;
38 }; 45 };
39 46
40 class DownloadAction : public Action<DownloadAction>, 47 class DownloadAction : public Action<DownloadAction>,
41 public HttpFetcherDelegate { 48 public HttpFetcherDelegate {
42 public: 49 public:
43 // Takes ownership of the passed in HttpFetcher. Useful for testing. 50 // Takes ownership of the passed in HttpFetcher. Useful for testing.
44 // A good calling pattern is: 51 // A good calling pattern is:
45 // DownloadAction(new WhateverHttpFetcher); 52 // DownloadAction(new WhateverHttpFetcher);
46 DownloadAction(HttpFetcher* http_fetcher); 53 DownloadAction(HttpFetcher* http_fetcher);
47 virtual ~DownloadAction(); 54 virtual ~DownloadAction();
48 typedef ActionTraits<DownloadAction>::InputObjectType InputObjectType; 55 typedef ActionTraits<DownloadAction>::InputObjectType InputObjectType;
49 typedef ActionTraits<DownloadAction>::OutputObjectType OutputObjectType; 56 typedef ActionTraits<DownloadAction>::OutputObjectType OutputObjectType;
50 void PerformAction(); 57 void PerformAction();
51 void TerminateProcessing(); 58 void TerminateProcessing();
52 59
60 // Testing
61 void SetTestFileWriter(FileWriter* writer) {
62 writer_ = writer;
63 }
64
53 // Debugging/logging 65 // Debugging/logging
54 static std::string StaticType() { return "DownloadAction"; } 66 static std::string StaticType() { return "DownloadAction"; }
55 std::string Type() const { return StaticType(); } 67 std::string Type() const { return StaticType(); }
56 68
57 // Delegate methods (see http_fetcher.h) 69 // Delegate methods (see http_fetcher.h)
58 virtual void ReceivedBytes(HttpFetcher *fetcher, 70 virtual void ReceivedBytes(HttpFetcher *fetcher,
59 const char* bytes, int length); 71 const char* bytes, int length);
60 virtual void TransferComplete(HttpFetcher *fetcher, bool successful); 72 virtual void TransferComplete(HttpFetcher *fetcher, bool successful);
61 73
62 private: 74 private:
63 // Expected size of the file (will be used for progress info) 75 // The InstallPlan passed in
64 const size_t size_; 76 InstallPlan install_plan_;
65
66 // URL to download
67 std::string url_;
68
69 // Path to save URL to
70 std::string output_path_;
71
72 // Expected hash of the file. The hash must match for this action to
73 // succeed.
74 std::string hash_;
75
76 // Whether the caller requested that we decompress the downloaded data.
77 bool should_decompress_;
78 77
79 // The FileWriter that downloaded data should be written to. It will 78 // The FileWriter that downloaded data should be written to. It will
80 // either point to *decompressing_file_writer_ or *direct_file_writer_. 79 // either point to *decompressing_file_writer_ or *delta_performer_.
81 FileWriter* writer_; 80 FileWriter* writer_;
82 81
83 // If non-null, a FileWriter used for gzip decompressing downloaded data 82 // These are used for full updates:
84 scoped_ptr<GzipDecompressingFileWriter> decompressing_file_writer_; 83 scoped_ptr<GzipDecompressingFileWriter> decompressing_file_writer_;
84 scoped_ptr<SplitFileWriter> split_file_writer_;
85 scoped_ptr<DirectFileWriter> kernel_file_writer_;
86 scoped_ptr<DirectFileWriter> rootfs_file_writer_;
85 87
86 // Used to write out the downloaded file 88 // Used to apply a delta update:
87 scoped_ptr<DirectFileWriter> direct_file_writer_; 89 scoped_ptr<DeltaPerformer> delta_performer_;
88 90
89 // pointer to the HttpFetcher that does the http work 91 // Pointer to the HttpFetcher that does the http work.
90 scoped_ptr<HttpFetcher> http_fetcher_; 92 scoped_ptr<HttpFetcher> http_fetcher_;
91 93
92 // Used to find the hash of the bytes downloaded 94 // Used to find the hash of the bytes downloaded
93 OmahaHashCalculator omaha_hash_calculator_; 95 OmahaHashCalculator omaha_hash_calculator_;
94 DISALLOW_COPY_AND_ASSIGN(DownloadAction); 96 DISALLOW_COPY_AND_ASSIGN(DownloadAction);
95 }; 97 };
96 98
97 // We want to be sure that we're compiled with large file support on linux, 99 // We want to be sure that we're compiled with large file support on linux,
98 // just in case we find ourselves downloading large images. 100 // just in case we find ourselves downloading large images.
99 COMPILE_ASSERT(8 == sizeof(off_t), off_t_not_64_bit); 101 COMPILE_ASSERT(8 == sizeof(off_t), off_t_not_64_bit);
100 102
101 } // namespace chromeos_update_engine 103 } // namespace chromeos_update_engine
102 104
103 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DOWNLOAD_ACTION_H__ 105 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DOWNLOAD_ACTION_H__
OLDNEW
« no previous file with comments | « no previous file | src/platform/update_engine/download_action.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698