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

Unified Diff: libcurl_http_fetcher.cc

Issue 4029002: AU: Don't use network on expensive connection types (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: Created 10 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: libcurl_http_fetcher.cc
diff --git a/libcurl_http_fetcher.cc b/libcurl_http_fetcher.cc
index c8468125f042aabd5a67eaf765b3d02e12ed17c2..9cacf869b96f1ba40b0253e333b5d5aedd045e07 100644
--- a/libcurl_http_fetcher.cc
+++ b/libcurl_http_fetcher.cc
@@ -3,11 +3,19 @@
// found in the LICENSE file.
#include "update_engine/libcurl_http_fetcher.h"
+
#include <algorithm>
-#include "base/logging.h"
+#include <string>
+
+#include <base/logging.h>
+
+#include "update_engine/dbus_interface.h"
+#include "update_engine/flimflam_proxy.h"
+#include "update_engine/utils.h"
using std::max;
using std::make_pair;
+using std::string;
// This is a concrete implementation of HttpFetcher that uses libcurl to do the
// http work.
@@ -17,12 +25,24 @@ namespace chromeos_update_engine {
namespace {
const int kMaxRetriesCount = 20;
const char kCACertificatesPath[] = "/usr/share/update_engine/ca-certificates";
-}
+} // namespace {}
LibcurlHttpFetcher::~LibcurlHttpFetcher() {
CleanUp();
}
+// On error, returns false.
+bool LibcurlHttpFetcher::ConnectionIsExpensive() const {
+ if (force_connection_type_)
+ return forced_expensive_connection_;
+ NetworkConnectionType type;
+ ConcreteDbusGlib dbus_iface;
+ TEST_AND_RETURN_FALSE(FlimFlamProxy::GetConnectionType(&dbus_iface, &type));
+ LOG(INFO) << "We are connected via "
+ << FlimFlamProxy::StringForConnectionType(type);
+ return FlimFlamProxy::IsExpensiveConnectionType(type);
+}
+
void LibcurlHttpFetcher::ResumeTransfer(const std::string& url) {
LOG(INFO) << "Starting/Resuming transfer";
CHECK(!transfer_in_progress_);
@@ -54,7 +74,18 @@ void LibcurlHttpFetcher::ResumeTransfer(const std::string& url) {
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_WRITEDATA, this), CURLE_OK);
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_WRITEFUNCTION,
StaticLibcurlWrite), CURLE_OK);
- CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_URL, url_.c_str()), CURLE_OK);
+
+ string url_to_use(url_);
+ if (ConnectionIsExpensive()) {
petkov 2010/10/21 05:15:19 If the device switches from WiFi to 3G in the midd
adlr 2010/10/21 19:41:14 This code path is called for every connection or r
+ LOG(INFO) << "Not initiating HTTP connection b/c we are on an expensive"
+ << " connection";
+ url_to_use = ""; // Sabotage the URL
+ }
+
+ CHECK_EQ(curl_easy_setopt(curl_handle_,
+ CURLOPT_URL,
+ url_to_use.c_str()),
+ CURLE_OK);
// If the connection drops under 10 bytes/sec for 3 minutes, reconnect.
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_LOW_SPEED_LIMIT, 10),
« flimflam_proxy_unittest.cc ('K') | « libcurl_http_fetcher.h ('k') | mock_dbus_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698