summaryrefslogtreecommitdiff
path: root/chromium/components/download/database
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/components/download/database
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-85-based.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/download/database')
-rw-r--r--chromium/components/download/database/download_db_conversions.cc72
-rw-r--r--chromium/components/download/database/download_db_conversions.h8
-rw-r--r--chromium/components/download/database/download_db_conversions_unittest.cc22
-rw-r--r--chromium/components/download/database/in_progress/in_progress_info.cc3
-rw-r--r--chromium/components/download/database/in_progress/in_progress_info.h8
-rw-r--r--chromium/components/download/database/proto/download_entry.proto6
6 files changed, 103 insertions, 16 deletions
diff --git a/chromium/components/download/database/download_db_conversions.cc b/chromium/components/download/database/download_db_conversions.cc
index fc79a1483d2..d9c2ef32717 100644
--- a/chromium/components/download/database/download_db_conversions.cc
+++ b/chromium/components/download/database/download_db_conversions.cc
@@ -9,6 +9,20 @@
#include "base/pickle.h"
namespace download {
+namespace {
+
+// Converts base::Time to a timpstamp in milliseconds.
+int64_t FromTimeToMilliseconds(base::Time time) {
+ return time.ToDeltaSinceWindowsEpoch().InMilliseconds();
+}
+
+// Converts a time stamp in milliseconds to base::Time.
+base::Time FromMillisecondsToTime(int64_t time_ms) {
+ return base::Time::FromDeltaSinceWindowsEpoch(
+ base::TimeDelta::FromMilliseconds(time_ms));
+}
+
+} // namespace
DownloadEntry DownloadDBConversions::DownloadEntryFromProto(
const download_pb::DownloadEntry& proto) {
@@ -173,12 +187,10 @@ download_pb::InProgressInfo DownloadDBConversions::InProgressInfoToProto(
proto.set_start_time(
in_progress_info.start_time.is_null()
? -1
- : in_progress_info.start_time.ToDeltaSinceWindowsEpoch()
- .InMilliseconds());
+ : FromTimeToMilliseconds(in_progress_info.start_time));
proto.set_end_time(in_progress_info.end_time.is_null()
? -1
- : in_progress_info.end_time.ToDeltaSinceWindowsEpoch()
- .InMilliseconds());
+ : FromTimeToMilliseconds(in_progress_info.end_time));
for (size_t i = 0; i < in_progress_info.received_slices.size(); ++i) {
download_pb::ReceivedSlice* slice = proto.add_received_slices();
slice->set_received_bytes(
@@ -195,6 +207,15 @@ download_pb::InProgressInfo DownloadDBConversions::InProgressInfoToProto(
proto.set_metered(in_progress_info.metered);
proto.set_bytes_wasted(in_progress_info.bytes_wasted);
proto.set_auto_resume_count(in_progress_info.auto_resume_count);
+ if (in_progress_info.download_schedule.has_value()) {
+ DCHECK_NE(in_progress_info.download_schedule->only_on_wifi(),
+ in_progress_info.metered);
+ auto download_schedule_proto =
+ std::make_unique<download_pb::DownloadSchedule>(DownloadScheduleToProto(
+ in_progress_info.download_schedule.value()));
+ proto.set_allocated_download_schedule(download_schedule_proto.release());
+ }
+
return proto;
}
@@ -223,16 +244,12 @@ InProgressInfo DownloadDBConversions::InProgressInfoFromProto(
base::Pickle(proto.target_path().data(), proto.target_path().size()));
info.target_path.ReadFromPickle(&target_path);
info.received_bytes = proto.received_bytes();
- info.start_time =
- proto.start_time() == -1
- ? base::Time()
- : base::Time::FromDeltaSinceWindowsEpoch(
- base::TimeDelta::FromMilliseconds(proto.start_time()));
- info.end_time =
- proto.end_time() == -1
- ? base::Time()
- : base::Time::FromDeltaSinceWindowsEpoch(
- base::TimeDelta::FromMilliseconds(proto.end_time()));
+ info.start_time = proto.start_time() == -1
+ ? base::Time()
+ : FromMillisecondsToTime(proto.start_time());
+ info.end_time = proto.end_time() == -1
+ ? base::Time()
+ : FromMillisecondsToTime(proto.end_time());
for (int i = 0; i < proto.received_slices_size(); ++i) {
info.received_slices.emplace_back(proto.received_slices(i).offset(),
@@ -249,6 +266,12 @@ InProgressInfo DownloadDBConversions::InProgressInfoFromProto(
info.metered = proto.metered();
info.bytes_wasted = proto.bytes_wasted();
info.auto_resume_count = proto.auto_resume_count();
+ if (proto.has_download_schedule()) {
+ info.download_schedule = DownloadScheduleFromProto(
+ proto.download_schedule(), !proto.metered() /*only_on_wifi*/);
+ DCHECK_NE(info.download_schedule->only_on_wifi(), info.metered);
+ }
+
return info;
}
@@ -268,6 +291,27 @@ download_pb::UkmInfo DownloadDBConversions::UkmInfoToProto(
return proto;
}
+download_pb::DownloadSchedule DownloadDBConversions::DownloadScheduleToProto(
+ const DownloadSchedule& download_schedule) {
+ // download::DownloadSchedule.only_on_wifi is not persisted, use
+ // InProgressInfo.metered instead.
+ download_pb::DownloadSchedule proto;
+ if (download_schedule.start_time().has_value()) {
+ proto.set_start_time(
+ FromTimeToMilliseconds(download_schedule.start_time().value()));
+ }
+ return proto;
+}
+
+DownloadSchedule DownloadDBConversions::DownloadScheduleFromProto(
+ const download_pb::DownloadSchedule& proto,
+ bool only_on_wifi) {
+ base::Optional<base::Time> start_time;
+ if (proto.has_start_time())
+ start_time = FromMillisecondsToTime(proto.start_time());
+ return DownloadSchedule(only_on_wifi, std::move(start_time));
+}
+
DownloadInfo DownloadDBConversions::DownloadInfoFromProto(
const download_pb::DownloadInfo& proto) {
DownloadInfo info;
diff --git a/chromium/components/download/database/download_db_conversions.h b/chromium/components/download/database/download_db_conversions.h
index a113d86e7e2..39ad586d092 100644
--- a/chromium/components/download/database/download_db_conversions.h
+++ b/chromium/components/download/database/download_db_conversions.h
@@ -14,6 +14,7 @@
#include "components/download/database/in_progress/ukm_info.h"
#include "components/download/database/proto/download_entry.pb.h"
#include "components/download/database/proto/download_source.pb.h"
+#include "components/download/public/common/download_schedule.h"
namespace download {
@@ -53,6 +54,13 @@ class DownloadDBConversions {
static UkmInfo UkmInfoFromProto(const download_pb::UkmInfo& proto);
+ static download_pb::DownloadSchedule DownloadScheduleToProto(
+ const DownloadSchedule& download_schedule);
+
+ static DownloadSchedule DownloadScheduleFromProto(
+ const download_pb::DownloadSchedule& proto,
+ bool metered);
+
static download_pb::DownloadInfo DownloadInfoToProto(
const DownloadInfo& download_info);
diff --git a/chromium/components/download/database/download_db_conversions_unittest.cc b/chromium/components/download/database/download_db_conversions_unittest.cc
index 0dfbd563305..c89f8cbd06f 100644
--- a/chromium/components/download/database/download_db_conversions_unittest.cc
+++ b/chromium/components/download/database/download_db_conversions_unittest.cc
@@ -4,6 +4,8 @@
#include "components/download/database/download_db_conversions.h"
+#include "base/optional.h"
+#include "components/download/public/common/download_schedule.h"
#include "components/download/public/common/download_url_parameters.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -46,6 +48,8 @@ InProgressInfo CreateInProgressInfo() {
std::make_pair<std::string, std::string>("123", "456"));
info.request_headers.emplace_back(
std::make_pair<std::string, std::string>("ABC", "def"));
+ info.download_schedule = base::make_optional<DownloadSchedule>(
+ false /*only_on_wifi*/, base::nullopt);
return info;
}
@@ -163,4 +167,22 @@ TEST_F(DownloadDBConversionsTest, DownloadDBEntry) {
EXPECT_EQ(entry, DownloadDBEntryFromProto(DownloadDBEntryToProto(entry)));
}
+TEST_F(DownloadDBConversionsTest, DownloadSchedule) {
+ const bool kOnlyOnWifi = true;
+ DownloadSchedule download_schedule(kOnlyOnWifi, base::nullopt /*start_time*/);
+ // InProgressInfo.metered is used to set DownloadSchedule.only_on_wifi.
+ auto persisted_download_schedule = DownloadScheduleFromProto(
+ DownloadScheduleToProto(download_schedule), !kOnlyOnWifi);
+ EXPECT_FALSE(persisted_download_schedule.only_on_wifi());
+ EXPECT_TRUE(download_schedule.only_on_wifi());
+
+ base::Time time;
+ bool success = base::Time::FromUTCString("2020-06-11 15:41", &time);
+ ASSERT_TRUE(success);
+ download_schedule = DownloadSchedule(kOnlyOnWifi, time);
+ persisted_download_schedule = DownloadScheduleFromProto(
+ DownloadScheduleToProto(download_schedule), kOnlyOnWifi);
+ EXPECT_EQ(persisted_download_schedule, download_schedule);
+}
+
} // namespace download
diff --git a/chromium/components/download/database/in_progress/in_progress_info.cc b/chromium/components/download/database/in_progress/in_progress_info.cc
index 7cb0c20fc9b..61a7afbd023 100644
--- a/chromium/components/download/database/in_progress/in_progress_info.cc
+++ b/chromium/components/download/database/in_progress/in_progress_info.cc
@@ -30,7 +30,8 @@ bool InProgressInfo::operator==(const InProgressInfo& other) const {
danger_type == other.danger_type &&
interrupt_reason == other.interrupt_reason && paused == other.paused &&
metered == other.metered && bytes_wasted == other.bytes_wasted &&
- auto_resume_count == other.auto_resume_count;
+ auto_resume_count == other.auto_resume_count &&
+ download_schedule == other.download_schedule;
}
} // namespace download
diff --git a/chromium/components/download/database/in_progress/in_progress_info.h b/chromium/components/download/database/in_progress/in_progress_info.h
index 3f7b5fac15e..2b67686c04c 100644
--- a/chromium/components/download/database/in_progress/in_progress_info.h
+++ b/chromium/components/download/database/in_progress/in_progress_info.h
@@ -8,8 +8,10 @@
#include <string>
#include <vector>
+#include "base/optional.h"
#include "components/download/public/common/download_danger_type.h"
#include "components/download/public/common/download_item.h"
+#include "components/download/public/common/download_schedule.h"
#include "components/download/public/common/download_url_parameters.h"
#include "url/gurl.h"
@@ -118,8 +120,12 @@ struct InProgressInfo {
// triggered resumption.
int32_t auto_resume_count = 0;
- // Whether the download is initiated on a metered network
+ // Whether the download is initiated on a metered network. If false, download
+ // can ony be resumed on WIFI.
bool metered = false;
+
+ // When to start the download. Used by download later feature.
+ base::Optional<DownloadSchedule> download_schedule;
};
} // namespace download
diff --git a/chromium/components/download/database/proto/download_entry.proto b/chromium/components/download/database/proto/download_entry.proto
index cbed5951b5f..af788572287 100644
--- a/chromium/components/download/database/proto/download_entry.proto
+++ b/chromium/components/download/database/proto/download_entry.proto
@@ -44,6 +44,11 @@ message UkmInfo {
optional int64 ukm_download_id = 2;
}
+// Information about when to start the download, used by download later feature.
+message DownloadSchedule {
+ optional int64 start_time = 1;
+}
+
// Information about an in progress download.
message InProgressInfo {
repeated string url_chain = 1;
@@ -73,6 +78,7 @@ message InProgressInfo {
optional bool metered = 25;
optional int64 bytes_wasted = 26;
optional int32 auto_resume_count = 27;
+ optional DownloadSchedule download_schedule = 28;
}
// Stores various metadata related to a download.