Commit eccd24aa authored by Elad Alon's avatar Elad Alon Committed by Commit Bot

Use FormatBytesWithUnits in WebRtcEventLogUploader

Before this CL, an ad-hoc implementation of FormatBytesWithUnits
was used, rather than call ui::FormatBytesWithUnits().

Bug: 775415
Change-Id: Ieb125023ef50943ef164b3d97246ba7e6fc8ad27
Reviewed-on: https://chromium-review.googlesource.com/1179667
Commit-Queue: Elad Alon <eladalon@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585224}
parent 415f86f6
......@@ -18,6 +18,7 @@
#include "net/http/http_status_code.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "ui/base/text/bytes_formatting.h"
namespace {
// TODO(crbug.com/817495): Eliminate the duplication with other uploaders.
......@@ -108,25 +109,12 @@ void BindURLLoaderFactoryRequest(
shared_url_loader_factory->Clone(std::move(url_loader_factory_request));
}
#if DCHECK_IS_ON()
void OnURLLoadUploadProgress(uint64_t current, uint64_t total) {
std::string unit;
if (total <= 1000) {
unit = "bytes";
} else if (total <= 1000 * 1000) {
unit = "KBs";
current /= 1000;
total /= 1000;
} else {
unit = "MBs";
current /= 1000 * 1000;
total /= 1000 * 1000;
}
VLOG(1) << "WebRTC event log upload progress: " << current << " / " << total
<< " " << unit << ".";
ui::DataUnits unit = ui::GetByteDisplayUnits(total);
VLOG(1) << "WebRTC event log upload progress: "
<< FormatBytesWithUnits(current, unit, false) << " / "
<< FormatBytesWithUnits(total, unit, true) << ".";
}
#endif
} // namespace
const char WebRtcEventLogUploaderImpl::kUploadURL[] =
......@@ -263,10 +251,8 @@ void WebRtcEventLogUploaderImpl::StartUpload(const std::string& upload_data) {
url_loader_ = network::SimpleURLLoader::Create(
std::move(resource_request), kWebrtcEventLogUploaderTrafficAnnotation);
url_loader_->AttachStringForUpload(upload_data, MimeContentType());
#if DCHECK_IS_ON()
url_loader_->SetOnUploadProgressCallback(
base::BindRepeating(OnURLLoadUploadProgress));
#endif
// See comment in destructor for an explanation about why using
// base::Unretained(this) is safe here.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment