| 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_HTTP_FETCHER_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_HTTP_FETCHER_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_HTTP_FETCHER_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_HTTP_FETCHER_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include <glib.h> | 10 #include <glib.h> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 // Optional: Post data to the server. The HttpFetcher should make a copy | 36 // Optional: Post data to the server. The HttpFetcher should make a copy |
| 37 // of this data and upload it via HTTP POST during the transfer. | 37 // of this data and upload it via HTTP POST during the transfer. |
| 38 void SetPostData(const void* data, size_t size) { | 38 void SetPostData(const void* data, size_t size) { |
| 39 post_data_set_ = true; | 39 post_data_set_ = true; |
| 40 post_data_.clear(); | 40 post_data_.clear(); |
| 41 const char *char_data = reinterpret_cast<const char*>(data); | 41 const char *char_data = reinterpret_cast<const char*>(data); |
| 42 post_data_.insert(post_data_.end(), char_data, char_data + size); | 42 post_data_.insert(post_data_.end(), char_data, char_data + size); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Downloading should resume from this offset |
| 46 virtual void SetOffset(off_t offset) = 0; |
| 47 |
| 45 // Begins the transfer to the specified URL. | 48 // Begins the transfer to the specified URL. |
| 46 virtual void BeginTransfer(const std::string& url) = 0; | 49 virtual void BeginTransfer(const std::string& url) = 0; |
| 47 | 50 |
| 48 // Aborts the transfer. TransferComplete() will not be called on the | 51 // Aborts the transfer. TransferComplete() will not be called on the |
| 49 // delegate. | 52 // delegate. |
| 50 virtual void TerminateTransfer() = 0; | 53 virtual void TerminateTransfer() = 0; |
| 51 | 54 |
| 52 // If data is coming in too quickly, you can call Pause() to pause the | 55 // If data is coming in too quickly, you can call Pause() to pause the |
| 53 // transfer. The delegate will not have ReceivedBytes() called while | 56 // transfer. The delegate will not have ReceivedBytes() called while |
| 54 // an HttpFetcher is paused. | 57 // an HttpFetcher is paused. |
| 55 virtual void Pause() = 0; | 58 virtual void Pause() = 0; |
| 56 | 59 |
| 57 // Used to unpause an HttpFetcher and let the bytes stream in again. | 60 // Used to unpause an HttpFetcher and let the bytes stream in again. |
| 58 // If a delegate is set, ReceivedBytes() may be called on it before | 61 // If a delegate is set, ReceivedBytes() may be called on it before |
| 59 // Unpause() returns | 62 // Unpause() returns |
| 60 virtual void Unpause() = 0; | 63 virtual void Unpause() = 0; |
| 61 | 64 |
| 65 // These two function are overloaded in LibcurlHttp fetcher to speed |
| 66 // testing. |
| 67 virtual void set_idle_seconds(int seconds) {} |
| 68 virtual void set_retry_seconds(int seconds) {} |
| 69 |
| 62 protected: | 70 protected: |
| 63 // The URL we're actively fetching from | 71 // The URL we're actively fetching from |
| 64 std::string url_; | 72 std::string url_; |
| 65 | 73 |
| 66 // POST data for the transfer, and whether or not it was ever set | 74 // POST data for the transfer, and whether or not it was ever set |
| 67 bool post_data_set_; | 75 bool post_data_set_; |
| 68 std::vector<char> post_data_; | 76 std::vector<char> post_data_; |
| 69 | 77 |
| 70 // The server's HTTP response code from the last transfer. This | 78 // The server's HTTP response code from the last transfer. This |
| 71 // field should be set to 0 when a new transfer is initiated, and | 79 // field should be set to 0 when a new transfer is initiated, and |
| (...skipping 16 matching lines...) Expand all Loading... |
| 88 int length) = 0; | 96 int length) = 0; |
| 89 | 97 |
| 90 // Called when the transfer has completed successfully or been somehow | 98 // Called when the transfer has completed successfully or been somehow |
| 91 // aborted. | 99 // aborted. |
| 92 virtual void TransferComplete(HttpFetcher* fetcher, bool successful) = 0; | 100 virtual void TransferComplete(HttpFetcher* fetcher, bool successful) = 0; |
| 93 }; | 101 }; |
| 94 | 102 |
| 95 } // namespace chromeos_update_engine | 103 } // namespace chromeos_update_engine |
| 96 | 104 |
| 97 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_HTTP_FETCHER_H__ | 105 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_HTTP_FETCHER_H__ |
| OLD | NEW |