Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 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> |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 error_code(in_error_code) {} | 78 error_code(in_error_code) {} |
| 79 | 79 |
| 80 Type type; | 80 Type type; |
| 81 Result result; | 81 Result result; |
| 82 ActionExitCode error_code; | 82 ActionExitCode error_code; |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 class NoneType; | 85 class NoneType; |
| 86 class OmahaRequestAction; | 86 class OmahaRequestAction; |
| 87 struct OmahaRequestParams; | 87 struct OmahaRequestParams; |
| 88 class PrefsInterface; | |
| 88 | 89 |
| 89 template<> | 90 template<> |
| 90 class ActionTraits<OmahaRequestAction> { | 91 class ActionTraits<OmahaRequestAction> { |
| 91 public: | 92 public: |
| 92 // Takes parameters on the input pipe. | 93 // Takes parameters on the input pipe. |
| 93 typedef NoneType InputObjectType; | 94 typedef NoneType InputObjectType; |
| 94 // On UpdateCheck success, puts the Omaha response on output. Event | 95 // On UpdateCheck success, puts the Omaha response on output. Event |
| 95 // requests do not have an output pipe. | 96 // requests do not have an output pipe. |
| 96 typedef OmahaResponse OutputObjectType; | 97 typedef OmahaResponse OutputObjectType; |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 class OmahaRequestAction : public Action<OmahaRequestAction>, | 100 class OmahaRequestAction : public Action<OmahaRequestAction>, |
| 100 public HttpFetcherDelegate { | 101 public HttpFetcherDelegate { |
| 101 public: | 102 public: |
| 103 static const int kNeverPinged = -1; | |
| 104 static const int kPingTimeJump = -2; | |
| 105 | |
| 102 // The ctor takes in all the parameters that will be used for making | 106 // The ctor takes in all the parameters that will be used for making |
| 103 // the request to Omaha. For some of them we have constants that | 107 // the request to Omaha. For some of them we have constants that |
| 104 // should be used. | 108 // should be used. |
| 105 // | 109 // |
| 106 // Takes ownership of the passed in HttpFetcher. Useful for testing. | 110 // Takes ownership of the passed in HttpFetcher. Useful for testing. |
| 107 // | 111 // |
| 108 // Takes ownership of the passed in OmahaEvent. If |event| is NULL, | 112 // Takes ownership of the passed in OmahaEvent. If |event| is NULL, |
| 109 // this is an UpdateCheck request, otherwise it's an Event request. | 113 // this is an UpdateCheck request, otherwise it's an Event request. |
| 110 // Event requests always succeed. | 114 // Event requests always succeed. |
| 111 // | 115 // |
| 112 // A good calling pattern is: | 116 // A good calling pattern is: |
| 113 // OmahaRequestAction(..., new OmahaEvent(...), new WhateverHttpFetcher); | 117 // OmahaRequestAction(..., new OmahaEvent(...), new WhateverHttpFetcher); |
| 114 // or | 118 // or |
| 115 // OmahaRequestAction(..., NULL, new WhateverHttpFetcher); | 119 // OmahaRequestAction(..., NULL, new WhateverHttpFetcher); |
| 116 OmahaRequestAction(const OmahaRequestParams& params, | 120 OmahaRequestAction(PrefsInterface* prefs, |
| 121 const OmahaRequestParams& params, | |
| 117 OmahaEvent* event, | 122 OmahaEvent* event, |
| 118 HttpFetcher* http_fetcher); | 123 HttpFetcher* http_fetcher); |
| 119 virtual ~OmahaRequestAction(); | 124 virtual ~OmahaRequestAction(); |
| 120 typedef ActionTraits<OmahaRequestAction>::InputObjectType InputObjectType; | 125 typedef ActionTraits<OmahaRequestAction>::InputObjectType InputObjectType; |
| 121 typedef ActionTraits<OmahaRequestAction>::OutputObjectType OutputObjectType; | 126 typedef ActionTraits<OmahaRequestAction>::OutputObjectType OutputObjectType; |
| 122 void PerformAction(); | 127 void PerformAction(); |
| 123 void TerminateProcessing(); | 128 void TerminateProcessing(); |
| 124 | 129 |
| 125 // Debugging/logging | 130 // Debugging/logging |
| 126 static std::string StaticType() { return "OmahaRequestAction"; } | 131 static std::string StaticType() { return "OmahaRequestAction"; } |
| 127 std::string Type() const { return StaticType(); } | 132 std::string Type() const { return StaticType(); } |
| 128 | 133 |
| 129 // Delegate methods (see http_fetcher.h) | 134 // Delegate methods (see http_fetcher.h) |
| 130 virtual void ReceivedBytes(HttpFetcher *fetcher, | 135 virtual void ReceivedBytes(HttpFetcher *fetcher, |
| 131 const char* bytes, int length); | 136 const char* bytes, int length); |
| 132 virtual void TransferComplete(HttpFetcher *fetcher, bool successful); | 137 virtual void TransferComplete(HttpFetcher *fetcher, bool successful); |
| 133 | 138 |
| 134 // Returns true if this is an Event request, false if it's an UpdateCheck. | 139 // Returns true if this is an Event request, false if it's an UpdateCheck. |
| 135 bool IsEvent() const { return event_.get() != NULL; } | 140 bool IsEvent() const { return event_.get() != NULL; } |
| 136 | 141 |
| 137 private: | 142 private: |
| 143 // If this is an update check request, initializes | |
| 144 // |ping_active_days_| and |ping_roll_call_days_| to values that may | |
| 145 // be sent as pings to Omaha. | |
| 146 void InitPingDays(); | |
| 147 | |
| 148 // Based on the perstitent preference store values, calculates the | |
|
Carl Nygaard
2010/07/29 21:02:53
perstitent -> persistent
| |
| 149 // number of days since the last ping sent for |key|. | |
| 150 int CalculatePingDays(const std::string& key); | |
| 151 | |
| 152 // Access to the preferences store. | |
| 153 PrefsInterface* prefs_; | |
| 154 | |
| 138 // These are data that are passed in the request to the Omaha server. | 155 // These are data that are passed in the request to the Omaha server. |
| 139 const OmahaRequestParams& params_; | 156 const OmahaRequestParams& params_; |
| 140 | 157 |
| 141 // Pointer to the OmahaEvent info. This is an UpdateCheck request if NULL. | 158 // Pointer to the OmahaEvent info. This is an UpdateCheck request if NULL. |
| 142 scoped_ptr<OmahaEvent> event_; | 159 scoped_ptr<OmahaEvent> event_; |
| 143 | 160 |
| 144 // pointer to the HttpFetcher that does the http work | 161 // pointer to the HttpFetcher that does the http work |
| 145 scoped_ptr<HttpFetcher> http_fetcher_; | 162 scoped_ptr<HttpFetcher> http_fetcher_; |
| 146 | 163 |
| 147 // Stores the response from the omaha server | 164 // Stores the response from the omaha server |
| 148 std::vector<char> response_buffer_; | 165 std::vector<char> response_buffer_; |
| 149 | 166 |
| 167 // Initialized by InitPingDays to values that may be sent to Omaha | |
| 168 // as part of a ping message. Note that only positive values and -1 | |
| 169 // are sent to Omaha. | |
| 170 int ping_active_days_; | |
| 171 int ping_roll_call_days_; | |
| 172 | |
| 150 DISALLOW_COPY_AND_ASSIGN(OmahaRequestAction); | 173 DISALLOW_COPY_AND_ASSIGN(OmahaRequestAction); |
| 151 }; | 174 }; |
| 152 | 175 |
| 153 } // namespace chromeos_update_engine | 176 } // namespace chromeos_update_engine |
| 154 | 177 |
| 155 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__ | 178 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_REQUEST_ACTION_H__ |
| OLD | NEW |