AU: Don't use network on expensive connection types

Specifically:

- FlimFlam proxy class to query the current network status and find
out if it's expensive.
- Dbus Interface, so dbus can be mocked.
- Libcurl change to redirect the URL if we are on an expensive
connection. This may seem hacky, but the reason I avoided retooling
the whole class is that we may decide that some network usage is
okay on pricy connections. Perhaps it's okay to throttle. So, for
now this is a more minimal change.

BUG=chromium-os:2397
TEST=Unit tests, tested that flimflam proxy works on the device.

Review URL: http://codereview.chromium.org/4029002

Change-Id: Ic4dcde1ca863bda890bc46a55c552e2b32d9433d
diff --git a/http_fetcher_unittest.cc b/http_fetcher_unittest.cc
index 06cabac..bd16768 100644
--- a/http_fetcher_unittest.cc
+++ b/http_fetcher_unittest.cc
@@ -135,6 +135,7 @@
     // Speed up test execution.
     ret->set_idle_seconds(1);
     ret->set_retry_seconds(1);
+    ret->SetConnectionAsExpensive(false);
     return ret;
   }
   HttpFetcher* NewSmallFetcher() {
@@ -696,4 +697,44 @@
   }
 }
 
+namespace {
+class ExpensiveConnectionTestDelegate : public HttpFetcherDelegate {
+ public:
+  virtual void ReceivedBytes(HttpFetcher* fetcher,
+                             const char* bytes, int length) {
+    ADD_FAILURE();
+  }
+  virtual void TransferComplete(HttpFetcher* fetcher, bool successful) {
+    EXPECT_FALSE(successful);
+    g_main_loop_quit(loop_);
+  }
+  GMainLoop* loop_;
+};
+
+}  // namespace
+
+TYPED_TEST(HttpFetcherTest, ExpensiveConnectionTest) {
+  if (this->IsMock() || this->IsMulti())
+    return;
+  typename TestFixture::HttpServer server;
+  
+  ASSERT_TRUE(server.started_);
+
+  GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
+  ExpensiveConnectionTestDelegate delegate;
+  delegate.loop_ = loop;
+
+  scoped_ptr<HttpFetcher> fetcher(this->NewLargeFetcher());
+  dynamic_cast<LibcurlHttpFetcher*>(
+      fetcher.get())->SetConnectionAsExpensive(true);
+  fetcher->set_delegate(&delegate);
+
+  StartTransferArgs start_xfer_args =
+      { fetcher.get(), LocalServerUrlForPath(this->SmallUrl()) };
+
+  g_timeout_add(0, StartTransfer, &start_xfer_args);
+  g_main_loop_run(loop);
+  g_main_loop_unref(loop);
+}
+
 }  // namespace chromeos_update_engine