summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgfhuang <gfhuang@chromium.org>2015-02-17 15:19:07 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-17 23:19:37 +0000
commita8a9e2cd46440abd315cc876a8f6740ded878a0b (patch)
tree970937a61c2be75d3f988224b2c752ea886f4cd3
parentab967c97aa9dd75e7121c12edfa14c23052f4cb3 (diff)
downloadchromium_src-a8a9e2cd46440abd315cc876a8f6740ded878a0b.zip
chromium_src-a8a9e2cd46440abd315cc876a8f6740ded878a0b.tar.gz
chromium_src-a8a9e2cd46440abd315cc876a8f6740ded878a0b.tar.bz2
Fix a bug that newly created current_fetch_ is reset, if on_upload_complete
somehow calls NetMetricsLogUploader::UploadLog. BUG=458934 Review URL: https://codereview.chromium.org/912373003 Cr-Commit-Position: refs/heads/master@{#316697}
-rw-r--r--components/components_tests.gyp1
-rw-r--r--components/metrics/net/net_metrics_log_uploader.cc2
-rw-r--r--components/metrics/net/net_metrics_log_uploader_unittest.cc58
3 files changed, 60 insertions, 1 deletions
diff --git a/components/components_tests.gyp b/components/components_tests.gyp
index 67456f5..3287ead 100644
--- a/components/components_tests.gyp
+++ b/components/components_tests.gyp
@@ -205,6 +205,7 @@
'metrics/metrics_reporting_scheduler_unittest.cc',
'metrics/metrics_service_unittest.cc',
'metrics/metrics_state_manager_unittest.cc',
+ 'metrics/net/net_metrics_log_uploader_unittest.cc',
'metrics/persisted_logs_unittest.cc',
'metrics/profiler/profiler_metrics_provider_unittest.cc',
'navigation_interception/intercept_navigation_resource_throttle_unittest.cc',
diff --git a/components/metrics/net/net_metrics_log_uploader.cc b/components/metrics/net/net_metrics_log_uploader.cc
index 8c68ca0..1a68674 100644
--- a/components/metrics/net/net_metrics_log_uploader.cc
+++ b/components/metrics/net/net_metrics_log_uploader.cc
@@ -53,8 +53,8 @@ void NetMetricsLogUploader::OnURLFetchComplete(const net::URLFetcher* source) {
int response_code = source->GetResponseCode();
if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID)
response_code = -1;
- on_upload_complete_.Run(response_code);
current_fetch_.reset();
+ on_upload_complete_.Run(response_code);
}
} // namespace metrics
diff --git a/components/metrics/net/net_metrics_log_uploader_unittest.cc b/components/metrics/net/net_metrics_log_uploader_unittest.cc
new file mode 100644
index 0000000..c205b42
--- /dev/null
+++ b/components/metrics/net/net_metrics_log_uploader_unittest.cc
@@ -0,0 +1,58 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/metrics/net/net_metrics_log_uploader.h"
+
+#include "base/bind.h"
+#include "net/url_request/test_url_fetcher_factory.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace metrics {
+
+class NetMetricsLogUploaderTest : public testing::Test {
+ public:
+ NetMetricsLogUploaderTest() : on_upload_complete_count_(0) {
+ }
+
+ void CreateAndOnUploadCompleteReuseUploader() {
+ uploader_.reset(new NetMetricsLogUploader(
+ NULL, "http://dummy_server", "dummy_mime",
+ base::Bind(&NetMetricsLogUploaderTest::OnUploadCompleteReuseUploader,
+ base::Unretained(this))));
+ uploader_->UploadLog("initial_dummy_data", "initial_dummy_hash");
+ }
+
+ void OnUploadCompleteReuseUploader(int response_code) {
+ ++on_upload_complete_count_;
+ if (on_upload_complete_count_ == 1)
+ uploader_->UploadLog("dummy_data", "dummy_hash");
+ }
+
+ int on_upload_complete_count() const {
+ return on_upload_complete_count_;
+ }
+
+ private:
+ scoped_ptr<NetMetricsLogUploader> uploader_;
+ int on_upload_complete_count_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetMetricsLogUploaderTest);
+};
+
+TEST_F(NetMetricsLogUploaderTest, OnUploadCompleteReuseUploader) {
+ net::TestURLFetcherFactory factory;
+ CreateAndOnUploadCompleteReuseUploader();
+
+ // Mimic the initial fetcher callback.
+ net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
+ fetcher->delegate()->OnURLFetchComplete(fetcher);
+
+ // Mimic the second fetcher callback.
+ fetcher = factory.GetFetcherByID(0);
+ fetcher->delegate()->OnURLFetchComplete(fetcher);
+
+ EXPECT_EQ(on_upload_complete_count(), 2);
+}
+
+} // namespace metrics