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

Side by Side Diff: omaha_request_action.h

Issue 2836053: Turn OmahaRequestPrepAction into OmahaRequestDeviceParams. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: Update copyrights. Created 10 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « main.cc ('k') | omaha_request_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) 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 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__ 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__ 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__
7 7
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <sys/types.h> 9 #include <sys/types.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/http_fetcher.h" 18 #include "update_engine/http_fetcher.h"
19 19
20 // The Omaha Request action makes a request to Omaha and can output 20 // The Omaha Request action makes a request to Omaha and can output
21 // the response on the output ActionPipe. 21 // the response on the output ActionPipe.
22 22
23 namespace chromeos_update_engine { 23 namespace chromeos_update_engine {
24 24
25 // Encodes XML entities in a given string with libxml2. input must be 25 // Encodes XML entities in a given string with libxml2. input must be
26 // UTF-8 formatted. Output will be UTF-8 formatted. 26 // UTF-8 formatted. Output will be UTF-8 formatted.
27 std::string XmlEncode(const std::string& input); 27 std::string XmlEncode(const std::string& input);
28 28
29 // This struct encapsulates the data Omaha gets for the request.
30 // These strings in this struct should not be XML escaped.
31 struct OmahaRequestParams {
32 OmahaRequestParams()
33 : os_platform(kOsPlatform), os_version(kOsVersion), app_id(kAppId) {}
34 OmahaRequestParams(const std::string& in_machine_id,
35 const std::string& in_user_id,
36 const std::string& in_os_platform,
37 const std::string& in_os_version,
38 const std::string& in_os_sp,
39 const std::string& in_os_board,
40 const std::string& in_app_id,
41 const std::string& in_app_version,
42 const std::string& in_app_lang,
43 const std::string& in_app_track,
44 const std::string& in_update_url)
45 : machine_id(in_machine_id),
46 user_id(in_user_id),
47 os_platform(in_os_platform),
48 os_version(in_os_version),
49 os_sp(in_os_sp),
50 os_board(in_os_board),
51 app_id(in_app_id),
52 app_version(in_app_version),
53 app_lang(in_app_lang),
54 app_track(in_app_track),
55 update_url(in_update_url) {}
56
57 std::string machine_id;
58 std::string user_id;
59 std::string os_platform;
60 std::string os_version;
61 std::string os_sp;
62 std::string os_board;
63 std::string app_id;
64 std::string app_version;
65 std::string app_lang;
66 std::string app_track;
67
68 std::string update_url;
69
70 // Suggested defaults
71 static const char* const kAppId;
72 static const char* const kOsPlatform;
73 static const char* const kOsVersion;
74 static const char* const kUpdateUrl;
75 };
76
77 // This struct encapsulates the data Omaha's response for the request. 29 // This struct encapsulates the data Omaha's response for the request.
78 // These strings in this struct are not XML escaped. 30 // These strings in this struct are not XML escaped.
79 struct OmahaResponse { 31 struct OmahaResponse {
80 OmahaResponse() 32 OmahaResponse()
81 : update_exists(false), size(0), needs_admin(false), prompt(false) {} 33 : update_exists(false), size(0), needs_admin(false), prompt(false) {}
82 // True iff there is an update to be downloaded. 34 // True iff there is an update to be downloaded.
83 bool update_exists; 35 bool update_exists;
84 36
85 // These are only valid if update_exists is true: 37 // These are only valid if update_exists is true:
86 std::string display_version; 38 std::string display_version;
(...skipping 29 matching lines...) Expand all
116 OmahaEvent(Type in_type, Result in_result, int in_error_code) 68 OmahaEvent(Type in_type, Result in_result, int in_error_code)
117 : type(in_type), 69 : type(in_type),
118 result(in_result), 70 result(in_result),
119 error_code(in_error_code) {} 71 error_code(in_error_code) {}
120 72
121 Type type; 73 Type type;
122 Result result; 74 Result result;
123 int error_code; 75 int error_code;
124 }; 76 };
125 77
78 class NoneType;
126 class OmahaRequestAction; 79 class OmahaRequestAction;
127 class NoneType; 80 struct OmahaRequestParams;
128 81
129 template<> 82 template<>
130 class ActionTraits<OmahaRequestAction> { 83 class ActionTraits<OmahaRequestAction> {
131 public: 84 public:
132 // Takes parameters on the input pipe. 85 // Takes parameters on the input pipe.
133 typedef OmahaRequestParams InputObjectType; 86 typedef NoneType InputObjectType;
134 // On UpdateCheck success, puts the Omaha response on output. Event 87 // On UpdateCheck success, puts the Omaha response on output. Event
135 // requests do not have an output pipe. 88 // requests do not have an output pipe.
136 typedef OmahaResponse OutputObjectType; 89 typedef OmahaResponse OutputObjectType;
137 }; 90 };
138 91
139 class OmahaRequestAction : public Action<OmahaRequestAction>, 92 class OmahaRequestAction : public Action<OmahaRequestAction>,
140 public HttpFetcherDelegate { 93 public HttpFetcherDelegate {
141 public: 94 public:
142 // The ctor takes in all the parameters that will be used for making 95 // The ctor takes in all the parameters that will be used for making
143 // the request to Omaha. For some of them we have constants that 96 // the request to Omaha. For some of them we have constants that
144 // should be used. 97 // should be used.
145 // 98 //
146 // Takes ownership of the passed in HttpFetcher. Useful for testing. 99 // Takes ownership of the passed in HttpFetcher. Useful for testing.
147 // 100 //
148 // Takes ownership of the passed in OmahaEvent. If |event| is NULL, 101 // Takes ownership of the passed in OmahaEvent. If |event| is NULL,
149 // this is an UpdateCheck request, otherwise it's an Event request. 102 // this is an UpdateCheck request, otherwise it's an Event request.
150 // Event requests always succeed. 103 // Event requests always succeed.
151 // 104 //
152 // A good calling pattern is: 105 // A good calling pattern is:
153 // OmahaRequestAction(new OmahaEvent(...), new WhateverHttpFetcher); 106 // OmahaRequestAction(..., new OmahaEvent(...), new WhateverHttpFetcher);
154 // or 107 // or
155 // OmahaRequestAction(NULL, new WhateverHttpFetcher); 108 // OmahaRequestAction(..., NULL, new WhateverHttpFetcher);
156 OmahaRequestAction(OmahaEvent* event, 109 OmahaRequestAction(const OmahaRequestParams& params,
110 OmahaEvent* event,
157 HttpFetcher* http_fetcher); 111 HttpFetcher* http_fetcher);
158 virtual ~OmahaRequestAction(); 112 virtual ~OmahaRequestAction();
159 typedef ActionTraits<OmahaRequestAction>::InputObjectType InputObjectType; 113 typedef ActionTraits<OmahaRequestAction>::InputObjectType InputObjectType;
160 typedef ActionTraits<OmahaRequestAction>::OutputObjectType OutputObjectType; 114 typedef ActionTraits<OmahaRequestAction>::OutputObjectType OutputObjectType;
161 void PerformAction(); 115 void PerformAction();
162 void TerminateProcessing(); 116 void TerminateProcessing();
163 117
164 // Debugging/logging 118 // Debugging/logging
165 static std::string StaticType() { return "OmahaRequestAction"; } 119 static std::string StaticType() { return "OmahaRequestAction"; }
166 std::string Type() const { return StaticType(); } 120 std::string Type() const { return StaticType(); }
167 121
168 // Delegate methods (see http_fetcher.h) 122 // Delegate methods (see http_fetcher.h)
169 virtual void ReceivedBytes(HttpFetcher *fetcher, 123 virtual void ReceivedBytes(HttpFetcher *fetcher,
170 const char* bytes, int length); 124 const char* bytes, int length);
171 virtual void TransferComplete(HttpFetcher *fetcher, bool successful); 125 virtual void TransferComplete(HttpFetcher *fetcher, bool successful);
172 126
173 // Returns true if this is an Event request, false if it's an UpdateCheck. 127 // Returns true if this is an Event request, false if it's an UpdateCheck.
174 bool IsEvent() const { return event_.get() != NULL; } 128 bool IsEvent() const { return event_.get() != NULL; }
175 129
176 private: 130 private:
177 // These are data that are passed in the request to the Omaha server 131 // These are data that are passed in the request to the Omaha server.
178 OmahaRequestParams params_; 132 const OmahaRequestParams& params_;
179 133
180 // Pointer to the OmahaEvent info. This is an UpdateCheck request if NULL. 134 // Pointer to the OmahaEvent info. This is an UpdateCheck request if NULL.
181 scoped_ptr<OmahaEvent> event_; 135 scoped_ptr<OmahaEvent> event_;
182 136
183 // pointer to the HttpFetcher that does the http work 137 // pointer to the HttpFetcher that does the http work
184 scoped_ptr<HttpFetcher> http_fetcher_; 138 scoped_ptr<HttpFetcher> http_fetcher_;
185 139
186 // Stores the response from the omaha server 140 // Stores the response from the omaha server
187 std::vector<char> response_buffer_; 141 std::vector<char> response_buffer_;
188 142
189 DISALLOW_COPY_AND_ASSIGN(OmahaRequestAction); 143 DISALLOW_COPY_AND_ASSIGN(OmahaRequestAction);
190 }; 144 };
191 145
192 } // namespace chromeos_update_engine 146 } // namespace chromeos_update_engine
193 147
194 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__ 148 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__
OLDNEW
« no previous file with comments | « main.cc ('k') | omaha_request_action.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698