diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-09-01 11:08:40 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-10-01 12:16:21 +0000 |
commit | 03c549e0392f92c02536d3f86d5e1d8dfa3435ac (patch) | |
tree | fe49d170a929b34ba82cd10db1a0bd8e3760fa4b /chromium/components/download | |
parent | 5d013f5804a0d91fcf6c626b2d6fb6eca5c845b0 (diff) | |
download | qtwebengine-chromium-03c549e0392f92c02536d3f86d5e1d8dfa3435ac.tar.gz |
BASELINE: Update Chromium to 91.0.4472.160
Change-Id: I0def1f08a2412aeed79a9ab95dd50eb5c3f65f31
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/download')
39 files changed, 197 insertions, 279 deletions
diff --git a/chromium/components/download/content/public/all_download_item_notifier_unittest.cc b/chromium/components/download/content/public/all_download_item_notifier_unittest.cc index b893c8ab19a..a7bae166644 100644 --- a/chromium/components/download/content/public/all_download_item_notifier_unittest.cc +++ b/chromium/components/download/content/public/all_download_item_notifier_unittest.cc @@ -4,6 +4,8 @@ #include "components/download/content/public/all_download_item_notifier.h" +#include <memory> + #include "base/macros.h" #include "components/download/public/common/mock_download_item.h" #include "content/public/test/mock_download_manager.h" @@ -58,8 +60,8 @@ class AllDownloadItemNotifierTest : public testing::Test { void SetNotifier() { EXPECT_CALL(*download_manager_, AddObserver(_)); - notifier_.reset( - new AllDownloadItemNotifier(download_manager_.get(), &observer_)); + notifier_ = std::make_unique<AllDownloadItemNotifier>( + download_manager_.get(), &observer_); } void ClearNotifier() { notifier_.reset(); } diff --git a/chromium/components/download/database/download_db_impl_unittest.cc b/chromium/components/download/database/download_db_impl_unittest.cc index 4df08226694..89cdd4d39c2 100644 --- a/chromium/components/download/database/download_db_impl_unittest.cc +++ b/chromium/components/download/database/download_db_impl_unittest.cc @@ -49,8 +49,8 @@ class DownloadDBTest : public testing::Test { leveldb_proto::test::FakeDB<download_pb::DownloadDBEntry>>( &db_entries_); db_ = db.get(); - download_db_.reset(new DownloadDBImpl( - DownloadNamespace::NAMESPACE_BROWSER_DOWNLOAD, std::move(db))); + download_db_ = std::make_unique<DownloadDBImpl>( + DownloadNamespace::NAMESPACE_BROWSER_DOWNLOAD, std::move(db)); } void InitCallback(bool success) { init_success_ = success; } diff --git a/chromium/components/download/internal/background_service/config.cc b/chromium/components/download/internal/background_service/config.cc index f876e629b78..23ea86d8670 100644 --- a/chromium/components/download/internal/background_service/config.cc +++ b/chromium/components/download/internal/background_service/config.cc @@ -8,6 +8,7 @@ #include "base/metrics/field_trial_params.h" #include "base/strings/string_number_conversions.h" +#include "build/build_config.h" #include "components/download/public/background_service/features.h" namespace download { @@ -59,8 +60,13 @@ const base::TimeDelta kDefaultWindowStartTime = base::TimeDelta::FromMinutes(5); const base::TimeDelta kDefaultWindowEndTime = base::TimeDelta::FromHours(8); // Default value for start up delay to wait for network stack ready. +#if defined(OS_ANDROID) const base::TimeDelta kDefaultNetworkStartupDelay = base::TimeDelta::FromSeconds(25); +#else +const base::TimeDelta kDefaultNetworkStartupDelay = + base::TimeDelta::FromSeconds(2); +#endif // defined(OS_ANDROID) // Default value for start up delay to wait for network stack ready when // triggered from a background task. diff --git a/chromium/components/download/internal/background_service/controller_impl.cc b/chromium/components/download/internal/background_service/controller_impl.cc index 1060e6ee71b..b620c89d8ee 100644 --- a/chromium/components/download/internal/background_service/controller_impl.cc +++ b/chromium/components/download/internal/background_service/controller_impl.cc @@ -9,6 +9,7 @@ #include <utility> #include "base/bind.h" +#include "base/callback_helpers.h" #include "base/optional.h" #include "base/strings/stringprintf.h" #include "base/threading/thread_task_runner_handle.h" diff --git a/chromium/components/download/internal/background_service/download_store_unittest.cc b/chromium/components/download/internal/background_service/download_store_unittest.cc index 422d507bda9..0e39297d535 100644 --- a/chromium/components/download/internal/background_service/download_store_unittest.cc +++ b/chromium/components/download/internal/background_service/download_store_unittest.cc @@ -33,7 +33,7 @@ class DownloadStoreTest : public testing::Test { auto db = std::make_unique<leveldb_proto::test::FakeDB<protodb::Entry>>( &db_entries_); db_ = db.get(); - store_.reset(new DownloadStore(std::move(db))); + store_ = std::make_unique<DownloadStore>(std::move(db)); } void InitCallback(std::vector<Entry>* loaded_entries, diff --git a/chromium/components/download/internal/background_service/in_memory_download_unittest.cc b/chromium/components/download/internal/background_service/in_memory_download_unittest.cc index 4064c983072..6dd468430ef 100644 --- a/chromium/components/download/internal/background_service/in_memory_download_unittest.cc +++ b/chromium/components/download/internal/background_service/in_memory_download_unittest.cc @@ -4,6 +4,8 @@ #include "components/download/internal/background_service/in_memory_download.h" +#include <memory> + #include "base/bind.h" #include "base/guid.h" #include "base/message_loop/message_pump_type.h" @@ -88,7 +90,7 @@ class InMemoryDownloadTest : public testing::Test { ~InMemoryDownloadTest() override = default; void SetUp() override { - io_thread_.reset(new base::Thread("Network and Blob IO thread")); + io_thread_ = std::make_unique<base::Thread>("Network and Blob IO thread"); base::Thread::Options options(base::MessagePumpType::IO, 0); io_thread_->StartWithOptions(options); diff --git a/chromium/components/download/internal/background_service/scheduler/battery_status_listener_impl.cc b/chromium/components/download/internal/background_service/scheduler/battery_status_listener_impl.cc index e74bf55405d..d42874afc20 100644 --- a/chromium/components/download/internal/background_service/scheduler/battery_status_listener_impl.cc +++ b/chromium/components/download/internal/background_service/scheduler/battery_status_listener_impl.cc @@ -30,13 +30,13 @@ void BatteryStatusListenerImpl::Start(Observer* observer) { observer_ = observer; DCHECK(base::PowerMonitor::IsInitialized()); - base::PowerMonitor::AddObserver(this); + base::PowerMonitor::AddPowerStateObserver(this); UpdateBatteryPercentage(true); } void BatteryStatusListenerImpl::Stop() { - base::PowerMonitor::RemoveObserver(this); + base::PowerMonitor::RemovePowerStateObserver(this); } int BatteryStatusListenerImpl::GetBatteryPercentageInternal() { diff --git a/chromium/components/download/internal/background_service/scheduler/battery_status_listener_impl.h b/chromium/components/download/internal/background_service/scheduler/battery_status_listener_impl.h index 1efbcf45010..8f95b932ecd 100644 --- a/chromium/components/download/internal/background_service/scheduler/battery_status_listener_impl.h +++ b/chromium/components/download/internal/background_service/scheduler/battery_status_listener_impl.h @@ -14,7 +14,7 @@ namespace download { // Default implementation of BatteryStatusListener. class BatteryStatusListenerImpl : public BatteryStatusListener, - public base::PowerObserver { + public base::PowerStateObserver { public: explicit BatteryStatusListenerImpl( const base::TimeDelta& battery_query_interval); @@ -35,7 +35,7 @@ class BatteryStatusListenerImpl : public BatteryStatusListener, // |battery_query_interval_| when |force| is false. void UpdateBatteryPercentage(bool force); - // base::PowerObserver implementation. + // base::PowerStateObserver implementation. void OnPowerStateChange(bool on_battery_power) override; // Cached battery percentage. diff --git a/chromium/components/download/internal/background_service/scheduler/device_status_listener_unittest.cc b/chromium/components/download/internal/background_service/scheduler/device_status_listener_unittest.cc index f814936cdef..9381396f953 100644 --- a/chromium/components/download/internal/background_service/scheduler/device_status_listener_unittest.cc +++ b/chromium/components/download/internal/background_service/scheduler/device_status_listener_unittest.cc @@ -9,6 +9,7 @@ #include "base/run_loop.h" #include "base/test/power_monitor_test_base.h" #include "base/test/task_environment.h" +#include "build/build_config.h" #include "components/download/internal/background_service/scheduler/battery_status_listener_impl.h" #include "components/download/network/network_status_listener_impl.h" #include "services/network/test/test_network_connection_tracker.h" @@ -261,6 +262,21 @@ TEST_F(DeviceStatusListenerTest, NotifyObserverNetworkChange) { listener_->CurrentDeviceStatus().network_status); } +// Ensures the CONNECTION_UNKNOWN is treated correctly on non-Android. +TEST_F(DeviceStatusListenerTest, ConnectionUnknownTreatedCorrectly) { + listener_->Start(base::TimeDelta()); + base::RunLoop().RunUntilIdle(); + + // Initial states check. +#if defined(OS_ANDROID) + EXPECT_EQ(NetworkStatus::DISCONNECTED, + listener_->CurrentDeviceStatus().network_status); +#else + EXPECT_EQ(NetworkStatus::UNMETERED, + listener_->CurrentDeviceStatus().network_status); +#endif +} + // Ensures the observer is notified when battery condition changes. TEST_F(DeviceStatusListenerTest, NotifyObserverBatteryChange) { InSequence s; diff --git a/chromium/components/download/internal/common/BUILD.gn b/chromium/components/download/internal/common/BUILD.gn index 44d41af8674..e9d3b6f66d9 100644 --- a/chromium/components/download/internal/common/BUILD.gn +++ b/chromium/components/download/internal/common/BUILD.gn @@ -72,10 +72,10 @@ source_set("internal") { "//base", "//components/download/database", "//components/download/public/common:interfaces", - "//components/download/quarantine", "//components/filename_generation", "//components/leveldb_proto", "//components/safe_browsing:buildflags", + "//components/services/quarantine", "//mojo/public/c/system", "//net", "//services/device/public/mojom:mojom", @@ -120,7 +120,6 @@ if (is_android) { deps = [ "//base:base_java", - "//base:jni_java", "//third_party/android_provider:android_provider_java", "//third_party/androidx:androidx_annotation_annotation_java", ] @@ -164,10 +163,6 @@ source_set("unit_tests") { "rate_estimator_unittest.cc", ] - if (is_win) { - sources += [ "base_file_win_unittest.cc" ] - } - deps = [ ":for_tests", "//base/test:test_support", diff --git a/chromium/components/download/internal/common/DEPS b/chromium/components/download/internal/common/DEPS index 5ca4d5886fa..661002b5e04 100644 --- a/chromium/components/download/internal/common/DEPS +++ b/chromium/components/download/internal/common/DEPS @@ -3,11 +3,11 @@ include_rules = [ "+components/download/downloader/in_progress", "+components/download/internal/common/jni_headers", "+components/download/public/common", - "+components/download/quarantine", "+components/filename_generation/filename_generation.h", "+components/leveldb_proto", "+components/safe_browsing", "+components/services/quarantine/public/cpp/quarantine_features_win.h", + "+components/services/quarantine/quarantine.h", "+components/ukm/test_ukm_recorder.h", "+crypto", "+mojo/public/c/system", diff --git a/chromium/components/download/internal/common/base_file.cc b/chromium/components/download/internal/common/base_file.cc index 8124e170ee5..932ab3ea286 100644 --- a/chromium/components/download/internal/common/base_file.cc +++ b/chromium/components/download/internal/common/base_file.cc @@ -23,7 +23,7 @@ #include "components/download/public/common/download_interrupt_reasons_utils.h" #include "components/download/public/common/download_item.h" #include "components/download/public/common/download_stats.h" -#include "components/download/quarantine/quarantine.h" +#include "components/services/quarantine/quarantine.h" #include "crypto/secure_hash.h" #if defined(OS_WIN) @@ -607,34 +607,6 @@ GURL GetEffectiveAuthorityURL(const GURL& source_url, } // namespace -#if defined(OS_WIN) || defined(OS_APPLE) || defined(OS_LINUX) || \ - defined(OS_CHROMEOS) - -DownloadInterruptReason BaseFile::AnnotateWithSourceInformationSync( - const std::string& client_guid, - const GURL& source_url, - const GURL& referrer_url) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK(!detached_); - DCHECK(!full_path_.empty()); - - CONDITIONAL_TRACE(BEGIN0("download", "DownloadFileAnnotate")); - QuarantineFileResult result = QuarantineFile( - full_path_, GetEffectiveAuthorityURL(source_url, referrer_url), - referrer_url, client_guid); - CONDITIONAL_TRACE(END0("download", "DownloadFileAnnotate")); - - return QuarantineFileResultToReason(result); -} -#else // !OS_WIN && !OS_APPLE && !OS_LINUX && !OS_CHROMEOS -DownloadInterruptReason BaseFile::AnnotateWithSourceInformationSync( - const std::string& client_guid, - const GURL& source_url, - const GURL& referrer_url) { - return DOWNLOAD_INTERRUPT_REASON_NONE; -} -#endif - void BaseFile::OnFileQuarantined( bool connection_error, quarantine::mojom::QuarantineFileResult result) { @@ -670,10 +642,12 @@ void BaseFile::AnnotateWithSourceInformation( GURL authority_url = GetEffectiveAuthorityURL(source_url, referrer_url); if (!remote_quarantine) { #if defined(OS_WIN) - QuarantineFileResult result = quarantine::SetInternetZoneIdentifierDirectly( - full_path_, authority_url, referrer_url); + quarantine::mojom::QuarantineFileResult result = + quarantine::SetInternetZoneIdentifierDirectly(full_path_, authority_url, + referrer_url); #else - QuarantineFileResult result = QuarantineFileResult::ANNOTATION_FAILED; + quarantine::mojom::QuarantineFileResult result = + quarantine::mojom::QuarantineFileResult::ANNOTATION_FAILED; #endif std::move(on_annotation_done_callback) .Run(QuarantineFileResultToReason(result)); diff --git a/chromium/components/download/internal/common/base_file_unittest.cc b/chromium/components/download/internal/common/base_file_unittest.cc index 9ced7de3c41..e0955f4efe4 100644 --- a/chromium/components/download/internal/common/base_file_unittest.cc +++ b/chromium/components/download/internal/common/base_file_unittest.cc @@ -6,6 +6,8 @@ #include <stddef.h> #include <stdint.h> + +#include <memory> #include <utility> #include "base/files/file.h" @@ -60,7 +62,7 @@ class BaseFileTest : public testing::Test { void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - base_file_.reset(new BaseFile(DownloadItem::kInvalidId)); + base_file_ = std::make_unique<BaseFile>(DownloadItem::kInvalidId); } void TearDown() override { @@ -414,7 +416,7 @@ TEST_F(BaseFileTest, WriteWithError) { // Pass a file handle which was opened without the WRITE flag. // This should result in an error when writing. base::File file(path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ); - base_file_.reset(new BaseFile(download::DownloadItem::kInvalidId)); + base_file_ = std::make_unique<BaseFile>(download::DownloadItem::kInvalidId); EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, base_file_->Initialize(path, base::FilePath(), std::move(file), 0, std::string(), @@ -456,7 +458,7 @@ TEST_F(BaseFileTest, AppendToBaseFile) { set_expected_data(kTestData4); // Use the file we've just created. - base_file_.reset(new BaseFile(download::DownloadItem::kInvalidId)); + base_file_ = std::make_unique<BaseFile>(download::DownloadItem::kInvalidId); ASSERT_EQ( DOWNLOAD_INTERRUPT_REASON_NONE, base_file_->Initialize(existing_file_name, base::FilePath(), base::File(), @@ -487,7 +489,7 @@ TEST_F(BaseFileTest, ReadonlyBaseFile) { EXPECT_TRUE(base::MakeFileUnwritable(readonly_file_name)); // Try to overwrite it. - base_file_.reset(new BaseFile(download::DownloadItem::kInvalidId)); + base_file_ = std::make_unique<BaseFile>(download::DownloadItem::kInvalidId); EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, base_file_->Initialize(readonly_file_name, base::FilePath(), base::File(), 0, std::string(), diff --git a/chromium/components/download/internal/common/base_file_win_unittest.cc b/chromium/components/download/internal/common/base_file_win_unittest.cc deleted file mode 100644 index d10cf267163..00000000000 --- a/chromium/components/download/internal/common/base_file_win_unittest.cc +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2016 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/download/public/common/base_file.h" - -#include "base/files/file_util.h" -#include "base/files/scoped_temp_dir.h" -#include "components/download/public/common/download_interrupt_reasons.h" -#include "components/download/public/common/download_item.h" -#include "net/base/filename_util.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace download { - -TEST(BaseFileWin, AnnotateWithSourceInformation) { - const char kTestFileContents[] = "Hello world!"; - const base::FilePath::CharType kZoneIdentifierStreamName[] = - FILE_PATH_LITERAL(":Zone.Identifier"); - - struct { - const char* const url; - const char* const referrer; - bool expected_internet_zone; - } kTestCases[] = { - // Test cases where we expect a MOTW. - {"http://example.com", "http://example.com", true}, - {"", "http://example.com", true}, - {"", "", true}, - {"http://example.com", "", true}, - {"data:text/plain,Foo", "http://example.com", true}, - {"data:text/plain,Foo", "", true}, - {"data:text/plain,Foo", "data:text/plain,Bar", true}, - {"data:text/plain,Foo", "ftp://localhost/foo", true}, - {"http://example.com", "http://localhost/foo", true}, - {"ftp://example.com/foo", "", true}, - - // Test cases where we don't expect a MOTW. These test cases result in - // different behavior across Windows versions. - {"ftp://localhost/foo", "", false}, - {"http://localhost/foo", "", false}, - {"", "http://localhost/foo", false}, - {"file:///exists.txt", "", false}, - {"file:///exists.txt", "http://example.com", false}, - {"file:///does-not-exist.txt", "", false}, - }; - - base::ScopedTempDir target_directory; - ASSERT_TRUE(target_directory.CreateUniqueTempDir()); - - for (const auto& test_case : kTestCases) { - GURL url(test_case.url); - GURL referrer(test_case.referrer); - - // Resolve file:// URLs relative to our temp directory. - if (url.SchemeIsFile()) { - base::FilePath relative_path = - base::FilePath().AppendASCII(url.path().substr(1)); - url = net::FilePathToFileURL( - target_directory.GetPath().Append(relative_path)); - } - - SCOPED_TRACE(::testing::Message() << "Source URL: " << url.spec() - << " Referrer: " << test_case.referrer); - - BaseFile base_file(download::DownloadItem::kInvalidId); - int64_t bytes_wasted = 0; // unused - ASSERT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, - base_file.Initialize(base::FilePath(), target_directory.GetPath(), - base::File(), 0, std::string(), - std::unique_ptr<crypto::SecureHash>(), false, - &bytes_wasted)); - ASSERT_FALSE(base_file.full_path().empty()); - ASSERT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, - base_file.Rename( - target_directory.GetPath().AppendASCII("test_file.doc"))); - ASSERT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, - base_file.AppendDataToFile(kTestFileContents, - base::size(kTestFileContents))); - ASSERT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, - base_file.AnnotateWithSourceInformationSync( - "7B2CEE7C-DC81-4160-86F1-9C968597118F", url, referrer)); - base_file.Detach(); - base_file.Finish(); - - base::FilePath path = base_file.full_path(); - base::FilePath zone_identifier_stream(path.value() + - kZoneIdentifierStreamName); - - ASSERT_TRUE(base::PathExists(path)); - - std::string zone_identifier; - base::ReadFileToString(zone_identifier_stream, &zone_identifier); - - if (test_case.expected_internet_zone) { - // The actual assigned zone could be anything and the contents of the zone - // identifier depends on the version of Windows. So only testing that - // there is a zone annotation. - EXPECT_FALSE(zone_identifier.empty()); - } else if (!zone_identifier.empty()) { - // Seeing an unexpected zone identifier is not an error, but we log a - // warning just the same so that such cases can be identified during - // manual testing. - LOG(WARNING) << "Unexpected zone annotation for Source:" << url.spec() - << " Referrer:" << test_case.referrer - << " Annotation:" << std::endl - << zone_identifier; - } - base::DeleteFile(path); - } -} - -} // namespace download diff --git a/chromium/components/download/internal/common/download_file_impl.cc b/chromium/components/download/internal/common/download_file_impl.cc index 33bb7d1a814..b34b5b579ff 100644 --- a/chromium/components/download/internal/common/download_file_impl.cc +++ b/chromium/components/download/internal/common/download_file_impl.cc @@ -5,6 +5,7 @@ #include "components/download/public/common/download_file_impl.h" #include <algorithm> +#include <memory> #include <string> #include <utility> @@ -192,7 +193,7 @@ void DownloadFileImpl::Initialize( bool is_parallelizable) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - update_timer_.reset(new base::RepeatingTimer()); + update_timer_ = std::make_unique<base::RepeatingTimer>(); int64_t bytes_so_far = 0; cancel_request_callback_ = cancel_request_callback; received_slices_ = received_slices; diff --git a/chromium/components/download/internal/common/download_file_unittest.cc b/chromium/components/download/internal/common/download_file_unittest.cc index 46d8883ded2..9e51afeabe9 100644 --- a/chromium/components/download/internal/common/download_file_unittest.cc +++ b/chromium/components/download/internal/common/download_file_unittest.cc @@ -5,6 +5,7 @@ #include <stddef.h> #include <stdint.h> +#include <memory> #include <utility> #include <vector> @@ -246,10 +247,10 @@ class DownloadFileTest : public testing::Test { save_info->offset = 0; save_info->file_offset = file_offset; - download_file_.reset(new TestDownloadFileImpl( + download_file_ = std::make_unique<TestDownloadFileImpl>( std::move(save_info), download_dir_.GetPath(), std::unique_ptr<MockInputStream>(input_stream_), - DownloadItem::kInvalidId, observer_factory_.GetWeakPtr())); + DownloadItem::kInvalidId, observer_factory_.GetWeakPtr()); EXPECT_CALL(*input_stream_, Read(_, _)) .WillOnce(Return(InputStream::EMPTY)) diff --git a/chromium/components/download/internal/common/download_item_impl_unittest.cc b/chromium/components/download/internal/common/download_item_impl_unittest.cc index 2405ec42511..30f609d2537 100644 --- a/chromium/components/download/internal/common/download_item_impl_unittest.cc +++ b/chromium/components/download/internal/common/download_item_impl_unittest.cc @@ -240,9 +240,8 @@ class DownloadItemTest : public testing::Test { base::test::TaskEnvironment::MainThreadType::UI, base::test::TaskEnvironment::ThreadPoolExecutionMode::QUEUED), next_download_id_(DownloadItem::kInvalidId + 1) { - create_info_.reset(new DownloadCreateInfo()); - create_info_->save_info = - std::unique_ptr<DownloadSaveInfo>(new DownloadSaveInfo()); + create_info_ = std::make_unique<DownloadCreateInfo>(); + create_info_->save_info = std::make_unique<DownloadSaveInfo>(); create_info_->save_info->prompt_for_save_location = false; create_info_->url_chain.push_back(GURL("http://example.com/download")); create_info_->etag = "SomethingToSatisfyResumption"; diff --git a/chromium/components/download/internal/common/download_response_handler.cc b/chromium/components/download/internal/common/download_response_handler.cc index a14cb9d1808..a5f785aca05 100644 --- a/chromium/components/download/internal/common/download_response_handler.cc +++ b/chromium/components/download/internal/common/download_response_handler.cc @@ -88,6 +88,9 @@ DownloadResponseHandler::DownloadResponseHandler( DownloadResponseHandler::~DownloadResponseHandler() = default; +void DownloadResponseHandler::OnReceiveEarlyHints( + network::mojom::EarlyHintsPtr early_hints) {} + void DownloadResponseHandler::OnReceiveResponse( network::mojom::URLResponseHeadPtr head) { create_info_ = CreateDownloadCreateInfo(*head); diff --git a/chromium/components/download/internal/common/download_ukm_helper_unittest.cc b/chromium/components/download/internal/common/download_ukm_helper_unittest.cc index a2f75e7f13a..b309c033170 100644 --- a/chromium/components/download/internal/common/download_ukm_helper_unittest.cc +++ b/chromium/components/download/internal/common/download_ukm_helper_unittest.cc @@ -4,6 +4,8 @@ #include "components/download/public/common/download_ukm_helper.h" +#include <memory> + #include "base/run_loop.h" #include "base/test/task_environment.h" #include "components/ukm/test_ukm_recorder.h" @@ -25,7 +27,7 @@ class DownloadUkmHelperTest : public testing::Test { ~DownloadUkmHelperTest() override = default; void ResetUkmRecorder() { - test_recorder_.reset(new ukm::TestAutoSetUkmRecorder); + test_recorder_ = std::make_unique<ukm::TestAutoSetUkmRecorder>(); } void ExpectUkmMetrics(const base::StringPiece entry_name, diff --git a/chromium/components/download/internal/common/download_worker.cc b/chromium/components/download/internal/common/download_worker.cc index 1ac51d79157..87155179737 100644 --- a/chromium/components/download/internal/common/download_worker.cc +++ b/chromium/components/download/internal/common/download_worker.cc @@ -4,6 +4,8 @@ #include "components/download/internal/common/download_worker.h" +#include <memory> + #include "base/bind.h" #include "components/download/internal/common/resource_downloader.h" #include "components/download/public/common/download_create_info.h" @@ -133,7 +135,7 @@ void DownloadWorker::OnUrlDownloadStarted( VLOG(kWorkerVerboseLevel) << "Parallel download sub-request failed. reason = " << create_info->result; - input_stream.reset(new CompletedInputStream(create_info->result)); + input_stream = std::make_unique<CompletedInputStream>(create_info->result); url_download_handler_.reset(); } diff --git a/chromium/components/download/internal/common/resource_downloader.cc b/chromium/components/download/internal/common/resource_downloader.cc index 64b8adb711a..20ebc607e12 100644 --- a/chromium/components/download/internal/common/resource_downloader.cc +++ b/chromium/components/download/internal/common/resource_downloader.cc @@ -179,7 +179,6 @@ void ResourceDownloader::Start( // Set up the URLLoader url_loader_factory_->CreateLoaderAndStart( url_loader_.BindNewPipeAndPassReceiver(), - 0, // routing_id 0, // request_id network::mojom::kURLLoadOptionSendSSLInfoWithResponse, *(resource_request_.get()), std::move(url_loader_client_remote), diff --git a/chromium/components/download/network/BUILD.gn b/chromium/components/download/network/BUILD.gn index 474413dccdd..9d37ed9bfa9 100644 --- a/chromium/components/download/network/BUILD.gn +++ b/chromium/components/download/network/BUILD.gn @@ -44,7 +44,6 @@ if (is_android) { deps = [ "//base:base_java", - "//base:jni_java", "//net/android:net_java", "//third_party/androidx:androidx_annotation_annotation_java", ] diff --git a/chromium/components/download/public/background_service/BUILD.gn b/chromium/components/download/public/background_service/BUILD.gn index c9d96905e8e..0e22c563e2e 100644 --- a/chromium/components/download/public/background_service/BUILD.gn +++ b/chromium/components/download/public/background_service/BUILD.gn @@ -9,6 +9,8 @@ if (is_android) { source_set("public") { sources = [ + "basic_task_scheduler.cc", + "basic_task_scheduler.h", "blob_context_getter_factory.h", "client.cc", "client.h", diff --git a/chromium/components/download/public/background_service/basic_task_scheduler.cc b/chromium/components/download/public/background_service/basic_task_scheduler.cc new file mode 100644 index 00000000000..69dd08e5569 --- /dev/null +++ b/chromium/components/download/public/background_service/basic_task_scheduler.cc @@ -0,0 +1,53 @@ +// Copyright 2017 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/download/public/background_service/basic_task_scheduler.h" + +#include "base/bind.h" +#include "base/sequenced_task_runner.h" +#include "base/task/post_task.h" +#include "base/task/task_traits.h" +#include "base/threading/thread_task_runner_handle.h" +#include "base/time/time.h" +#include "components/download/public/background_service/download_service.h" + +namespace download { + +BasicTaskScheduler::BasicTaskScheduler( + const base::RepeatingCallback<DownloadService*()>& get_download_service) + : get_download_service_(get_download_service) {} + +BasicTaskScheduler::~BasicTaskScheduler() = default; + +void BasicTaskScheduler::ScheduleTask(download::DownloadTaskType task_type, + bool require_unmetered_network, + bool require_charging, + int optimal_battery_percentage, + int64_t window_start_time_seconds, + int64_t window_end_time_seconds) { + scheduled_tasks_[task_type].Reset( + base::BindOnce(&BasicTaskScheduler::RunScheduledTask, + weak_factory_.GetWeakPtr(), task_type)); + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( + FROM_HERE, scheduled_tasks_[task_type].callback(), + base::TimeDelta::FromSeconds(window_start_time_seconds)); +} + +void BasicTaskScheduler::CancelTask(download::DownloadTaskType task_type) { + scheduled_tasks_[task_type].Cancel(); +} + +void BasicTaskScheduler::RunScheduledTask( + download::DownloadTaskType task_type) { + get_download_service_.Run()->OnStartScheduledTask( + task_type, base::BindOnce(&BasicTaskScheduler::OnTaskFinished, + weak_factory_.GetWeakPtr())); +} + +void BasicTaskScheduler::OnTaskFinished(bool reschedule) { + // TODO(shaktisahu): Cache the original scheduling params and re-post task in + // case it needs reschedule. +} + +} // namespace download diff --git a/chromium/components/download/public/background_service/basic_task_scheduler.h b/chromium/components/download/public/background_service/basic_task_scheduler.h new file mode 100644 index 00000000000..aa4fef38521 --- /dev/null +++ b/chromium/components/download/public/background_service/basic_task_scheduler.h @@ -0,0 +1,54 @@ +// Copyright 2017 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. + +#ifndef COMPONENTS_DOWNLOAD_PUBLIC_BACKGROUND_SERVICE_BASIC_TASK_SCHEDULER_H_ +#define COMPONENTS_DOWNLOAD_PUBLIC_BACKGROUND_SERVICE_BASIC_TASK_SCHEDULER_H_ + +#include <map> + +#include "base/callback.h" +#include "base/cancelable_callback.h" +#include "base/macros.h" +#include "base/memory/weak_ptr.h" +#include "components/download/public/task/task_scheduler.h" + +namespace download { + +class DownloadService; + +// A TaskScheduler implementation that doesn't do anything but posts the task +// after the specified delay. +class BasicTaskScheduler : public download::TaskScheduler { + public: + explicit BasicTaskScheduler( + const base::RepeatingCallback<DownloadService*()>& get_download_service); + BasicTaskScheduler(const BasicTaskScheduler& other) = delete; + BasicTaskScheduler& operator=(const BasicTaskScheduler& other) = delete; + ~BasicTaskScheduler() override; + + // TaskScheduler implementation. + void ScheduleTask(download::DownloadTaskType task_type, + bool require_unmetered_network, + bool require_charging, + int optimal_battery_percentage, + int64_t window_start_time_seconds, + int64_t window_end_time_seconds) override; + void CancelTask(download::DownloadTaskType task_type) override; + + private: + void RunScheduledTask(download::DownloadTaskType task_type); + void OnTaskFinished(bool reschedule); + + // Keeps track of scheduled tasks so that they can be cancelled. + std::map<download::DownloadTaskType, base::CancelableOnceClosure> + scheduled_tasks_; + + base::RepeatingCallback<DownloadService*()> get_download_service_; + + base::WeakPtrFactory<BasicTaskScheduler> weak_factory_{this}; +}; + +} // namespace download + +#endif // COMPONENTS_DOWNLOAD_PUBLIC_TASK_TASK_SCHEDULER_H_ diff --git a/chromium/components/download/public/common/auto_resumption_handler_unittest.cc b/chromium/components/download/public/common/auto_resumption_handler_unittest.cc index 53ae100bd76..d7fa404ee55 100644 --- a/chromium/components/download/public/common/auto_resumption_handler_unittest.cc +++ b/chromium/components/download/public/common/auto_resumption_handler_unittest.cc @@ -8,6 +8,7 @@ #include "base/bind.h" #include "base/callback.h" +#include "base/callback_helpers.h" #include "base/guid.h" #include "base/optional.h" #include "base/test/simple_test_clock.h" diff --git a/chromium/components/download/public/common/base_file.h b/chromium/components/download/public/common/base_file.h index 67893e9a986..058d640e941 100644 --- a/chromium/components/download/public/common/base_file.h +++ b/chromium/components/download/public/common/base_file.h @@ -146,8 +146,15 @@ class COMPONENTS_DOWNLOAD_EXPORT BaseFile { // will cause |secure_hash_| to get calculated. std::unique_ptr<crypto::SecureHash> Finish(); - // Informs the OS that this file came from the internet. Returns a - // DownloadInterruptReason indicating the result of the operation. + // Callback used with AnnotateWithSourceInformation. + // Created by DownloadFileImpl::RenameWithRetryInternal + // to bind DownloadFileImpl::OnRenameComplete. + using OnAnnotationDoneCallback = + base::OnceCallback<void(DownloadInterruptReason)>; + + // Informs the OS that this file came from the internet. Calls + // |on_annotation_done_callback| with DownloadInterruptReason indicating the + // result of the operation. // // |client_guid|: The client GUID which will be used to identify the caller to // the system AV scanning function. @@ -156,21 +163,6 @@ class COMPONENTS_DOWNLOAD_EXPORT BaseFile { // that originated this download. Will be used to annotate source // information and also to determine the relative danger level of the // file. - DownloadInterruptReason AnnotateWithSourceInformationSync( - const std::string& client_guid, - const GURL& source_url, - const GURL& referrer_url); - - // Callback used with AnnotateWithSourceInformation. - // Created by DownloadFileImpl::RenameWithRetryInternal - // to bind DownloadFileImpl::OnRenameComplete. - using OnAnnotationDoneCallback = - base::OnceCallback<void(DownloadInterruptReason)>; - - // Called when a quarantine service is used. - // and the callback will be called from the service. - // TODO (crbug.com/973497): Remove non-service version when - // kPreventDownloadsWithSamePath feature is removed. void AnnotateWithSourceInformation( const std::string& client_guid, const GURL& source_url, diff --git a/chromium/components/download/public/common/download_features.h b/chromium/components/download/public/common/download_features.h index 8713b77be76..891cf65d4e6 100644 --- a/chromium/components/download/public/common/download_features.h +++ b/chromium/components/download/public/common/download_features.h @@ -12,13 +12,13 @@ namespace download { namespace features { -// The Finch parameter for download later feature to function only on cellular -// network. -constexpr char kDownloadLaterRequireCellular[] = "require_cellular"; +// The Finch parameter to control whether download later dialog should show the +// date time picker option. +constexpr char kDownloadLaterShowDateTimePicker[] = "show_date_time_picker"; -// The Finch parameter for download later feature to enable only in lite -// mode(data saver). -constexpr char kDownloadLaterRequireLiteMode[] = "require_lite_mode"; +// The Finch parameter to control the minimum download file size to show the +// download later dialog. +constexpr char kDownloadLaterMinFileSizeKb[] = "min_file_size_kb"; // Whether offline content provider should be used for the downloads UI.. COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature diff --git a/chromium/components/download/public/common/download_item.h b/chromium/components/download/public/common/download_item.h index 070ea7765a8..b561de01fba 100644 --- a/chromium/components/download/public/common/download_item.h +++ b/chromium/components/download/public/common/download_item.h @@ -27,7 +27,6 @@ #include "base/files/file_path.h" #include "base/memory/ref_counted.h" #include "base/optional.h" -#include "base/strings/string16.h" #include "base/supports_user_data.h" #include "components/download/public/common/download_danger_type.h" #include "components/download/public/common/download_export.h" diff --git a/chromium/components/download/public/common/download_response_handler.h b/chromium/components/download/public/common/download_response_handler.h index 7736c274a2f..e7081025df2 100644 --- a/chromium/components/download/public/common/download_response_handler.h +++ b/chromium/components/download/public/common/download_response_handler.h @@ -58,6 +58,7 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadResponseHandler ~DownloadResponseHandler() override; // network::mojom::URLLoaderClient + void OnReceiveEarlyHints(network::mojom::EarlyHintsPtr early_hints) override; void OnReceiveResponse(network::mojom::URLResponseHeadPtr head) override; void OnReceiveRedirect(const net::RedirectInfo& redirect_info, network::mojom::URLResponseHeadPtr head) override; diff --git a/chromium/components/download/public/common/download_save_info.h b/chromium/components/download/public/common/download_save_info.h index f2e0043b3a1..b847585cbb4 100644 --- a/chromium/components/download/public/common/download_save_info.h +++ b/chromium/components/download/public/common/download_save_info.h @@ -39,7 +39,7 @@ struct COMPONENTS_DOWNLOAD_EXPORT DownloadSaveInfo { // If non-empty, contains an untrusted filename suggestion. This can't contain // a path (only a filename), and is only effective if |file_path| is empty. - base::string16 suggested_name; + std::u16string suggested_name; // If valid, contains the source data stream for the file contents. base::File file; diff --git a/chromium/components/download/public/common/download_url_parameters.h b/chromium/components/download/public/common/download_url_parameters.h index d5ed92b8a8e..0be34e0e33f 100644 --- a/chromium/components/download/public/common/download_url_parameters.h +++ b/chromium/components/download/public/common/download_url_parameters.h @@ -165,7 +165,7 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadUrlParameters { // Suggested filename for the download. The suggestion can be overridden by // either a Content-Disposition response header or a |file_path|. - void set_suggested_name(const base::string16& suggested_name) { + void set_suggested_name(const std::u16string& suggested_name) { save_info_.suggested_name = suggested_name; } @@ -287,7 +287,7 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadUrlParameters { const RequestHeadersType& request_headers() const { return request_headers_; } const base::FilePath& file_path() const { return save_info_.file_path; } - const base::string16& suggested_name() const { + const std::u16string& suggested_name() const { return save_info_.suggested_name; } int64_t offset() const { return save_info_.offset; } diff --git a/chromium/components/download/public/common/mock_download_item_impl.h b/chromium/components/download/public/common/mock_download_item_impl.h index 3cafe813d18..e2ea66f139f 100644 --- a/chromium/components/download/public/common/mock_download_item_impl.h +++ b/chromium/components/download/public/common/mock_download_item_impl.h @@ -69,7 +69,7 @@ class MockDownloadItemImpl : public DownloadItemImpl { MOCK_CONST_METHOD0(CurrentSpeed, int64_t()); MOCK_CONST_METHOD0(PercentComplete, int()); MOCK_CONST_METHOD0(AllDataSaved, bool()); - MOCK_CONST_METHOD1(MatchesQuery, bool(const base::string16& query)); + MOCK_CONST_METHOD1(MatchesQuery, bool(const std::u16string& query)); MOCK_CONST_METHOD0(IsDone, bool()); MOCK_CONST_METHOD0(GetFullPath, const base::FilePath&()); MOCK_CONST_METHOD0(GetTargetFilePath, const base::FilePath&()); diff --git a/chromium/components/download/quarantine/BUILD.gn b/chromium/components/download/quarantine/BUILD.gn deleted file mode 100644 index 4fb32a83aa3..00000000000 --- a/chromium/components/download/quarantine/BUILD.gn +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright 2018 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. - -static_library("quarantine") { - sources = [ - "quarantine.cc", - "quarantine.h", - ] - - deps = [ "//components/services/quarantine" ] -} diff --git a/chromium/components/download/quarantine/DEPS b/chromium/components/download/quarantine/DEPS deleted file mode 100644 index ad6fcad01aa..00000000000 --- a/chromium/components/download/quarantine/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - "+components/services/quarantine/quarantine.h", -] diff --git a/chromium/components/download/quarantine/DIR_METADATA b/chromium/components/download/quarantine/DIR_METADATA deleted file mode 100644 index 6bf7cbfb89f..00000000000 --- a/chromium/components/download/quarantine/DIR_METADATA +++ /dev/null @@ -1,3 +0,0 @@ -monorail { - component: "UI>Browser>Downloads" -} diff --git a/chromium/components/download/quarantine/OWNERS b/chromium/components/download/quarantine/OWNERS deleted file mode 100644 index 15eb1078310..00000000000 --- a/chromium/components/download/quarantine/OWNERS +++ /dev/null @@ -1,2 +0,0 @@ -asanka@chromium.org -wfh@chromium.org diff --git a/chromium/components/download/quarantine/quarantine.cc b/chromium/components/download/quarantine/quarantine.cc deleted file mode 100644 index b576c4de1f7..00000000000 --- a/chromium/components/download/quarantine/quarantine.cc +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2016 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/download/quarantine/quarantine.h" - -namespace download { - -QuarantineFileResult QuarantineFile(const base::FilePath& file, - const GURL& source_url, - const GURL& referrer_url, - const std::string& client_guid) { - return quarantine::QuarantineFile(file, source_url, referrer_url, - client_guid); -} - -} // namespace download diff --git a/chromium/components/download/quarantine/quarantine.h b/chromium/components/download/quarantine/quarantine.h deleted file mode 100644 index eb6e94691f3..00000000000 --- a/chromium/components/download/quarantine/quarantine.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2016 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. - -#ifndef COMPONENTS_DOWNLOAD_QUARANTINE_QUARANTINE_H_ -#define COMPONENTS_DOWNLOAD_QUARANTINE_QUARANTINE_H_ - -#include <string> - -#include "components/services/quarantine/quarantine.h" - -class GURL; - -namespace base { -class FilePath; -} - -namespace download { - -using quarantine::QuarantineFileResult; - -// Quarantine a file that was downloaded from the internet. -// See components/services/quarantine/quarantine.h for a full explanation. -// -// Forwards to the definition in components/services/quarantine. -// This is a temporary state before the quarantine service is fully implemented, -// when the call sites will be updated to use the service directly. -// -// TODO: Delete this file (and all of components/download/quarantine) -// when the quarantine service is implemented. -QuarantineFileResult QuarantineFile(const base::FilePath& file, - const GURL& source_url, - const GURL& referrer_url, - const std::string& client_guid); - -} // namespace download - -#endif // COMPONENTS_DOWNLOAD_QUARANTINE_QUARANTINE_H_ |