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

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

Issue 466036: AU: Beginnings of delta support (Closed)
Patch Set: Created 11 years 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
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 UPDATE_ENGINE_DOWNLOAD_ACTION_H__ 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DOWNLOAD_ACTION_H__
6 #define 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 <map> 12 #include <map>
13 #include <string> 13 #include <string>
14 14
15 #include <curl/curl.h> 15 #include <curl/curl.h>
16 16
17 #include "base/scoped_ptr.h" 17 #include "base/scoped_ptr.h"
18 #include "update_engine/action.h" 18 #include "update_engine/action.h"
19 #include "update_engine/decompressing_file_writer.h" 19 #include "update_engine/decompressing_file_writer.h"
20 #include "update_engine/file_writer.h" 20 #include "update_engine/file_writer.h"
21 #include "update_engine/http_fetcher.h" 21 #include "update_engine/http_fetcher.h"
22 #include "update_engine/install_plan.h"
22 #include "update_engine/omaha_hash_calculator.h" 23 #include "update_engine/omaha_hash_calculator.h"
23 24
24 // The Download Action downloads a requested url to a specified path on disk. 25 // The Download Action downloads a requested url to a specified path on disk.
25 // It takes no input object, but if successful, passes the output path 26 // The url and output path are determined by the InstallPlan passed in.
26 // to the output pipe.
27 27
28 using std::map; 28 using std::map;
29 using std::string; 29 using std::string;
30 30
31 namespace chromeos_update_engine { 31 namespace chromeos_update_engine {
32 32
33 class DownloadAction; 33 class DownloadAction;
34 class NoneType; 34 class NoneType;
35 35
36 template<> 36 template<>
37 class ActionTraits<DownloadAction> { 37 class ActionTraits<DownloadAction> {
38 public: 38 public:
39 // Does not take an object for input 39 // Takes and returns an InstallPlan
40 typedef NoneType InputObjectType; 40 typedef InstallPlan InputObjectType;
41 // On success, puts the output path on output 41 typedef InstallPlan OutputObjectType;
42 typedef std::string OutputObjectType;
43 }; 42 };
44 43
45 class DownloadAction : public Action<DownloadAction>, 44 class DownloadAction : public Action<DownloadAction>,
46 public HttpFetcherDelegate { 45 public HttpFetcherDelegate {
47 public: 46 public:
48 // Takes ownership of the passed in HttpFetcher. Useful for testing. 47 // Takes ownership of the passed in HttpFetcher. Useful for testing.
49 // A good calling pattern is: 48 // A good calling pattern is:
50 // DownloadAction(..., new WhateverHttpFetcher); 49 // DownloadAction(new WhateverHttpFetcher);
51 DownloadAction(const std::string& url, const std::string& output_path, 50 DownloadAction(HttpFetcher* http_fetcher);
52 off_t size, const std::string& hash,
53 const bool should_decompress,
54 HttpFetcher* http_fetcher);
55 virtual ~DownloadAction(); 51 virtual ~DownloadAction();
56 typedef ActionTraits<DownloadAction>::InputObjectType InputObjectType; 52 typedef ActionTraits<DownloadAction>::InputObjectType InputObjectType;
57 typedef ActionTraits<DownloadAction>::OutputObjectType OutputObjectType; 53 typedef ActionTraits<DownloadAction>::OutputObjectType OutputObjectType;
58 void PerformAction(); 54 void PerformAction();
59 void TerminateProcessing(); 55 void TerminateProcessing();
60 56
61 // Debugging/logging 57 // Debugging/logging
62 std::string Type() const { return "DownloadAction"; } 58 static std::string StaticType() { return "DownloadAction"; }
59 std::string Type() const { return StaticType(); }
63 60
64 // Delegate methods (see http_fetcher.h) 61 // Delegate methods (see http_fetcher.h)
65 virtual void ReceivedBytes(HttpFetcher *fetcher, 62 virtual void ReceivedBytes(HttpFetcher *fetcher,
66 const char* bytes, int length); 63 const char* bytes, int length);
67 virtual void TransferComplete(HttpFetcher *fetcher, bool successful); 64 virtual void TransferComplete(HttpFetcher *fetcher, bool successful);
68 65
69 private: 66 private:
70 // Expected size of the file (will be used for progress info) 67 // Expected size of the file (will be used for progress info)
71 const size_t size_; 68 const size_t size_;
72 69
73 // URL to download 70 // URL to download
74 const std::string url_; 71 std::string url_;
75 72
76 // Path to save URL to 73 // Path to save URL to
77 const std::string output_path_; 74 std::string output_path_;
78 75
79 // Expected hash of the file. The hash must match for this action to 76 // Expected hash of the file. The hash must match for this action to
80 // succeed. 77 // succeed.
81 const std::string hash_; 78 std::string hash_;
82 79
83 // Whether the caller requested that we decompress the downloaded data. 80 // Whether the caller requested that we decompress the downloaded data.
84 const bool should_decompress_; 81 bool should_decompress_;
85 82
86 // The FileWriter that downloaded data should be written to. It will 83 // The FileWriter that downloaded data should be written to. It will
87 // either point to *decompressing_file_writer_ or *direct_file_writer_. 84 // either point to *decompressing_file_writer_ or *direct_file_writer_.
88 FileWriter* writer_; 85 FileWriter* writer_;
89 86
90 // If non-null, a FileWriter used for gzip decompressing downloaded data 87 // If non-null, a FileWriter used for gzip decompressing downloaded data
91 scoped_ptr<GzipDecompressingFileWriter> decompressing_file_writer_; 88 scoped_ptr<GzipDecompressingFileWriter> decompressing_file_writer_;
92 89
93 // Used to write out the downloaded file 90 // Used to write out the downloaded file
94 scoped_ptr<DirectFileWriter> direct_file_writer_; 91 scoped_ptr<DirectFileWriter> direct_file_writer_;
95 92
96 // pointer to the HttpFetcher that does the http work 93 // pointer to the HttpFetcher that does the http work
97 scoped_ptr<HttpFetcher> http_fetcher_; 94 scoped_ptr<HttpFetcher> http_fetcher_;
98 95
99 // Used to find the hash of the bytes downloaded 96 // Used to find the hash of the bytes downloaded
100 OmahaHashCalculator omaha_hash_calculator_; 97 OmahaHashCalculator omaha_hash_calculator_;
101 DISALLOW_COPY_AND_ASSIGN(DownloadAction); 98 DISALLOW_COPY_AND_ASSIGN(DownloadAction);
102 }; 99 };
103 100
104 // We want to be sure that we're compiled with large file support on linux, 101 // We want to be sure that we're compiled with large file support on linux,
105 // just in case we find ourselves downloading large images. 102 // just in case we find ourselves downloading large images.
106 COMPILE_ASSERT(8 == sizeof(off_t), off_t_not_64_bit); 103 COMPILE_ASSERT(8 == sizeof(off_t), off_t_not_64_bit);
107 104
108 } // namespace chromeos_update_engine 105 } // namespace chromeos_update_engine
109 106
110 #endif // UPDATE_ENGINE_DOWNLOAD_ACTION_H__ 107 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DOWNLOAD_ACTION_H__
OLDNEW
« no previous file with comments | « src/platform/update_engine/decompressing_file_writer.cc ('k') | src/platform/update_engine/download_action.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698