| 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 #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> |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 std::string display_version; | 86 std::string display_version; |
| 87 std::string codebase; | 87 std::string codebase; |
| 88 std::string more_info_url; | 88 std::string more_info_url; |
| 89 std::string hash; | 89 std::string hash; |
| 90 off_t size; | 90 off_t size; |
| 91 bool needs_admin; | 91 bool needs_admin; |
| 92 bool prompt; | 92 bool prompt; |
| 93 }; | 93 }; |
| 94 COMPILE_ASSERT(sizeof(off_t) == 8, off_t_not_64bit); | 94 COMPILE_ASSERT(sizeof(off_t) == 8, off_t_not_64bit); |
| 95 | 95 |
| 96 // This struct encapsulates the Omaha event information. For a |
| 97 // complete list of defined event types and results, see |
| 98 // http://code.google.com/p/omaha/wiki/ServerProtocol#event |
| 99 struct OmahaEvent { |
| 100 enum Type { |
| 101 kTypeUnknown = 0, |
| 102 kTypeDownloadComplete = 1, |
| 103 kTypeInstallComplete = 2, |
| 104 kTypeUpdateComplete = 3, |
| 105 }; |
| 106 |
| 107 enum Result { |
| 108 kResultError = 0, |
| 109 kResultSuccess = 1, |
| 110 }; |
| 111 |
| 112 OmahaEvent() |
| 113 : type(kTypeUnknown), |
| 114 result(kResultError), |
| 115 error_code(0) {} |
| 116 OmahaEvent(Type in_type, Result in_result, int in_error_code) |
| 117 : type(in_type), |
| 118 result(in_result), |
| 119 error_code(in_error_code) {} |
| 120 |
| 121 Type type; |
| 122 Result result; |
| 123 int error_code; |
| 124 }; |
| 125 |
| 96 class OmahaRequestAction; | 126 class OmahaRequestAction; |
| 97 class NoneType; | 127 class NoneType; |
| 98 | 128 |
| 99 template<> | 129 template<> |
| 100 class ActionTraits<OmahaRequestAction> { | 130 class ActionTraits<OmahaRequestAction> { |
| 101 public: | 131 public: |
| 102 // Takes parameters on the input pipe | 132 // Takes parameters on the input pipe. |
| 103 typedef OmahaRequestParams InputObjectType; | 133 typedef OmahaRequestParams InputObjectType; |
| 104 // On success, puts the output path on output | 134 // On UpdateCheck success, puts the Omaha response on output. Event |
| 135 // requests do not have an output pipe. |
| 105 typedef OmahaResponse OutputObjectType; | 136 typedef OmahaResponse OutputObjectType; |
| 106 }; | 137 }; |
| 107 | 138 |
| 108 class OmahaRequestAction : public Action<OmahaRequestAction>, | 139 class OmahaRequestAction : public Action<OmahaRequestAction>, |
| 109 public HttpFetcherDelegate { | 140 public HttpFetcherDelegate { |
| 110 public: | 141 public: |
| 111 // The ctor takes in all the parameters that will be used for | 142 // The ctor takes in all the parameters that will be used for making |
| 112 // making the request to Omaha. For some of them we have constants | 143 // the request to Omaha. For some of them we have constants that |
| 113 // that should be used. | 144 // should be used. |
| 145 // |
| 114 // Takes ownership of the passed in HttpFetcher. Useful for testing. | 146 // Takes ownership of the passed in HttpFetcher. Useful for testing. |
| 147 // |
| 148 // Takes ownership of the passed in OmahaEvent. If |event| is NULL, |
| 149 // this is an UpdateCheck request, otherwise it's an Event request. |
| 150 // Event requests always succeed. |
| 151 // |
| 115 // A good calling pattern is: | 152 // A good calling pattern is: |
| 116 // OmahaRequestAction(..., new WhateverHttpFetcher); | 153 // OmahaRequestAction(new OmahaEvent(...), new WhateverHttpFetcher); |
| 117 OmahaRequestAction(HttpFetcher* http_fetcher); | 154 // or |
| 155 // OmahaRequestAction(NULL, new WhateverHttpFetcher); |
| 156 OmahaRequestAction(OmahaEvent* event, |
| 157 HttpFetcher* http_fetcher); |
| 118 virtual ~OmahaRequestAction(); | 158 virtual ~OmahaRequestAction(); |
| 119 typedef ActionTraits<OmahaRequestAction>::InputObjectType InputObjectType; | 159 typedef ActionTraits<OmahaRequestAction>::InputObjectType InputObjectType; |
| 120 typedef ActionTraits<OmahaRequestAction>::OutputObjectType OutputObjectType; | 160 typedef ActionTraits<OmahaRequestAction>::OutputObjectType OutputObjectType; |
| 121 void PerformAction(); | 161 void PerformAction(); |
| 122 void TerminateProcessing(); | 162 void TerminateProcessing(); |
| 123 | 163 |
| 124 // Debugging/logging | 164 // Debugging/logging |
| 125 static std::string StaticType() { return "OmahaRequestAction"; } | 165 static std::string StaticType() { return "OmahaRequestAction"; } |
| 126 std::string Type() const { return StaticType(); } | 166 std::string Type() const { return StaticType(); } |
| 127 | 167 |
| 128 // Delegate methods (see http_fetcher.h) | 168 // Delegate methods (see http_fetcher.h) |
| 129 virtual void ReceivedBytes(HttpFetcher *fetcher, | 169 virtual void ReceivedBytes(HttpFetcher *fetcher, |
| 130 const char* bytes, int length); | 170 const char* bytes, int length); |
| 131 virtual void TransferComplete(HttpFetcher *fetcher, bool successful); | 171 virtual void TransferComplete(HttpFetcher *fetcher, bool successful); |
| 132 | 172 |
| 173 // Returns true if this is an Event request, false if it's an UpdateCheck. |
| 174 bool IsEvent() const { return event_.get() != NULL; } |
| 175 |
| 133 private: | 176 private: |
| 134 // These are data that are passed in the request to the Omaha server | 177 // These are data that are passed in the request to the Omaha server |
| 135 OmahaRequestParams params_; | 178 OmahaRequestParams params_; |
| 136 | 179 |
| 180 // Pointer to the OmahaEvent info. This is an UpdateCheck request if NULL. |
| 181 scoped_ptr<OmahaEvent> event_; |
| 182 |
| 137 // pointer to the HttpFetcher that does the http work | 183 // pointer to the HttpFetcher that does the http work |
| 138 scoped_ptr<HttpFetcher> http_fetcher_; | 184 scoped_ptr<HttpFetcher> http_fetcher_; |
| 139 | 185 |
| 140 // Stores the response from the omaha server | 186 // Stores the response from the omaha server |
| 141 std::vector<char> response_buffer_; | 187 std::vector<char> response_buffer_; |
| 142 | 188 |
| 143 DISALLOW_COPY_AND_ASSIGN(OmahaRequestAction); | 189 DISALLOW_COPY_AND_ASSIGN(OmahaRequestAction); |
| 144 }; | 190 }; |
| 145 | 191 |
| 146 } // namespace chromeos_update_engine | 192 } // namespace chromeos_update_engine |
| 147 | 193 |
| 148 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__ | 194 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__ |
| OLD | NEW |