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 UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ |
6 #define UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <curl/curl.h> | 10 #include <curl/curl.h> |
11 #include <glib.h> | 11 #include <glib.h> |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/logging.h" | 13 #include "chromeos/obsolete_logging.h" |
14 #include "update_engine/http_fetcher.h" | 14 #include "update_engine/http_fetcher.h" |
15 | 15 |
16 // This is a concrete implementation of HttpFetcher that uses libcurl to do the | 16 // This is a concrete implementation of HttpFetcher that uses libcurl to do the |
17 // http work. | 17 // http work. |
18 | 18 |
19 namespace chromeos_update_engine { | 19 namespace chromeos_update_engine { |
20 | 20 |
21 class LibcurlHttpFetcher : public HttpFetcher { | 21 class LibcurlHttpFetcher : public HttpFetcher { |
22 public: | 22 public: |
23 LibcurlHttpFetcher() | 23 LibcurlHttpFetcher() |
(...skipping 23 matching lines...) Expand all Loading... |
47 // primarily useful for testing. | 47 // primarily useful for testing. |
48 // From http://curl.haxx.se/libcurl/c/curl_multi_timeout.html: | 48 // From http://curl.haxx.se/libcurl/c/curl_multi_timeout.html: |
49 // if libcurl returns a -1 timeout here, it just means that libcurl | 49 // if libcurl returns a -1 timeout here, it just means that libcurl |
50 // currently has no stored timeout value. You must not wait too long | 50 // currently has no stored timeout value. You must not wait too long |
51 // (more than a few seconds perhaps) before you call | 51 // (more than a few seconds perhaps) before you call |
52 // curl_multi_perform() again. | 52 // curl_multi_perform() again. |
53 void set_idle_ms(long ms) { | 53 void set_idle_ms(long ms) { |
54 idle_ms_ = ms; | 54 idle_ms_ = ms; |
55 } | 55 } |
56 private: | 56 private: |
| 57 // Resumes a transfer where it left off. This will use the |
| 58 // HTTP Range: header to make a new connection from where the last |
| 59 // left off. |
| 60 virtual void ResumeTransfer(const std::string& url); |
57 | 61 |
58 // These two methods are for glib main loop callbacks. They are called | 62 // These two methods are for glib main loop callbacks. They are called |
59 // when either a file descriptor is ready for work or when a timer | 63 // when either a file descriptor is ready for work or when a timer |
60 // has fired. The static versions are shims for libcurl which has a C API. | 64 // has fired. The static versions are shims for libcurl which has a C API. |
61 bool FDCallback(GIOChannel *source, GIOCondition condition); | 65 bool FDCallback(GIOChannel *source, GIOCondition condition); |
62 static gboolean StaticFDCallback(GIOChannel *source, | 66 static gboolean StaticFDCallback(GIOChannel *source, |
63 GIOCondition condition, | 67 GIOCondition condition, |
64 gpointer data) { | 68 gpointer data) { |
65 return reinterpret_cast<LibcurlHttpFetcher*>(data)->FDCallback(source, | 69 return reinterpret_cast<LibcurlHttpFetcher*>(data)->FDCallback(source, |
66 condition); | 70 condition); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // glib main loop | 106 // glib main loop |
103 typedef std::map<int, std::pair<GIOChannel*, guint> > IOChannels; | 107 typedef std::map<int, std::pair<GIOChannel*, guint> > IOChannels; |
104 IOChannels io_channels_; | 108 IOChannels io_channels_; |
105 | 109 |
106 // if non-NULL, a timer we're waiting on. glib main loop will call us back | 110 // if non-NULL, a timer we're waiting on. glib main loop will call us back |
107 // when it fires. | 111 // when it fires. |
108 GSource* timeout_source_; | 112 GSource* timeout_source_; |
109 | 113 |
110 bool transfer_in_progress_; | 114 bool transfer_in_progress_; |
111 | 115 |
| 116 // The transfer size. -1 if not known. |
| 117 off_t transfer_size_; |
| 118 |
| 119 // How many bytes have been downloaded and sent to the delegate. |
| 120 off_t bytes_downloaded_; |
| 121 |
| 122 // If we resumed an earlier transfer, data offset that we used for the |
| 123 // new connection. 0 otherwise. |
| 124 off_t resume_offset_; |
| 125 |
112 long idle_ms_; | 126 long idle_ms_; |
113 DISALLOW_COPY_AND_ASSIGN(LibcurlHttpFetcher); | 127 DISALLOW_COPY_AND_ASSIGN(LibcurlHttpFetcher); |
114 }; | 128 }; |
115 | 129 |
116 } // namespace chromeos_update_engine | 130 } // namespace chromeos_update_engine |
117 | 131 |
118 #endif // UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ | 132 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_LIBCURL_HTTP_FETCHER_H__ |
OLD | NEW |