diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-10-24 11:30:15 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-10-30 12:56:19 +0000 |
commit | 6036726eb981b6c4b42047513b9d3f4ac865daac (patch) | |
tree | 673593e70678e7789766d1f732eb51f613a2703b /chromium/components/update_client | |
parent | 466052c4e7c052268fd931888cd58961da94c586 (diff) | |
download | qtwebengine-chromium-6036726eb981b6c4b42047513b9d3f4ac865daac.tar.gz |
BASELINE: Update Chromium to 70.0.3538.78
Change-Id: Ie634710bf039e26c1957f4ae45e101bd4c434ae7
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/components/update_client')
32 files changed, 547 insertions, 672 deletions
diff --git a/chromium/components/update_client/BUILD.gn b/chromium/components/update_client/BUILD.gn index f5d203de8f6..966e7346891 100644 --- a/chromium/components/update_client/BUILD.gn +++ b/chromium/components/update_client/BUILD.gn @@ -177,6 +177,8 @@ source_set("unit_tests") { "//components/version_info:version_info", "//courgette:courgette_lib", "//net:test_support", + "//services/network:test_support", + "//services/network/public/cpp:cpp", "//services/network/public/cpp:cpp_base", "//services/service_manager/public/cpp", "//services/service_manager/public/cpp/test:test_support", diff --git a/chromium/components/update_client/action_runner.cc b/chromium/components/update_client/action_runner.cc index 8cfb13c448a..fd465d19725 100644 --- a/chromium/components/update_client/action_runner.cc +++ b/chromium/components/update_client/action_runner.cc @@ -12,8 +12,9 @@ #include "base/files/file_util.h" #include "base/location.h" #include "base/logging.h" -#include "base/task_scheduler/post_task.h" +#include "base/task/post_task.h" #include "build/build_config.h" +#include "components/crx_file/crx_verifier.h" #include "components/update_client/component.h" #include "components/update_client/configurator.h" #include "components/update_client/task_traits.h" @@ -44,7 +45,7 @@ void ActionRunner::Run(Callback run_complete) { void ActionRunner::Unpack( std::unique_ptr<service_manager::Connector> connector) { - const auto& installer = component_.crx_component()->installer; + const auto installer = component_.crx_component()->installer; base::FilePath file_path; installer->GetInstalledFile(component_.action_run(), &file_path); @@ -52,7 +53,8 @@ void ActionRunner::Unpack( // Contains the key hash of the CRX this object is allowed to run. const auto key_hash = component_.config()->GetRunActionKeyHash(); auto unpacker = base::MakeRefCounted<ComponentUnpacker>( - key_hash, file_path, installer, std::move(connector)); + key_hash, file_path, installer, std::move(connector), + component_.crx_component()->crx_format_requirement); unpacker->Unpack( base::BindOnce(&ActionRunner::UnpackComplete, base::Unretained(this))); } diff --git a/chromium/components/update_client/action_runner_win.cc b/chromium/components/update_client/action_runner_win.cc index b92a5089543..b257c382ed4 100644 --- a/chromium/components/update_client/action_runner_win.cc +++ b/chromium/components/update_client/action_runner_win.cc @@ -12,7 +12,7 @@ #include "base/process/launch.h" #include "base/process/process.h" #include "base/single_thread_task_runner.h" -#include "base/task_scheduler/post_task.h" +#include "base/task/post_task.h" #include "components/update_client/component.h" #include "components/update_client/configurator.h" #include "components/update_client/task_traits.h" diff --git a/chromium/components/update_client/background_downloader_win.cc b/chromium/components/update_client/background_downloader_win.cc index 29d3db7ce59..f0867157998 100644 --- a/chromium/components/update_client/background_downloader_win.cc +++ b/chromium/components/update_client/background_downloader_win.cc @@ -4,8 +4,6 @@ #include "components/update_client/background_downloader_win.h" -#include <atlbase.h> -#include <atlcom.h> #include <objbase.h> #include <winerror.h> @@ -26,8 +24,9 @@ #include "base/sequenced_task_runner.h" #include "base/strings/string_piece.h" #include "base/strings/sys_string_conversions.h" -#include "base/task_scheduler/post_task.h" -#include "base/task_scheduler/task_traits.h" +#include "base/task/post_task.h" +#include "base/task/task_traits.h" +#include "base/win/atl.h" #include "base/win/scoped_co_mem.h" #include "components/update_client/task_traits.h" #include "components/update_client/update_client_errors.h" @@ -581,8 +580,6 @@ void BackgroundDownloader::EndDownload(HRESULT error) { result.error = error_to_report; if (!result.error) result.response = response_; - result.downloaded_bytes = downloaded_bytes; - result.total_bytes = total_bytes; main_task_runner()->PostTask( FROM_HERE, base::BindOnce(&BackgroundDownloader::OnDownloadComplete, base::Unretained(this), is_handled, result, @@ -663,19 +660,9 @@ bool BackgroundDownloader::OnStateTransferring() { // data and it is making progress. job_stuck_begin_time_ = base::TimeTicks::Now(); - int64_t downloaded_bytes = -1; - int64_t total_bytes = -1; - HRESULT hr = GetJobByteCount(job_, &downloaded_bytes, &total_bytes); - if (FAILED(hr)) - return false; - - Result result; - result.downloaded_bytes = downloaded_bytes; - result.total_bytes = total_bytes; - main_task_runner()->PostTask( FROM_HERE, base::BindOnce(&BackgroundDownloader::OnDownloadProgress, - base::Unretained(this), result)); + base::Unretained(this))); return false; } diff --git a/chromium/components/update_client/component.cc b/chromium/components/update_client/component.cc index 4cdaaf730c7..44e8f02e87a 100644 --- a/chromium/components/update_client/component.cc +++ b/chromium/components/update_client/component.cc @@ -13,7 +13,7 @@ #include "base/location.h" #include "base/logging.h" #include "base/single_thread_task_runner.h" -#include "base/task_scheduler/post_task.h" +#include "base/task/post_task.h" #include "base/threading/thread_task_runner_handle.h" #include "components/update_client/action_runner.h" #include "components/update_client/component_unpacker.h" @@ -70,7 +70,7 @@ void InstallComplete( const base::FilePath& unpack_path, const CrxInstaller::Result& result) { base::PostTaskWithTraits( - FROM_HERE, {base::TaskPriority::BACKGROUND, base::MayBlock()}, + FROM_HERE, {base::TaskPriority::BEST_EFFORT, base::MayBlock()}, base::BindOnce( [](scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, InstallOnBlockingTaskRunnerCompleteCallback callback, @@ -149,9 +149,10 @@ void StartInstallOnBlockingTaskRunner( const std::string& fingerprint, scoped_refptr<CrxInstaller> installer, std::unique_ptr<service_manager::Connector> connector, + crx_file::VerifierFormat crx_format, InstallOnBlockingTaskRunnerCompleteCallback callback) { auto unpacker = base::MakeRefCounted<ComponentUnpacker>( - pk_hash, crx_path, installer, std::move(connector)); + pk_hash, crx_path, installer, std::move(connector), crx_format); unpacker->Unpack(base::BindOnce(&UnpackCompleteOnBlockingTaskRunner, main_task_runner, crx_path, fingerprint, @@ -256,7 +257,7 @@ void Component::Uninstall(const base::Version& version, int reason) { DCHECK_EQ(ComponentState::kNew, state()); - crx_component_ = std::make_unique<CrxComponent>(); + crx_component_ = CrxComponent(); crx_component_->version = version; previous_version_ = version; @@ -507,7 +508,7 @@ void Component::StateDownloadingDiff::DoHandle() { crx_downloader_ = update_context.crx_downloader_factory( component.CanDoBackgroundDownload(), - update_context.config->RequestContext()); + update_context.config->URLLoaderFactory()); const auto& id = component.id_; crx_downloader_->set_progress_callback( @@ -521,12 +522,10 @@ void Component::StateDownloadingDiff::DoHandle() { component.NotifyObservers(Events::COMPONENT_UPDATE_DOWNLOADING); } -// Called when progress is being made downloading a CRX. The progress may -// not monotonically increase due to how the CRX downloader switches between -// different downloaders and fallback urls. -void Component::StateDownloadingDiff::DownloadProgress( - const std::string& id, - const CrxDownloader::Result& download_result) { +// Called when progress is being made downloading a CRX. Can be called multiple +// times due to how the CRX downloader switches between different downloaders +// and fallback urls. +void Component::StateDownloadingDiff::DownloadProgress(const std::string& id) { DCHECK(thread_checker_.CalledOnValidThread()); component().NotifyObservers(Events::COMPONENT_UPDATE_DOWNLOADING); @@ -576,7 +575,7 @@ void Component::StateDownloading::DoHandle() { crx_downloader_ = update_context.crx_downloader_factory( component.CanDoBackgroundDownload(), - update_context.config->RequestContext()); + update_context.config->URLLoaderFactory()); const auto& id = component.id_; crx_downloader_->set_progress_callback( @@ -590,12 +589,10 @@ void Component::StateDownloading::DoHandle() { component.NotifyObservers(Events::COMPONENT_UPDATE_DOWNLOADING); } -// Called when progress is being made downloading a CRX. The progress may -// not monotonically increase due to how the CRX downloader switches between -// different downloaders and fallback urls. -void Component::StateDownloading::DownloadProgress( - const std::string& id, - const CrxDownloader::Result& download_result) { +// Called when progress is being made downloading a CRX. Can be called multiple +// times due to how the CRX downloader switches between different downloaders +// and fallback urls. +void Component::StateDownloading::DownloadProgress(const std::string& id) { DCHECK(thread_checker_.CalledOnValidThread()); component().NotifyObservers(Events::COMPONENT_UPDATE_DOWNLOADING); @@ -658,6 +655,7 @@ void Component::StateUpdatingDiff::DoHandle() { component.crx_component()->pk_hash, component.crx_path_, component.next_fp_, component.crx_component()->installer, std::move(connector), + component.crx_component()->crx_format_requirement, base::BindOnce(&Component::StateUpdatingDiff::InstallComplete, base::Unretained(this)))); } @@ -721,6 +719,7 @@ void Component::StateUpdating::DoHandle() { component.crx_component()->pk_hash, component.crx_path_, component.next_fp_, component.crx_component()->installer, std::move(connector), + component.crx_component()->crx_format_requirement, base::BindOnce(&Component::StateUpdating::InstallComplete, base::Unretained(this)))); } diff --git a/chromium/components/update_client/component.h b/chromium/components/update_client/component.h index e9adacd7f38..64f6d7bacae 100644 --- a/chromium/components/update_client/component.h +++ b/chromium/components/update_client/component.h @@ -73,9 +73,11 @@ class Component { std::string id() const { return id_; } - const CrxComponent* crx_component() const { return crx_component_.get(); } - void set_crx_component(std::unique_ptr<CrxComponent> crx_component) { - crx_component_ = std::move(crx_component); + const base::Optional<CrxComponent>& crx_component() const { + return crx_component_; + } + void set_crx_component(const CrxComponent& crx_component) { + crx_component_ = crx_component; } const base::Version& previous_version() const { return previous_version_; } @@ -240,11 +242,10 @@ class Component { // State overrides. void DoHandle() override; - // Called when progress is being made downloading a CRX. The progress may - // not monotonically increase due to how the CRX downloader switches between + // Called when progress is being made downloading a CRX. Can be called + // multiple times due to how the CRX downloader switches between // different downloaders and fallback urls. - void DownloadProgress(const std::string& id, - const CrxDownloader::Result& download_result); + void DownloadProgress(const std::string& id); void DownloadComplete(const std::string& id, const CrxDownloader::Result& download_result); @@ -264,11 +265,10 @@ class Component { // State overrides. void DoHandle() override; - // Called when progress is being made downloading a CRX. The progress may - // not monotonically increase due to how the CRX downloader switches between + // Called when progress is being made downloading a CRX. Can be called + // multiple times due to how the CRX downloader switches between // different downloaders and fallback urls. - void DownloadProgress(const std::string& id, - const CrxDownloader::Result& download_result); + void DownloadProgress(const std::string& id); void DownloadComplete(const std::string& id, const CrxDownloader::Result& download_result); @@ -371,7 +371,7 @@ class Component { base::ThreadChecker thread_checker_; const std::string id_; - std::unique_ptr<CrxComponent> crx_component_; + base::Optional<CrxComponent> crx_component_; // The status of the updatecheck response. std::string status_; diff --git a/chromium/components/update_client/component_patcher_operation.cc b/chromium/components/update_client/component_patcher_operation.cc index 895b488188d..b3a1ec1cd49 100644 --- a/chromium/components/update_client/component_patcher_operation.cc +++ b/chromium/components/update_client/component_patcher_operation.cc @@ -13,7 +13,7 @@ #include "base/files/memory_mapped_file.h" #include "base/location.h" #include "base/strings/string_number_conversions.h" -#include "base/task_scheduler/post_task.h" +#include "base/task/post_task.h" #include "base/threading/sequenced_task_runner_handle.h" #include "components/services/patch/public/cpp/patch.h" #include "components/update_client/update_client.h" diff --git a/chromium/components/update_client/component_unpacker.cc b/chromium/components/update_client/component_unpacker.cc index a8970c8e525..71815eab911 100644 --- a/chromium/components/update_client/component_unpacker.cc +++ b/chromium/components/update_client/component_unpacker.cc @@ -34,12 +34,14 @@ ComponentUnpacker::ComponentUnpacker( const std::vector<uint8_t>& pk_hash, const base::FilePath& path, scoped_refptr<CrxInstaller> installer, - std::unique_ptr<service_manager::Connector> connector) + std::unique_ptr<service_manager::Connector> connector, + crx_file::VerifierFormat crx_format) : pk_hash_(pk_hash), path_(path), is_delta_(false), installer_(installer), connector_(std::move(connector)), + crx_format_(crx_format), error_(UnpackerError::kNone), extended_error_(0) {} @@ -58,9 +60,9 @@ bool ComponentUnpacker::Verify() { return false; } const std::vector<std::vector<uint8_t>> required_keys = {pk_hash_}; - const crx_file::VerifierResult result = crx_file::Verify( - path_, crx_file::VerifierFormat::CRX2_OR_CRX3, required_keys, - std::vector<uint8_t>(), &public_key_, nullptr); + const crx_file::VerifierResult result = + crx_file::Verify(path_, crx_format_, required_keys, + std::vector<uint8_t>(), &public_key_, nullptr); if (result != crx_file::VerifierResult::OK_FULL && result != crx_file::VerifierResult::OK_DELTA) { error_ = UnpackerError::kInvalidFile; diff --git a/chromium/components/update_client/component_unpacker.h b/chromium/components/update_client/component_unpacker.h index 0fe5bcc927b..4c6b18527c6 100644 --- a/chromium/components/update_client/component_unpacker.h +++ b/chromium/components/update_client/component_unpacker.h @@ -18,6 +18,10 @@ #include "components/update_client/update_client_errors.h" #include "services/service_manager/public/cpp/connector.h" +namespace crx_file { +enum class VerifierFormat; +} + namespace update_client { class CrxInstaller; @@ -84,7 +88,8 @@ class ComponentUnpacker : public base::RefCountedThreadSafe<ComponentUnpacker> { ComponentUnpacker(const std::vector<uint8_t>& pk_hash, const base::FilePath& path, scoped_refptr<CrxInstaller> installer, - std::unique_ptr<service_manager::Connector> connector); + std::unique_ptr<service_manager::Connector> connector, + crx_file::VerifierFormat crx_format); // Begins the actual unpacking of the files. May invoke a patcher and the // component installer if the package is a differential update. @@ -127,6 +132,7 @@ class ComponentUnpacker : public base::RefCountedThreadSafe<ComponentUnpacker> { scoped_refptr<CrxInstaller> installer_; Callback callback_; std::unique_ptr<service_manager::Connector> connector_; + crx_file::VerifierFormat crx_format_; UnpackerError error_; int extended_error_; std::string public_key_; diff --git a/chromium/components/update_client/component_unpacker_unittest.cc b/chromium/components/update_client/component_unpacker_unittest.cc index 910bb4d99b8..8879dbf3439 100644 --- a/chromium/components/update_client/component_unpacker_unittest.cc +++ b/chromium/components/update_client/component_unpacker_unittest.cc @@ -16,7 +16,7 @@ #include "base/path_service.h" #include "base/run_loop.h" #include "base/single_thread_task_runner.h" -#include "base/task_scheduler/post_task.h" +#include "base/task/post_task.h" #include "base/test/scoped_task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "components/crx_file/crx_verifier.h" @@ -105,7 +105,8 @@ TEST_F(ComponentUnpackerTest, UnpackFullCrx) { base::MakeRefCounted<ComponentUnpacker>( std::vector<uint8_t>(std::begin(jebg_hash), std::end(jebg_hash)), test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"), nullptr, - config->CreateServiceManagerConnector()); + config->CreateServiceManagerConnector(), + crx_file::VerifierFormat::CRX2_OR_CRX3); component_unpacker->Unpack(base::BindOnce( &ComponentUnpackerTest::UnpackComplete, base::Unretained(this))); RunThreads(); @@ -136,7 +137,8 @@ TEST_F(ComponentUnpackerTest, UnpackFileNotFound) { scoped_refptr<ComponentUnpacker> component_unpacker = base::MakeRefCounted<ComponentUnpacker>( std::vector<uint8_t>(std::begin(jebg_hash), std::end(jebg_hash)), - test_file("file-not-found.crx"), nullptr, nullptr); + test_file("file-not-found.crx"), nullptr, nullptr, + crx_file::VerifierFormat::CRX2_OR_CRX3); component_unpacker->Unpack(base::BindOnce( &ComponentUnpackerTest::UnpackComplete, base::Unretained(this))); RunThreads(); @@ -153,7 +155,8 @@ TEST_F(ComponentUnpackerTest, UnpackFileHashMismatch) { scoped_refptr<ComponentUnpacker> component_unpacker = base::MakeRefCounted<ComponentUnpacker>( std::vector<uint8_t>(std::begin(abag_hash), std::end(abag_hash)), - test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"), nullptr, nullptr); + test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"), nullptr, nullptr, + crx_file::VerifierFormat::CRX2_OR_CRX3); component_unpacker->Unpack(base::BindOnce( &ComponentUnpackerTest::UnpackComplete, base::Unretained(this))); RunThreads(); diff --git a/chromium/components/update_client/configurator.h b/chromium/components/update_client/configurator.h index 370327315c8..db2762fe4f1 100644 --- a/chromium/components/update_client/configurator.h +++ b/chromium/components/update_client/configurator.h @@ -10,7 +10,6 @@ #include <vector> #include "base/memory/ref_counted.h" -#include "net/url_request/url_request_context_getter.h" #include "services/network/public/cpp/shared_url_loader_factory.h" class GURL; @@ -93,10 +92,6 @@ class Configurator : public base::RefCountedThreadSafe<Configurator> { // Returns an empty string if no policy is in effect. virtual std::string GetDownloadPreference() const = 0; - // The source of contexts for all the url requests. - virtual scoped_refptr<net::URLRequestContextGetter> RequestContext() - const = 0; - virtual scoped_refptr<network::SharedURLLoaderFactory> URLLoaderFactory() const = 0; diff --git a/chromium/components/update_client/crx_downloader.cc b/chromium/components/update_client/crx_downloader.cc index 9767f0ba87f..e07f6c6cce5 100644 --- a/chromium/components/update_client/crx_downloader.cc +++ b/chromium/components/update_client/crx_downloader.cc @@ -10,8 +10,8 @@ #include "base/files/file_util.h" #include "base/location.h" #include "base/logging.h" -#include "base/task_scheduler/post_task.h" -#include "base/task_scheduler/task_traits.h" +#include "base/task/post_task.h" +#include "base/task/task_traits.h" #include "base/threading/thread_task_runner_handle.h" #include "build/build_config.h" #if defined(OS_WIN) @@ -21,14 +21,10 @@ #include "components/update_client/update_client_errors.h" #include "components/update_client/url_fetcher_downloader.h" #include "components/update_client/utils.h" -#include "net/url_request/url_request_context_getter.h" +#include "services/network/public/cpp/shared_url_loader_factory.h" namespace update_client { -CrxDownloader::Result::Result() - : error(0), downloaded_bytes(-1), total_bytes(-1) { -} - CrxDownloader::DownloadMetrics::DownloadMetrics() : downloader(kNone), error(0), @@ -41,9 +37,10 @@ CrxDownloader::DownloadMetrics::DownloadMetrics() // which uses the BITS service. std::unique_ptr<CrxDownloader> CrxDownloader::Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { std::unique_ptr<CrxDownloader> url_fetcher_downloader = - std::make_unique<UrlFetcherDownloader>(nullptr, context_getter); + std::make_unique<UrlFetcherDownloader>(nullptr, + std::move(url_loader_factory)); #if defined(OS_WIN) if (is_background_download) { @@ -135,13 +132,13 @@ void CrxDownloader::OnDownloadComplete( download_metrics)); } -void CrxDownloader::OnDownloadProgress(const Result& result) { +void CrxDownloader::OnDownloadProgress() { DCHECK(thread_checker_.CalledOnValidThread()); if (progress_callback_.is_null()) return; - progress_callback_.Run(result); + progress_callback_.Run(); } // The function mutates the values of the parameters |result| and diff --git a/chromium/components/update_client/crx_downloader.h b/chromium/components/update_client/crx_downloader.h index eab67413e91..565b8bc40d9 100644 --- a/chromium/components/update_client/crx_downloader.h +++ b/chromium/components/update_client/crx_downloader.h @@ -19,9 +19,8 @@ #include "base/threading/thread_checker.h" #include "url/gurl.h" - -namespace net { -class URLRequestContextGetter; +namespace network { +class SharedURLLoaderFactory; } namespace update_client { @@ -57,20 +56,11 @@ class CrxDownloader { // Contains the progress or the outcome of the download. struct Result { - Result(); - // Download error: 0 indicates success. - int error; + int error = 0; // Path of the downloaded file if the download was successful. base::FilePath response; - - // Number of bytes actually downloaded, not including the bytes downloaded - // as a result of falling back on urls. - int64_t downloaded_bytes; - - // Number of bytes expected to be downloaded. - int64_t total_bytes; }; // The callback fires only once, regardless of how many urls are tried, and @@ -80,15 +70,14 @@ class CrxDownloader { // specific error codes and download metrics. using DownloadCallback = base::OnceCallback<void(const Result& result)>; - // The callback may fire 0 or many times during a download. Since this + // The callback may fire 0 or once during a download. Since this // class implements a chain of responsibility, the callback can fire for - // different urls and different downloaders. The number of actual downloaded - // bytes is not guaranteed to monotonically increment over time. - using ProgressCallback = base::Callback<void(const Result& result)>; + // different urls and different downloaders. + using ProgressCallback = base::RepeatingCallback<void()>; using Factory = std::unique_ptr<CrxDownloader> (*)( bool, - scoped_refptr<net::URLRequestContextGetter>); + scoped_refptr<network::SharedURLLoaderFactory>); // Factory method to create an instance of this class and build the // chain of responsibility. |is_background_download| specifies that a @@ -97,7 +86,7 @@ class CrxDownloader { // code such as file IO operations. static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter); + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory); virtual ~CrxDownloader(); void set_progress_callback(const ProgressCallback& progress_callback); @@ -132,7 +121,7 @@ class CrxDownloader { const DownloadMetrics& download_metrics); // Calls the callback when progress is made. - void OnDownloadProgress(const Result& result); + void OnDownloadProgress(); // Returns the url which is currently being downloaded from. GURL url() const; diff --git a/chromium/components/update_client/crx_downloader_unittest.cc b/chromium/components/update_client/crx_downloader_unittest.cc index cb5c80842f9..06a7361b22a 100644 --- a/chromium/components/update_client/crx_downloader_unittest.cc +++ b/chromium/components/update_client/crx_downloader_unittest.cc @@ -13,14 +13,15 @@ #include "base/memory/ref_counted.h" #include "base/path_service.h" #include "base/run_loop.h" +#include "base/test/bind_test_util.h" #include "base/test/scoped_task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "build/build_config.h" #include "components/update_client/update_client_errors.h" #include "components/update_client/utils.h" #include "net/base/net_errors.h" -#include "net/url_request/test_url_request_interceptor.h" -#include "net/url_request/url_request_test_util.h" +#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h" +#include "services/network/test/test_url_loader_factory.h" #include "testing/gtest/include/gtest/gtest.h" using base::ContentsEqual; @@ -29,9 +30,6 @@ namespace update_client { namespace { -// Intercepts HTTP GET requests sent to "localhost". -typedef net::LocalHostTestURLRequestInterceptor GetInterceptor; - const char kTestFileName[] = "jebgalgnebhfojomionfpkfelancnnkf.crx"; const char hash_jebg[] = @@ -61,12 +59,18 @@ class CrxDownloaderTest : public testing::Test { void DownloadComplete(int crx_context, const CrxDownloader::Result& result); - void DownloadProgress(int crx_context, const CrxDownloader::Result& result); + void DownloadProgress(int crx_context); + + int GetInterceptorCount() { return interceptor_count_; } + + void AddResponse(const GURL& url, + const base::FilePath& file_path, + int net_error); protected: std::unique_ptr<CrxDownloader> crx_downloader_; - std::unique_ptr<GetInterceptor> get_interceptor_; + network::TestURLLoaderFactory test_url_loader_factory_; CrxDownloader::DownloadCallback callback_; CrxDownloader::ProgressCallback progress_callback_; @@ -78,14 +82,17 @@ class CrxDownloaderTest : public testing::Test { // These members are updated by DownloadProgress. int num_progress_calls_; - CrxDownloader::Result download_progress_result_; + + // Accumulates the number of loads triggered. + int interceptor_count_ = 0; // A magic value for the context to be used in the tests. static const int kExpectedContext = 0xaabb; private: base::test::ScopedTaskEnvironment scoped_task_environment_; - scoped_refptr<net::TestURLRequestContextGetter> context_; + scoped_refptr<network::SharedURLLoaderFactory> + test_shared_url_loader_factory_; base::OnceClosure quit_closure_; }; @@ -103,29 +110,24 @@ CrxDownloaderTest::CrxDownloaderTest() num_progress_calls_(0), scoped_task_environment_( base::test::ScopedTaskEnvironment::MainThreadType::IO), - context_(base::MakeRefCounted<net::TestURLRequestContextGetter>( - base::ThreadTaskRunnerHandle::Get())) {} - -CrxDownloaderTest::~CrxDownloaderTest() { - context_ = nullptr; + test_shared_url_loader_factory_( + base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>( + &test_url_loader_factory_)) {} - // The GetInterceptor requires the message loop to run to destruct correctly. - get_interceptor_.reset(); - RunThreadsUntilIdle(); -} +CrxDownloaderTest::~CrxDownloaderTest() {} void CrxDownloaderTest::SetUp() { num_download_complete_calls_ = 0; download_complete_result_ = CrxDownloader::Result(); num_progress_calls_ = 0; - download_progress_result_ = CrxDownloader::Result(); // Do not use the background downloader in these tests. - crx_downloader_ = CrxDownloader::Create(false, context_.get()); + crx_downloader_ = + CrxDownloader::Create(false, test_shared_url_loader_factory_); crx_downloader_->set_progress_callback(progress_callback_); - get_interceptor_ = std::make_unique<GetInterceptor>( - base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get()); + test_url_loader_factory_.SetInterceptor(base::BindLambdaForTesting( + [&](const network::ResourceRequest& request) { interceptor_count_++; })); } void CrxDownloaderTest::TearDown() { @@ -145,10 +147,28 @@ void CrxDownloaderTest::DownloadComplete(int crx_context, Quit(); } -void CrxDownloaderTest::DownloadProgress(int crx_context, - const CrxDownloader::Result& result) { +void CrxDownloaderTest::DownloadProgress(int crx_context) { ++num_progress_calls_; - download_progress_result_ = result; +} + +void CrxDownloaderTest::AddResponse(const GURL& url, + const base::FilePath& file_path, + int net_error) { + if (net_error == net::OK) { + std::string data; + EXPECT_TRUE(base::ReadFileToString(file_path, &data)); + network::ResourceResponseHead head; + head.content_length = data.size(); + network::URLLoaderCompletionStatus status(net_error); + status.decoded_body_length = data.size(); + test_url_loader_factory_.AddResponse(url, head, data, status); + return; + } + + EXPECT_NE(net_error, net::OK); + test_url_loader_factory_.AddResponse( + url, network::ResourceResponseHead(), std::string(), + network::URLLoaderCompletionStatus(net_error)); } void CrxDownloaderTest::RunThreads() { @@ -180,8 +200,6 @@ TEST_F(CrxDownloaderTest, NoUrl) { EXPECT_EQ(static_cast<int>(CrxDownloaderError::NO_URL), download_complete_result_.error); EXPECT_TRUE(download_complete_result_.response.empty()); - EXPECT_EQ(-1, download_complete_result_.downloaded_bytes); - EXPECT_EQ(-1, download_complete_result_.total_bytes); EXPECT_EQ(0, num_progress_calls_); } @@ -197,8 +215,6 @@ TEST_F(CrxDownloaderTest, NoHash) { EXPECT_EQ(static_cast<int>(CrxDownloaderError::NO_HASH), download_complete_result_.error); EXPECT_TRUE(download_complete_result_.response.empty()); - EXPECT_EQ(-1, download_complete_result_.downloaded_bytes); - EXPECT_EQ(-1, download_complete_result_.total_bytes); EXPECT_EQ(0, num_progress_calls_); } @@ -208,27 +224,23 @@ TEST_F(CrxDownloaderTest, OneUrl) { GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); const base::FilePath test_file(MakeTestFilePath(kTestFileName)); - get_interceptor_->SetResponse(expected_crx_url, test_file); + AddResponse(expected_crx_url, test_file, net::OK); crx_downloader_->StartDownloadFromUrl( expected_crx_url, std::string(hash_jebg), std::move(callback_)); RunThreads(); - EXPECT_EQ(1, get_interceptor_->GetHitCount()); + EXPECT_EQ(1, GetInterceptorCount()); EXPECT_EQ(1, num_download_complete_calls_); EXPECT_EQ(kExpectedContext, crx_context_); EXPECT_EQ(0, download_complete_result_.error); - EXPECT_EQ(1843, download_complete_result_.downloaded_bytes); - EXPECT_EQ(1843, download_complete_result_.total_bytes); EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file)); EXPECT_TRUE( DeleteFileAndEmptyParentDirectory(download_complete_result_.response)); EXPECT_LE(1, num_progress_calls_); - EXPECT_EQ(1843, download_progress_result_.downloaded_bytes); - EXPECT_EQ(1843, download_progress_result_.total_bytes); } // Tests that downloading from one url fails if the actual hash of the file @@ -238,7 +250,7 @@ TEST_F(CrxDownloaderTest, OneUrlBadHash) { GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); const base::FilePath test_file(MakeTestFilePath(kTestFileName)); - get_interceptor_->SetResponse(expected_crx_url, test_file); + AddResponse(expected_crx_url, test_file, net::OK); crx_downloader_->StartDownloadFromUrl( expected_crx_url, @@ -247,19 +259,15 @@ TEST_F(CrxDownloaderTest, OneUrlBadHash) { std::move(callback_)); RunThreads(); - EXPECT_EQ(1, get_interceptor_->GetHitCount()); + EXPECT_EQ(1, GetInterceptorCount()); EXPECT_EQ(1, num_download_complete_calls_); EXPECT_EQ(kExpectedContext, crx_context_); EXPECT_EQ(static_cast<int>(CrxDownloaderError::BAD_HASH), download_complete_result_.error); - EXPECT_EQ(1843, download_complete_result_.downloaded_bytes); - EXPECT_EQ(1843, download_complete_result_.total_bytes); EXPECT_TRUE(download_complete_result_.response.empty()); EXPECT_LE(1, num_progress_calls_); - EXPECT_EQ(1843, download_progress_result_.downloaded_bytes); - EXPECT_EQ(1843, download_progress_result_.total_bytes); } // Tests that specifying two urls has no side effects. Expect a successful @@ -269,7 +277,7 @@ TEST_F(CrxDownloaderTest, TwoUrls) { GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); const base::FilePath test_file(MakeTestFilePath(kTestFileName)); - get_interceptor_->SetResponse(expected_crx_url, test_file); + AddResponse(expected_crx_url, test_file, net::OK); std::vector<GURL> urls; urls.push_back(expected_crx_url); @@ -279,21 +287,17 @@ TEST_F(CrxDownloaderTest, TwoUrls) { std::move(callback_)); RunThreads(); - EXPECT_EQ(1, get_interceptor_->GetHitCount()); + EXPECT_EQ(1, GetInterceptorCount()); EXPECT_EQ(1, num_download_complete_calls_); EXPECT_EQ(kExpectedContext, crx_context_); EXPECT_EQ(0, download_complete_result_.error); - EXPECT_EQ(1843, download_complete_result_.downloaded_bytes); - EXPECT_EQ(1843, download_complete_result_.total_bytes); EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file)); EXPECT_TRUE( DeleteFileAndEmptyParentDirectory(download_complete_result_.response)); EXPECT_LE(1, num_progress_calls_); - EXPECT_EQ(1843, download_progress_result_.downloaded_bytes); - EXPECT_EQ(1843, download_progress_result_.total_bytes); } // Tests that the fallback to a valid url is successful. @@ -304,9 +308,8 @@ TEST_F(CrxDownloaderTest, TwoUrls_FirstInvalid) { GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc.crx"); const base::FilePath test_file(MakeTestFilePath(kTestFileName)); - get_interceptor_->SetResponse(expected_crx_url, test_file); - get_interceptor_->SetResponse(no_file_url, - base::FilePath(FILE_PATH_LITERAL("no-file"))); + AddResponse(expected_crx_url, test_file, net::OK); + AddResponse(no_file_url, base::FilePath(), net::ERR_FILE_NOT_FOUND); std::vector<GURL> urls; urls.push_back(no_file_url); @@ -316,22 +319,18 @@ TEST_F(CrxDownloaderTest, TwoUrls_FirstInvalid) { std::move(callback_)); RunThreads(); - EXPECT_EQ(2, get_interceptor_->GetHitCount()); + EXPECT_EQ(2, GetInterceptorCount()); EXPECT_EQ(1, num_download_complete_calls_); EXPECT_EQ(kExpectedContext, crx_context_); EXPECT_EQ(0, download_complete_result_.error); - EXPECT_EQ(1843, download_complete_result_.downloaded_bytes); - EXPECT_EQ(1843, download_complete_result_.total_bytes); EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file)); EXPECT_TRUE( DeleteFileAndEmptyParentDirectory(download_complete_result_.response)); - // Expect at least some progress reported by the fetcher. + // Expect at least some progress reported by the loader. EXPECT_LE(1, num_progress_calls_); - EXPECT_EQ(1843, download_progress_result_.downloaded_bytes); - EXPECT_EQ(1843, download_progress_result_.total_bytes); const auto download_metrics = crx_downloader_->download_metrics(); ASSERT_EQ(2u, download_metrics.size()); @@ -354,9 +353,8 @@ TEST_F(CrxDownloaderTest, TwoUrls_SecondInvalid) { GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc.crx"); const base::FilePath test_file(MakeTestFilePath(kTestFileName)); - get_interceptor_->SetResponse(expected_crx_url, test_file); - get_interceptor_->SetResponse(no_file_url, - base::FilePath(FILE_PATH_LITERAL("no-file"))); + AddResponse(expected_crx_url, test_file, net::OK); + AddResponse(no_file_url, base::FilePath(), net::ERR_FILE_NOT_FOUND); std::vector<GURL> urls; urls.push_back(expected_crx_url); @@ -366,21 +364,17 @@ TEST_F(CrxDownloaderTest, TwoUrls_SecondInvalid) { std::move(callback_)); RunThreads(); - EXPECT_EQ(1, get_interceptor_->GetHitCount()); + EXPECT_EQ(1, GetInterceptorCount()); EXPECT_EQ(1, num_download_complete_calls_); EXPECT_EQ(kExpectedContext, crx_context_); EXPECT_EQ(0, download_complete_result_.error); - EXPECT_EQ(1843, download_complete_result_.downloaded_bytes); - EXPECT_EQ(1843, download_complete_result_.total_bytes); EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file)); EXPECT_TRUE( DeleteFileAndEmptyParentDirectory(download_complete_result_.response)); EXPECT_LE(1, num_progress_calls_); - EXPECT_EQ(1843, download_progress_result_.downloaded_bytes); - EXPECT_EQ(1843, download_progress_result_.total_bytes); EXPECT_EQ(1u, crx_downloader_->download_metrics().size()); } @@ -390,8 +384,7 @@ TEST_F(CrxDownloaderTest, TwoUrls_BothInvalid) { const GURL expected_crx_url = GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); - get_interceptor_->SetResponse(expected_crx_url, - base::FilePath(FILE_PATH_LITERAL("no-file"))); + AddResponse(expected_crx_url, base::FilePath(), net::ERR_FILE_NOT_FOUND); std::vector<GURL> urls; urls.push_back(expected_crx_url); @@ -401,7 +394,7 @@ TEST_F(CrxDownloaderTest, TwoUrls_BothInvalid) { std::move(callback_)); RunThreads(); - EXPECT_EQ(2, get_interceptor_->GetHitCount()); + EXPECT_EQ(2, GetInterceptorCount()); EXPECT_EQ(1, num_download_complete_calls_); EXPECT_EQ(kExpectedContext, crx_context_); diff --git a/chromium/components/update_client/crx_update_item.h b/chromium/components/update_client/crx_update_item.h index 9fd73988a7e..ac645b592bb 100644 --- a/chromium/components/update_client/crx_update_item.h +++ b/chromium/components/update_client/crx_update_item.h @@ -11,6 +11,7 @@ #include <vector> #include "base/memory/weak_ptr.h" +#include "base/optional.h" #include "base/time/time.h" #include "base/version.h" #include "components/update_client/crx_downloader.h" @@ -27,7 +28,12 @@ struct CrxUpdateItem { ComponentState state; std::string id; - CrxComponent component; + + // The value of this data member is provided to the |UpdateClient| by the + // caller by responding to the |CrxDataCallback|. If the caller can't + // provide this value, for instance, in cases where the CRX was uninstalled, + // then the |component| member will not be present. + base::Optional<CrxComponent> component; // Time when an update check for this CRX has happened. base::TimeTicks last_check; diff --git a/chromium/components/update_client/ping_manager_unittest.cc b/chromium/components/update_client/ping_manager_unittest.cc index 29e5481cfcf..3e0b9db9142 100644 --- a/chromium/components/update_client/ping_manager_unittest.cc +++ b/chromium/components/update_client/ping_manager_unittest.cc @@ -112,7 +112,7 @@ TEST_F(PingManagerTest, SendPing) { { Component component(*update_context, "abc"); - component.crx_component_ = std::make_unique<CrxComponent>(); + component.crx_component_ = CrxComponent(); component.state_ = std::make_unique<Component::StateUpdated>(&component); component.previous_version_ = base::Version("1.0"); component.next_version_ = base::Version("2.0"); @@ -145,7 +145,7 @@ TEST_F(PingManagerTest, SendPing) { { // Test eventresult="0" is sent for failed updates. Component component(*update_context, "abc"); - component.crx_component_ = std::make_unique<CrxComponent>(); + component.crx_component_ = CrxComponent(); component.state_ = std::make_unique<Component::StateUpdateError>(&component); component.previous_version_ = base::Version("1.0"); @@ -169,7 +169,7 @@ TEST_F(PingManagerTest, SendPing) { { // Test the error values and the fingerprints. Component component(*update_context, "abc"); - component.crx_component_ = std::make_unique<CrxComponent>(); + component.crx_component_ = CrxComponent(); component.state_ = std::make_unique<Component::StateUpdateError>(&component); component.previous_version_ = base::Version("1.0"); @@ -206,7 +206,7 @@ TEST_F(PingManagerTest, SendPing) { { // Test an invalid |next_version| is not serialized. Component component(*update_context, "abc"); - component.crx_component_ = std::make_unique<CrxComponent>(); + component.crx_component_ = CrxComponent(); component.state_ = std::make_unique<Component::StateUpdateError>(&component); component.previous_version_ = base::Version("1.0"); @@ -230,7 +230,7 @@ TEST_F(PingManagerTest, SendPing) { // Test a valid |previouversion| and |next_version| = base::Version("0") // are serialized correctly under <event...> for uninstall. Component component(*update_context, "abc"); - component.crx_component_ = std::make_unique<CrxComponent>(); + component.crx_component_ = CrxComponent(); component.Uninstall(base::Version("1.2.3.4"), 0); component.AppendEvent(BuildUninstalledEventElement(component)); @@ -251,7 +251,7 @@ TEST_F(PingManagerTest, SendPing) { { // Test the download metrics. Component component(*update_context, "abc"); - component.crx_component_ = std::make_unique<CrxComponent>(); + component.crx_component_ = CrxComponent(); component.state_ = std::make_unique<Component::StateUpdated>(&component); component.previous_version_ = base::Version("1.0"); component.next_version_ = base::Version("2.0"); @@ -309,7 +309,7 @@ TEST_F(PingManagerTest, RequiresEncryption) { const auto update_context = MakeMockUpdateContext(); Component component(*update_context, "abc"); - component.crx_component_ = std::make_unique<CrxComponent>(); + component.crx_component_ = CrxComponent(); // The default value for |requires_network_encryption| is true. EXPECT_TRUE(component.crx_component_->requires_network_encryption); diff --git a/chromium/components/update_client/protocol_builder.cc b/chromium/components/update_client/protocol_builder.cc index e708c46706a..54a172e1c50 100644 --- a/chromium/components/update_client/protocol_builder.cc +++ b/chromium/components/update_client/protocol_builder.cc @@ -336,7 +336,7 @@ std::string BuildUpdateCheckRequest( DCHECK_EQ(1u, components.count(id)); const auto& component = *components.at(id); const auto& component_id = component.id(); - const auto* crx_component = component.crx_component(); + const auto crx_component = component.crx_component(); DCHECK(crx_component); diff --git a/chromium/components/update_client/task_traits.h b/chromium/components/update_client/task_traits.h index 1a3d393b264..d14bbea8e00 100644 --- a/chromium/components/update_client/task_traits.h +++ b/chromium/components/update_client/task_traits.h @@ -5,22 +5,22 @@ #ifndef COMPONENTS_UPDATE_CLIENT_TASK_TRAITS_H_ #define COMPONENTS_UPDATE_CLIENT_TASK_TRAITS_H_ -#include "base/task_scheduler/task_traits.h" +#include "base/task/task_traits.h" namespace update_client { constexpr base::TaskTraits kTaskTraits = { - base::MayBlock(), base::TaskPriority::BACKGROUND, + base::MayBlock(), base::TaskPriority::BEST_EFFORT, base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}; constexpr base::TaskTraits kTaskTraitsBackgroundDownloader = { - base::MayBlock(), base::TaskPriority::BACKGROUND, + base::MayBlock(), base::TaskPriority::BEST_EFFORT, base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}; // This task joins a process, hence .WithBaseSyncPrimitives(). constexpr base::TaskTraits kTaskTraitsRunCommand = { base::MayBlock(), base::WithBaseSyncPrimitives(), - base::TaskPriority::BACKGROUND, + base::TaskPriority::BEST_EFFORT, base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}; } // namespace update_client diff --git a/chromium/components/update_client/test_configurator.cc b/chromium/components/update_client/test_configurator.cc index 882e5db3cb0..be07318b6fe 100644 --- a/chromium/components/update_client/test_configurator.cc +++ b/chromium/components/update_client/test_configurator.cc @@ -12,7 +12,6 @@ #include "components/services/patch/patch_service.h" #include "components/services/unzip/unzip_service.h" #include "components/update_client/activity_data_service.h" -#include "net/url_request/url_request_test_util.h" #include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h" #include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/service.h" @@ -38,8 +37,6 @@ TestConfigurator::TestConfigurator() ondemand_time_(0), enabled_cup_signing_(false), enabled_component_updates_(true), - context_(base::MakeRefCounted<net::TestURLRequestContextGetter>( - base::ThreadTaskRunnerHandle::Get())), test_shared_loader_factory_( base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>( &test_url_loader_factory_)) { @@ -119,11 +116,6 @@ std::string TestConfigurator::GetDownloadPreference() const { return download_preference_; } -scoped_refptr<net::URLRequestContextGetter> TestConfigurator::RequestContext() - const { - return context_; -} - scoped_refptr<network::SharedURLLoaderFactory> TestConfigurator::URLLoaderFactory() const { return test_shared_loader_factory_; diff --git a/chromium/components/update_client/test_configurator.h b/chromium/components/update_client/test_configurator.h index c7d4bbf715d..4868d734662 100644 --- a/chromium/components/update_client/test_configurator.h +++ b/chromium/components/update_client/test_configurator.h @@ -20,11 +20,6 @@ class PrefService; -namespace net { -class TestURLRequestContextGetter; -class URLRequestContextGetter; -} // namespace net - namespace network { class SharedURLLoaderFactory; } // namespace network @@ -91,7 +86,6 @@ class TestConfigurator : public Configurator { std::string GetOSLongName() const override; std::string ExtraRequestParams() const override; std::string GetDownloadPreference() const override; - scoped_refptr<net::URLRequestContextGetter> RequestContext() const override; scoped_refptr<network::SharedURLLoaderFactory> URLLoaderFactory() const override; std::unique_ptr<service_manager::Connector> CreateServiceManagerConnector() @@ -137,7 +131,6 @@ class TestConfigurator : public Configurator { std::unique_ptr<service_manager::TestConnectorFactory> connector_factory_; std::unique_ptr<service_manager::Connector> connector_; - scoped_refptr<net::TestURLRequestContextGetter> context_; scoped_refptr<network::SharedURLLoaderFactory> test_shared_loader_factory_; network::TestURLLoaderFactory test_url_loader_factory_; diff --git a/chromium/components/update_client/test_installer.cc b/chromium/components/update_client/test_installer.cc index 3ed161acb03..d0febe59c41 100644 --- a/chromium/components/update_client/test_installer.cc +++ b/chromium/components/update_client/test_installer.cc @@ -8,8 +8,8 @@ #include "base/files/file_path.h" #include "base/files/file_util.h" -#include "base/task_scheduler/post_task.h" -#include "base/task_scheduler/task_traits.h" +#include "base/task/post_task.h" +#include "base/task/task_traits.h" #include "base/values.h" #include "components/update_client/update_client_errors.h" #include "components/update_client/utils.h" diff --git a/chromium/components/update_client/update_checker.cc b/chromium/components/update_client/update_checker.cc index d4ecc9e73ee..d915d3834d4 100644 --- a/chromium/components/update_client/update_checker.cc +++ b/chromium/components/update_client/update_checker.cc @@ -17,7 +17,7 @@ #include "base/logging.h" #include "base/macros.h" #include "base/strings/stringprintf.h" -#include "base/task_scheduler/post_task.h" +#include "base/task/post_task.h" #include "base/threading/thread_checker.h" #include "base/threading/thread_task_runner_handle.h" #include "build/build_config.h" diff --git a/chromium/components/update_client/update_checker_unittest.cc b/chromium/components/update_client/update_checker_unittest.cc index bb8cf9ebcdf..8fc15dce703 100644 --- a/chromium/components/update_client/update_checker_unittest.cc +++ b/chromium/components/update_client/update_checker_unittest.cc @@ -18,7 +18,7 @@ #include "base/run_loop.h" #include "base/stl_util.h" #include "base/strings/stringprintf.h" -#include "base/task_scheduler/post_task.h" +#include "base/task/post_task.h" #include "base/test/bind_test_util.h" #include "base/test/scoped_task_environment.h" #include "base/threading/thread_task_runner_handle.h" @@ -227,17 +227,16 @@ scoped_refptr<UpdateContext> UpdateCheckerTest::MakeMockUpdateContext() const { } std::unique_ptr<Component> UpdateCheckerTest::MakeComponent() const { - std::unique_ptr<CrxComponent> crx_component = - std::make_unique<CrxComponent>(); - crx_component->name = "test_jebg"; - crx_component->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx_component->installer = nullptr; - crx_component->version = base::Version("0.9"); - crx_component->fingerprint = "fp1"; + CrxComponent crx_component; + crx_component.name = "test_jebg"; + crx_component.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx_component.installer = nullptr; + crx_component.version = base::Version("0.9"); + crx_component.fingerprint = "fp1"; auto component = std::make_unique<Component>(*update_context_, kUpdateItemId); component->state_ = std::make_unique<Component::StateNew>(component.get()); - component->crx_component_ = std::move(crx_component); + component->crx_component_ = crx_component; return component; } @@ -621,7 +620,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckInstallSource) { components[kUpdateItemId] = MakeComponent(); auto& component = components[kUpdateItemId]; - auto* crx_component = const_cast<CrxComponent*>(component->crx_component()); + auto crx_component = component->crx_component(); EXPECT_TRUE(post_interceptor_->ExpectRequest( std::make_unique<PartialMatch>("updatecheck"), @@ -652,6 +651,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckInstallSource) { update_context_->is_foreground = false; crx_component->install_source = "webstore"; crx_component->install_location = "external"; + component->set_crx_component(*crx_component); EXPECT_TRUE(post_interceptor_->ExpectRequest( std::make_unique<PartialMatch>("updatecheck"), test_file("updatecheck_reply_1.xml"))); @@ -668,6 +668,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckInstallSource) { update_context_->is_foreground = true; crx_component->install_source = "sideload"; crx_component->install_location = "policy"; + component->set_crx_component(*crx_component); EXPECT_TRUE(post_interceptor_->ExpectRequest( std::make_unique<PartialMatch>("updatecheck"), test_file("updatecheck_reply_1.xml"))); @@ -689,7 +690,7 @@ TEST_F(UpdateCheckerTest, ComponentDisabled) { components[kUpdateItemId] = MakeComponent(); auto& component = components[kUpdateItemId]; - auto* crx_component = const_cast<CrxComponent*>(component->crx_component()); + auto crx_component = component->crx_component(); EXPECT_TRUE(post_interceptor_->ExpectRequest( std::make_unique<PartialMatch>("updatecheck"), @@ -705,6 +706,7 @@ TEST_F(UpdateCheckerTest, ComponentDisabled) { EXPECT_THAT(body0, testing::Not(testing::HasSubstr("<disabled"))); crx_component->disabled_reasons = {}; + component->set_crx_component(*crx_component); update_checker_ = UpdateChecker::Create(config_, metadata_.get()); EXPECT_TRUE(post_interceptor_->ExpectRequest( std::make_unique<PartialMatch>("updatecheck"), @@ -720,6 +722,7 @@ TEST_F(UpdateCheckerTest, ComponentDisabled) { EXPECT_THAT(body1, testing::Not(testing::HasSubstr("<disabled"))); crx_component->disabled_reasons = {0}; + component->set_crx_component(*crx_component); EXPECT_TRUE(post_interceptor_->ExpectRequest( std::make_unique<PartialMatch>("updatecheck"), test_file("updatecheck_reply_1.xml"))); @@ -734,6 +737,7 @@ TEST_F(UpdateCheckerTest, ComponentDisabled) { EXPECT_THAT(body2, testing::HasSubstr(R"(<disabled reason="0")")); crx_component->disabled_reasons = {1}; + component->set_crx_component(*crx_component); update_checker_ = UpdateChecker::Create(config_, metadata_.get()); EXPECT_TRUE(post_interceptor_->ExpectRequest( std::make_unique<PartialMatch>("updatecheck"), @@ -749,6 +753,7 @@ TEST_F(UpdateCheckerTest, ComponentDisabled) { EXPECT_THAT(body3, testing::HasSubstr(R"(<disabled reason="1")")); crx_component->disabled_reasons = {4, 8, 16}; + component->set_crx_component(*crx_component); update_checker_ = UpdateChecker::Create(config_, metadata_.get()); EXPECT_TRUE(post_interceptor_->ExpectRequest( std::make_unique<PartialMatch>("updatecheck"), @@ -766,6 +771,7 @@ TEST_F(UpdateCheckerTest, ComponentDisabled) { EXPECT_THAT(body4, testing::HasSubstr(R"(<disabled reason="16")")); crx_component->disabled_reasons = {0, 4, 8, 16}; + component->set_crx_component(*crx_component); update_checker_ = UpdateChecker::Create(config_, metadata_.get()); EXPECT_TRUE(post_interceptor_->ExpectRequest( std::make_unique<PartialMatch>("updatecheck"), @@ -792,14 +798,14 @@ TEST_F(UpdateCheckerTest, UpdateCheckUpdateDisabled) { components[kUpdateItemId] = MakeComponent(); auto& component = components[kUpdateItemId]; + auto crx_component = component->crx_component(); // Tests the scenario where: // * the component does not support group policies. // * the component updates are disabled. // Expects the group policy to be ignored and the update check to not // include the "updatedisabled" attribute. - EXPECT_FALSE(component->crx_component_ - ->supports_group_policy_enable_component_updates); + EXPECT_FALSE(crx_component->supports_group_policy_enable_component_updates); EXPECT_TRUE(post_interceptor_->ExpectRequest( std::make_unique<PartialMatch>("updatecheck"), @@ -818,8 +824,8 @@ TEST_F(UpdateCheckerTest, UpdateCheckUpdateDisabled) { // * the component supports group policies. // * the component updates are disabled. // Expects the update check to include the "updatedisabled" attribute. - component->crx_component_->supports_group_policy_enable_component_updates = - true; + crx_component->supports_group_policy_enable_component_updates = true; + component->set_crx_component(*crx_component); update_checker_ = UpdateChecker::Create(config_, metadata_.get()); EXPECT_TRUE(post_interceptor_->ExpectRequest( std::make_unique<PartialMatch>("updatecheck"), @@ -839,8 +845,8 @@ TEST_F(UpdateCheckerTest, UpdateCheckUpdateDisabled) { // * the component does not support group policies. // * the component updates are enabled. // Expects the update check to not include the "updatedisabled" attribute. - component->crx_component_->supports_group_policy_enable_component_updates = - false; + crx_component->supports_group_policy_enable_component_updates = false; + component->set_crx_component(*crx_component); update_checker_ = UpdateChecker::Create(config_, metadata_.get()); EXPECT_TRUE(post_interceptor_->ExpectRequest( std::make_unique<PartialMatch>("updatecheck"), @@ -859,8 +865,8 @@ TEST_F(UpdateCheckerTest, UpdateCheckUpdateDisabled) { // * the component supports group policies. // * the component updates are enabled. // Expects the update check to not include the "updatedisabled" attribute. - component->crx_component_->supports_group_policy_enable_component_updates = - true; + crx_component->supports_group_policy_enable_component_updates = true; + component->set_crx_component(*crx_component); update_checker_ = UpdateChecker::Create(config_, metadata_.get()); EXPECT_TRUE(post_interceptor_->ExpectRequest( std::make_unique<PartialMatch>("updatecheck"), @@ -939,7 +945,7 @@ TEST_F(UpdateCheckerTest, UpdatePauseResume) { testing::HasSubstr(R"(<packages><package fp="fp1"/></packages></app>)")); } -// Tests that an update checker object and its underlying URLFetcher can +// Tests that an update checker object and its underlying SimpleURLLoader can // be safely destroyed while it is paused. TEST_F(UpdateCheckerTest, UpdateResetUpdateChecker) { base::RunLoop runloop; diff --git a/chromium/components/update_client/update_client.cc b/chromium/components/update_client/update_client.cc index 561bbcf9902..369c6d32c6a 100644 --- a/chromium/components/update_client/update_client.cc +++ b/chromium/components/update_client/update_client.cc @@ -19,6 +19,7 @@ #include "base/stl_util.h" #include "base/threading/thread_checker.h" #include "base/threading/thread_task_runner_handle.h" +#include "components/crx_file/crx_verifier.h" #include "components/prefs/pref_registry_simple.h" #include "components/update_client/configurator.h" #include "components/update_client/crx_update_item.h" @@ -37,21 +38,17 @@ namespace update_client { CrxUpdateItem::CrxUpdateItem() : state(ComponentState::kNew) {} - -CrxUpdateItem::~CrxUpdateItem() { -} - +CrxUpdateItem::~CrxUpdateItem() = default; CrxUpdateItem::CrxUpdateItem(const CrxUpdateItem& other) = default; CrxComponent::CrxComponent() : allows_background_download(true), requires_network_encryption(true), + crx_format_requirement( + crx_file::VerifierFormat::CRX3_WITH_PUBLISHER_PROOF), supports_group_policy_enable_component_updates(false) {} - CrxComponent::CrxComponent(const CrxComponent& other) = default; - -CrxComponent::~CrxComponent() { -} +CrxComponent::~CrxComponent() = default; // It is important that an instance of the UpdateClient binds an unretained // pointer to itself. Otherwise, a life time circular dependency between this diff --git a/chromium/components/update_client/update_client.h b/chromium/components/update_client/update_client.h index d8d546a16a2..6d58c59010f 100644 --- a/chromium/components/update_client/update_client.h +++ b/chromium/components/update_client/update_client.h @@ -8,12 +8,12 @@ #include <stdint.h> #include <map> -#include <memory> #include <string> #include <vector> #include "base/callback_forward.h" #include "base/memory/ref_counted.h" +#include "base/optional.h" #include "base/version.h" #include "components/update_client/update_client_errors.h" @@ -136,6 +136,10 @@ namespace base { class FilePath; } +namespace crx_file { +enum class VerifierFormat; +} + namespace update_client { class Configurator; @@ -211,7 +215,6 @@ class CrxInstaller : public base::RefCountedThreadSafe<CrxInstaller> { // may be used in the update checks requests. using InstallerAttributes = std::map<std::string, std::string>; -// TODO(sorin): this structure will be refactored soon. struct CrxComponent { CrxComponent(); CrxComponent(const CrxComponent& other); @@ -245,6 +248,9 @@ struct CrxComponent { // which only returns secure download URLs in this case. bool requires_network_encryption; + // Specifies the strength of package validation required for the item. + crx_file::VerifierFormat crx_format_requirement; + // True if the component allows enabling or disabling updates by group policy. // This member should be set to |false| for data, non-binary components, such // as CRLSet, Supervised User Whitelists, STH Set, Origin Trials, and File @@ -275,7 +281,7 @@ using Callback = base::OnceCallback<void(Error error)>; class UpdateClient : public base::RefCounted<UpdateClient> { public: using CrxDataCallback = - base::OnceCallback<std::vector<std::unique_ptr<CrxComponent>>( + base::OnceCallback<std::vector<base::Optional<CrxComponent>>( const std::vector<std::string>& ids)>; // Defines an interface to observe the UpdateClient. It provides diff --git a/chromium/components/update_client/update_client_internal.h b/chromium/components/update_client/update_client_internal.h index 38b5c93d999..2b6158c1b2f 100644 --- a/chromium/components/update_client/update_client_internal.h +++ b/chromium/components/update_client/update_client_internal.h @@ -82,7 +82,7 @@ class UpdateClientImpl : public UpdateClient { std::set<scoped_refptr<Task>> tasks_; scoped_refptr<PingManager> ping_manager_; scoped_refptr<UpdateEngine> update_engine_; - base::ObserverList<Observer> observer_list_; + base::ObserverList<Observer>::Unchecked observer_list_; DISALLOW_COPY_AND_ASSIGN(UpdateClientImpl); }; diff --git a/chromium/components/update_client/update_client_unittest.cc b/chromium/components/update_client/update_client_unittest.cc index 4e9900571dd..dc41bbd13b6 100644 --- a/chromium/components/update_client/update_client_unittest.cc +++ b/chromium/components/update_client/update_client_unittest.cc @@ -15,14 +15,15 @@ #include "base/path_service.h" #include "base/run_loop.h" #include "base/stl_util.h" -#include "base/task_scheduler/post_task.h" -#include "base/task_scheduler/task_traits.h" +#include "base/task/post_task.h" +#include "base/task/task_traits.h" #include "base/test/scoped_path_override.h" #include "base/test/scoped_task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "base/values.h" #include "base/version.h" #include "build/build_config.h" +#include "components/crx_file/crx_verifier.h" #include "components/prefs/testing_pref_service.h" #include "components/update_client/component_unpacker.h" #include "components/update_client/crx_update_item.h" @@ -215,15 +216,15 @@ base::FilePath UpdateClientTest::TestFilePath(const char* file) { TEST_F(UpdateClientTest, OneCrxNoUpdate) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::unique_ptr<CrxComponent> crx = std::make_unique<CrxComponent>(); - crx->name = "test_jebg"; - crx->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx->version = base::Version("0.9"); - crx->installer = base::MakeRefCounted<TestInstaller>(); - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx)); + CrxComponent crx; + crx.name = "test_jebg"; + crx.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx.version = base::Version("0.9"); + crx.installer = base::MakeRefCounted<TestInstaller>(); + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + std::vector<base::Optional<CrxComponent>> component = {crx}; return component; } }; @@ -278,7 +279,7 @@ TEST_F(UpdateClientTest, OneCrxNoUpdate) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -326,24 +327,23 @@ TEST_F(UpdateClientTest, OneCrxNoUpdate) { TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::unique_ptr<CrxComponent> crx1 = std::make_unique<CrxComponent>(); - crx1->name = "test_jebg"; - crx1->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx1->version = base::Version("0.9"); - crx1->installer = base::MakeRefCounted<TestInstaller>(); - - std::unique_ptr<CrxComponent> crx2 = std::make_unique<CrxComponent>(); - crx2->name = "test_abag"; - crx2->pk_hash.assign(abag_hash, abag_hash + base::size(abag_hash)); - crx2->version = base::Version("2.2"); - crx2->installer = base::MakeRefCounted<TestInstaller>(); - - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx1)); - component.push_back(std::move(crx2)); - return component; + CrxComponent crx1; + crx1.name = "test_jebg"; + crx1.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx1.version = base::Version("0.9"); + crx1.installer = base::MakeRefCounted<TestInstaller>(); + crx1.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + + CrxComponent crx2; + crx2.name = "test_abag"; + crx2.pk_hash.assign(abag_hash, abag_hash + base::size(abag_hash)); + crx2.version = base::Version("2.2"); + crx2.installer = base::MakeRefCounted<TestInstaller>(); + crx2.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + + return {crx1, crx2}; } }; @@ -443,7 +443,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -466,12 +466,10 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { Result result; result.error = 0; result.response = path; - result.downloaded_bytes = 1843; - result.total_bytes = 1843; base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, - base::Unretained(this), result)); + base::Unretained(this))); base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, @@ -545,24 +543,23 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { TEST_F(UpdateClientTest, TwoCrxUpdateFirstServerIgnoresSecond) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::unique_ptr<CrxComponent> crx1 = std::make_unique<CrxComponent>(); - crx1->name = "test_jebg"; - crx1->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx1->version = base::Version("0.9"); - crx1->installer = base::MakeRefCounted<TestInstaller>(); - - std::unique_ptr<CrxComponent> crx2 = std::make_unique<CrxComponent>(); - crx2->name = "test_abag"; - crx2->pk_hash.assign(abag_hash, abag_hash + base::size(abag_hash)); - crx2->version = base::Version("2.2"); - crx2->installer = base::MakeRefCounted<TestInstaller>(); - - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx1)); - component.push_back(std::move(crx2)); - return component; + CrxComponent crx1; + crx1.name = "test_jebg"; + crx1.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx1.version = base::Version("0.9"); + crx1.installer = base::MakeRefCounted<TestInstaller>(); + crx1.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + + CrxComponent crx2; + crx2.name = "test_abag"; + crx2.pk_hash.assign(abag_hash, abag_hash + base::size(abag_hash)); + crx2.version = base::Version("2.2"); + crx2.installer = base::MakeRefCounted<TestInstaller>(); + crx2.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + + return {crx1, crx2}; } }; @@ -646,7 +643,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateFirstServerIgnoresSecond) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -669,12 +666,10 @@ TEST_F(UpdateClientTest, TwoCrxUpdateFirstServerIgnoresSecond) { Result result; result.error = 0; result.response = path; - result.downloaded_bytes = 1843; - result.total_bytes = 1843; base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, - base::Unretained(this), result)); + base::Unretained(this))); base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, @@ -734,7 +729,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateFirstServerIgnoresSecond) { .Times(1) .WillOnce(Invoke([&update_client](Events event, const std::string& id) { CrxUpdateItem item; - update_client->GetCrxUpdateState(id, &item); + EXPECT_TRUE(update_client->GetCrxUpdateState(id, &item)); EXPECT_EQ(ComponentState::kUpdateError, item.state); EXPECT_EQ(5, static_cast<int>(item.error_category)); EXPECT_EQ(-10004, item.error_code); @@ -763,18 +758,15 @@ TEST_F(UpdateClientTest, TwoCrxUpdateFirstServerIgnoresSecond) { TEST_F(UpdateClientTest, TwoCrxUpdateNoCrxComponentData) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::unique_ptr<CrxComponent> crx = std::make_unique<CrxComponent>(); - crx->name = "test_jebg"; - crx->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx->version = base::Version("0.9"); - crx->installer = base::MakeRefCounted<TestInstaller>(); - - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx)); - component.push_back(std::move(nullptr)); - return component; + CrxComponent crx; + crx.name = "test_jebg"; + crx.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx.version = base::Version("0.9"); + crx.installer = base::MakeRefCounted<TestInstaller>(); + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + return {crx, base::nullopt}; } }; @@ -858,7 +850,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoCrxComponentData) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -882,15 +874,13 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoCrxComponentData) { result.error = 0; result.response = path; - result.downloaded_bytes = 1843; - result.total_bytes = 1843; } else { NOTREACHED(); } base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, - base::Unretained(this), result)); + base::Unretained(this))); base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, @@ -962,12 +952,9 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoCrxComponentData) { TEST_F(UpdateClientTest, TwoCrxUpdateNoCrxComponentDataAtAll) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(nullptr)); - component.push_back(std::move(nullptr)); - return component; + return {base::nullopt, base::nullopt}; } }; @@ -1001,7 +988,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoCrxComponentDataAtAll) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -1057,24 +1044,23 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoCrxComponentDataAtAll) { TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::unique_ptr<CrxComponent> crx1 = std::make_unique<CrxComponent>(); - crx1->name = "test_jebg"; - crx1->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx1->version = base::Version("0.9"); - crx1->installer = base::MakeRefCounted<TestInstaller>(); - - std::unique_ptr<CrxComponent> crx2 = std::make_unique<CrxComponent>(); - crx2->name = "test_ihfo"; - crx2->pk_hash.assign(ihfo_hash, ihfo_hash + base::size(ihfo_hash)); - crx2->version = base::Version("0.8"); - crx2->installer = base::MakeRefCounted<TestInstaller>(); - - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx1)); - component.push_back(std::move(crx2)); - return component; + CrxComponent crx1; + crx1.name = "test_jebg"; + crx1.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx1.version = base::Version("0.9"); + crx1.installer = base::MakeRefCounted<TestInstaller>(); + crx1.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + + CrxComponent crx2; + crx2.name = "test_ihfo"; + crx2.pk_hash.assign(ihfo_hash, ihfo_hash + base::size(ihfo_hash)); + crx2.version = base::Version("0.8"); + crx2.installer = base::MakeRefCounted<TestInstaller>(); + crx2.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + + return {crx1, crx2}; } }; @@ -1191,7 +1177,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -1212,8 +1198,6 @@ TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { // The result must not include a file path in the case of errors. result.error = -118; - result.downloaded_bytes = 0; - result.total_bytes = 0; } else if (url.path() == "/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx") { download_metrics.url = url; @@ -1228,15 +1212,13 @@ TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { result.error = 0; result.response = path; - result.downloaded_bytes = 53638; - result.total_bytes = 53638; } else { NOTREACHED(); } base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, - base::Unretained(this), result)); + base::Unretained(this))); base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, @@ -1287,7 +1269,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { .Times(1) .WillOnce(Invoke([&update_client](Events event, const std::string& id) { CrxUpdateItem item; - update_client->GetCrxUpdateState(id, &item); + EXPECT_TRUE(update_client->GetCrxUpdateState(id, &item)); EXPECT_EQ(ComponentState::kUpdateError, item.state); EXPECT_EQ(1, static_cast<int>(item.error_category)); EXPECT_EQ(-118, item.error_code); @@ -1329,7 +1311,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { TEST_F(UpdateClientTest, OneCrxDiffUpdate) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { static int num_calls = 0; @@ -1339,21 +1321,20 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdate) { ++num_calls; - std::unique_ptr<CrxComponent> crx = std::make_unique<CrxComponent>(); - crx->name = "test_ihfo"; - crx->pk_hash.assign(ihfo_hash, ihfo_hash + base::size(ihfo_hash)); - crx->installer = installer; + CrxComponent crx; + crx.name = "test_ihfo"; + crx.pk_hash.assign(ihfo_hash, ihfo_hash + base::size(ihfo_hash)); + crx.installer = installer; + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; if (num_calls == 1) { - crx->version = base::Version("0.8"); + crx.version = base::Version("0.8"); } else if (num_calls == 2) { - crx->version = base::Version("1.0"); + crx.version = base::Version("1.0"); } else { NOTREACHED(); } - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx)); - return component; + return {crx}; } }; @@ -1486,7 +1467,7 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdate) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -1510,8 +1491,6 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdate) { result.error = 0; result.response = path; - result.downloaded_bytes = 53638; - result.total_bytes = 53638; } else if (url.path() == "/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx") { download_metrics.url = url; @@ -1526,15 +1505,13 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdate) { result.error = 0; result.response = path; - result.downloaded_bytes = 2105; - result.total_bytes = 2105; } else { NOTREACHED(); } base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, - base::Unretained(this), result)); + base::Unretained(this))); base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, @@ -1668,7 +1645,7 @@ TEST_F(UpdateClientTest, OneCrxInstallError) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { scoped_refptr<MockInstaller> installer = base::MakeRefCounted<MockInstaller>(); @@ -1678,15 +1655,14 @@ TEST_F(UpdateClientTest, OneCrxInstallError) { EXPECT_CALL(*installer, GetInstalledFile(_, _)).Times(0); EXPECT_CALL(*installer, Uninstall()).Times(0); - std::unique_ptr<CrxComponent> crx = std::make_unique<CrxComponent>(); - crx->name = "test_jebg"; - crx->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx->version = base::Version("0.9"); - crx->installer = installer; + CrxComponent crx; + crx.name = "test_jebg"; + crx.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx.version = base::Version("0.9"); + crx.installer = installer; + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx)); - return component; + return {crx}; } }; @@ -1764,7 +1740,7 @@ TEST_F(UpdateClientTest, OneCrxInstallError) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -1787,12 +1763,10 @@ TEST_F(UpdateClientTest, OneCrxInstallError) { Result result; result.error = 0; result.response = path; - result.downloaded_bytes = 1843; - result.total_bytes = 1843; base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, - base::Unretained(this), result)); + base::Unretained(this))); base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, @@ -1856,7 +1830,7 @@ TEST_F(UpdateClientTest, OneCrxInstallError) { TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { static int num_calls = 0; @@ -1866,21 +1840,20 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { ++num_calls; - std::unique_ptr<CrxComponent> crx = std::make_unique<CrxComponent>(); - crx->name = "test_ihfo"; - crx->pk_hash.assign(ihfo_hash, ihfo_hash + base::size(ihfo_hash)); - crx->installer = installer; + CrxComponent crx; + crx.name = "test_ihfo"; + crx.pk_hash.assign(ihfo_hash, ihfo_hash + base::size(ihfo_hash)); + crx.installer = installer; + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; if (num_calls == 1) { - crx->version = base::Version("0.8"); + crx.version = base::Version("0.8"); } else if (num_calls == 2) { - crx->version = base::Version("1.0"); + crx.version = base::Version("1.0"); } else { NOTREACHED(); } - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx)); - return component; + return {crx}; } }; @@ -2015,7 +1988,7 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -2039,8 +2012,6 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { result.error = 0; result.response = path; - result.downloaded_bytes = 53638; - result.total_bytes = 53638; } else if (url.path() == "/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx") { // A download error is injected on this execution path. @@ -2053,8 +2024,6 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { // The response must not include a file path in the case of errors. result.error = -1; - result.downloaded_bytes = 0; - result.total_bytes = 2105; } else if (url.path() == "/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx") { download_metrics.url = url; @@ -2069,13 +2038,11 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { result.error = 0; result.response = path; - result.downloaded_bytes = 53855; - result.total_bytes = 53855; } base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, - base::Unretained(this), result)); + base::Unretained(this))); base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, @@ -2173,16 +2140,15 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { TEST_F(UpdateClientTest, OneCrxNoUpdateQueuedCall) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::unique_ptr<CrxComponent> crx = std::make_unique<CrxComponent>(); - crx->name = "test_jebg"; - crx->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx->version = base::Version("0.9"); - crx->installer = base::MakeRefCounted<TestInstaller>(); - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx)); - return component; + CrxComponent crx; + crx.name = "test_jebg"; + crx.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx.version = base::Version("0.9"); + crx.installer = base::MakeRefCounted<TestInstaller>(); + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + return {crx}; } }; @@ -2240,7 +2206,7 @@ TEST_F(UpdateClientTest, OneCrxNoUpdateQueuedCall) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -2294,17 +2260,15 @@ TEST_F(UpdateClientTest, OneCrxNoUpdateQueuedCall) { TEST_F(UpdateClientTest, OneCrxInstall) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::unique_ptr<CrxComponent> crx = std::make_unique<CrxComponent>(); - crx->name = "test_jebg"; - crx->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx->version = base::Version("0.0"); - crx->installer = base::MakeRefCounted<TestInstaller>(); - - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx)); - return component; + CrxComponent crx; + crx.name = "test_jebg"; + crx.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx.version = base::Version("0.0"); + crx.installer = base::MakeRefCounted<TestInstaller>(); + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + return {crx}; } }; @@ -2388,7 +2352,7 @@ TEST_F(UpdateClientTest, OneCrxInstall) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -2412,15 +2376,13 @@ TEST_F(UpdateClientTest, OneCrxInstall) { result.error = 0; result.response = path; - result.downloaded_bytes = 1843; - result.total_bytes = 1843; } else { NOTREACHED(); } base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, - base::Unretained(this), result)); + base::Unretained(this))); base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, @@ -2482,11 +2444,9 @@ TEST_F(UpdateClientTest, OneCrxInstall) { TEST_F(UpdateClientTest, OneCrxInstallNoCrxComponentData) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(nullptr); - return component; + return {base::nullopt}; } }; @@ -2520,7 +2480,7 @@ TEST_F(UpdateClientTest, OneCrxInstallNoCrxComponentData) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -2550,7 +2510,20 @@ TEST_F(UpdateClientTest, OneCrxInstallNoCrxComponentData) { InSequence seq; EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_ERROR, "jebgalgnebhfojomionfpkfelancnnkf")) - .Times(1); + .Times(1) + .WillOnce(Invoke([&update_client](Events event, const std::string& id) { + // Tests that the state of the component when the CrxComponent data + // is not provided. In this case, the optional |item.component| instance + // is not present. + CrxUpdateItem item; + EXPECT_TRUE(update_client->GetCrxUpdateState(id, &item)); + EXPECT_EQ(ComponentState::kUpdateError, item.state); + EXPECT_STREQ("jebgalgnebhfojomionfpkfelancnnkf", item.id.c_str()); + EXPECT_FALSE(item.component); + EXPECT_EQ(ErrorCategory::kService, item.error_category); + EXPECT_EQ(static_cast<int>(Error::CRX_NOT_FOUND), item.error_code); + EXPECT_EQ(0, item.extra_code1); + })); update_client->AddObserver(&observer); @@ -2568,16 +2541,15 @@ TEST_F(UpdateClientTest, OneCrxInstallNoCrxComponentData) { TEST_F(UpdateClientTest, ConcurrentInstallSameCRX) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::unique_ptr<CrxComponent> crx = std::make_unique<CrxComponent>(); - crx->name = "test_jebg"; - crx->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx->version = base::Version("0.0"); - crx->installer = base::MakeRefCounted<TestInstaller>(); - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx)); - return component; + CrxComponent crx; + crx.name = "test_jebg"; + crx.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx.version = base::Version("0.0"); + crx.installer = base::MakeRefCounted<TestInstaller>(); + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + return {crx}; } }; @@ -2641,7 +2613,7 @@ TEST_F(UpdateClientTest, ConcurrentInstallSameCRX) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -2695,7 +2667,7 @@ TEST_F(UpdateClientTest, ConcurrentInstallSameCRX) { TEST_F(UpdateClientTest, EmptyIdList) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { return {}; } @@ -2731,7 +2703,7 @@ TEST_F(UpdateClientTest, EmptyIdList) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -2792,7 +2764,7 @@ TEST_F(UpdateClientTest, SendUninstallPing) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return nullptr; } @@ -2834,16 +2806,15 @@ TEST_F(UpdateClientTest, SendUninstallPing) { TEST_F(UpdateClientTest, RetryAfter) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::unique_ptr<CrxComponent> crx = std::make_unique<CrxComponent>(); - crx->name = "test_jebg"; - crx->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx->version = base::Version("0.9"); - crx->installer = base::MakeRefCounted<TestInstaller>(); - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx)); - return component; + CrxComponent crx; + crx.name = "test_jebg"; + crx.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx.version = base::Version("0.9"); + crx.installer = base::MakeRefCounted<TestInstaller>(); + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + return {crx}; } }; @@ -2924,7 +2895,7 @@ TEST_F(UpdateClientTest, RetryAfter) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -3028,25 +2999,24 @@ TEST_F(UpdateClientTest, RetryAfter) { TEST_F(UpdateClientTest, TwoCrxUpdateOneUpdateDisabled) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::unique_ptr<CrxComponent> crx1 = std::make_unique<CrxComponent>(); - crx1->name = "test_jebg"; - crx1->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx1->version = base::Version("0.9"); - crx1->installer = base::MakeRefCounted<TestInstaller>(); - crx1->supports_group_policy_enable_component_updates = true; - - std::unique_ptr<CrxComponent> crx2 = std::make_unique<CrxComponent>(); - crx2->name = "test_ihfo"; - crx2->pk_hash.assign(ihfo_hash, ihfo_hash + base::size(ihfo_hash)); - crx2->version = base::Version("0.8"); - crx2->installer = base::MakeRefCounted<TestInstaller>(); - - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx1)); - component.push_back(std::move(crx2)); - return component; + CrxComponent crx1; + crx1.name = "test_jebg"; + crx1.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx1.version = base::Version("0.9"); + crx1.installer = base::MakeRefCounted<TestInstaller>(); + crx1.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + crx1.supports_group_policy_enable_component_updates = true; + + CrxComponent crx2; + crx2.name = "test_ihfo"; + crx2.pk_hash.assign(ihfo_hash, ihfo_hash + base::size(ihfo_hash)); + crx2.version = base::Version("0.8"); + crx2.installer = base::MakeRefCounted<TestInstaller>(); + crx2.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + + return {crx1, crx2}; } }; @@ -3167,7 +3137,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateOneUpdateDisabled) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -3191,15 +3161,13 @@ TEST_F(UpdateClientTest, TwoCrxUpdateOneUpdateDisabled) { result.error = 0; result.response = path; - result.downloaded_bytes = 53638; - result.total_bytes = 53638; } else { NOTREACHED(); } base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, - base::Unretained(this), result)); + base::Unretained(this))); base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, @@ -3286,16 +3254,15 @@ TEST_F(UpdateClientTest, TwoCrxUpdateOneUpdateDisabled) { TEST_F(UpdateClientTest, OneCrxUpdateCheckFails) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::unique_ptr<CrxComponent> crx = std::make_unique<CrxComponent>(); - crx->name = "test_jebg"; - crx->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx->version = base::Version("0.9"); - crx->installer = base::MakeRefCounted<TestInstaller>(); - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx)); - return component; + CrxComponent crx; + crx.name = "test_jebg"; + crx.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx.version = base::Version("0.9"); + crx.installer = base::MakeRefCounted<TestInstaller>(); + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + return {crx}; } }; @@ -3338,7 +3305,7 @@ TEST_F(UpdateClientTest, OneCrxUpdateCheckFails) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -3372,7 +3339,7 @@ TEST_F(UpdateClientTest, OneCrxUpdateCheckFails) { .Times(1) .WillOnce(Invoke([&update_client](Events event, const std::string& id) { CrxUpdateItem item; - update_client->GetCrxUpdateState(id, &item); + EXPECT_TRUE(update_client->GetCrxUpdateState(id, &item)); EXPECT_EQ(ComponentState::kUpdateError, item.state); EXPECT_EQ(5, static_cast<int>(item.error_category)); EXPECT_EQ(-1, item.error_code); @@ -3396,38 +3363,45 @@ TEST_F(UpdateClientTest, OneCrxUpdateCheckFails) { TEST_F(UpdateClientTest, OneCrxErrorUnknownApp) { class DataCallbackMock { public: - static std::vector<std::unique_ptr<CrxComponent>> Callback( + static std::vector<base::Optional<CrxComponent>> Callback( const std::vector<std::string>& ids) { - std::vector<std::unique_ptr<CrxComponent>> component; - - std::unique_ptr<CrxComponent> crx = std::make_unique<CrxComponent>(); - crx->name = "test_jebg"; - crx->pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); - crx->version = base::Version("0.9"); - crx->installer = base::MakeRefCounted<TestInstaller>(); - component.push_back(std::move(crx)); - - crx = std::make_unique<CrxComponent>(); - crx->name = "test_abag"; - crx->pk_hash.assign(abag_hash, abag_hash + base::size(abag_hash)); - crx->version = base::Version("0.1"); - crx->installer = base::MakeRefCounted<TestInstaller>(); - component.push_back(std::move(crx)); - - crx = std::make_unique<CrxComponent>(); - crx->name = "test_ihfo"; - crx->pk_hash.assign(ihfo_hash, ihfo_hash + base::size(ihfo_hash)); - crx->version = base::Version("0.2"); - crx->installer = base::MakeRefCounted<TestInstaller>(); - component.push_back(std::move(crx)); - - crx = std::make_unique<CrxComponent>(); - crx->name = "test_gjpm"; - crx->pk_hash.assign(gjpm_hash, gjpm_hash + base::size(gjpm_hash)); - crx->version = base::Version("0.3"); - crx->installer = base::MakeRefCounted<TestInstaller>(); - component.push_back(std::move(crx)); - + std::vector<base::Optional<CrxComponent>> component; + { + CrxComponent crx; + crx.name = "test_jebg"; + crx.pk_hash.assign(jebg_hash, jebg_hash + base::size(jebg_hash)); + crx.version = base::Version("0.9"); + crx.installer = base::MakeRefCounted<TestInstaller>(); + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + component.push_back(crx); + } + { + CrxComponent crx; + crx.name = "test_abag"; + crx.pk_hash.assign(abag_hash, abag_hash + base::size(abag_hash)); + crx.version = base::Version("0.1"); + crx.installer = base::MakeRefCounted<TestInstaller>(); + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + component.push_back(crx); + } + { + CrxComponent crx; + crx.name = "test_ihfo"; + crx.pk_hash.assign(ihfo_hash, ihfo_hash + base::size(ihfo_hash)); + crx.version = base::Version("0.2"); + crx.installer = base::MakeRefCounted<TestInstaller>(); + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + component.push_back(crx); + } + { + CrxComponent crx; + crx.name = "test_gjpm"; + crx.pk_hash.assign(gjpm_hash, gjpm_hash + base::size(gjpm_hash)); + crx.version = base::Version("0.3"); + crx.installer = base::MakeRefCounted<TestInstaller>(); + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + component.push_back(crx); + } return component; } }; @@ -3485,7 +3459,7 @@ TEST_F(UpdateClientTest, OneCrxErrorUnknownApp) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -3520,7 +3494,7 @@ TEST_F(UpdateClientTest, OneCrxErrorUnknownApp) { .Times(1) .WillOnce(Invoke([&update_client](Events event, const std::string& id) { CrxUpdateItem item; - update_client->GetCrxUpdateState(id, &item); + EXPECT_TRUE(update_client->GetCrxUpdateState(id, &item)); EXPECT_EQ(ComponentState::kUpdateError, item.state); EXPECT_EQ(5, static_cast<int>(item.error_category)); EXPECT_EQ(-10006, item.error_code); // UNKNOWN_APPPLICATION. @@ -3537,7 +3511,7 @@ TEST_F(UpdateClientTest, OneCrxErrorUnknownApp) { .Times(1) .WillOnce(Invoke([&update_client](Events event, const std::string& id) { CrxUpdateItem item; - update_client->GetCrxUpdateState(id, &item); + EXPECT_TRUE(update_client->GetCrxUpdateState(id, &item)); EXPECT_EQ(ComponentState::kUpdateError, item.state); EXPECT_EQ(5, static_cast<int>(item.error_category)); EXPECT_EQ(-10007, item.error_code); // RESTRICTED_APPLICATION. @@ -3554,7 +3528,7 @@ TEST_F(UpdateClientTest, OneCrxErrorUnknownApp) { .Times(1) .WillOnce(Invoke([&update_client](Events event, const std::string& id) { CrxUpdateItem item; - update_client->GetCrxUpdateState(id, &item); + EXPECT_TRUE(update_client->GetCrxUpdateState(id, &item)); EXPECT_EQ(ComponentState::kUpdateError, item.state); EXPECT_EQ(5, static_cast<int>(item.error_category)); EXPECT_EQ(-10008, item.error_code); // INVALID_APPID. @@ -3571,7 +3545,7 @@ TEST_F(UpdateClientTest, OneCrxErrorUnknownApp) { .Times(1) .WillOnce(Invoke([&update_client](Events event, const std::string& id) { CrxUpdateItem item; - update_client->GetCrxUpdateState(id, &item); + EXPECT_TRUE(update_client->GetCrxUpdateState(id, &item)); EXPECT_EQ(ComponentState::kUpdateError, item.state); EXPECT_EQ(5, static_cast<int>(item.error_category)); EXPECT_EQ(-10004, item.error_code); // UPDATE_RESPONSE_NOT_FOUND. @@ -3669,7 +3643,7 @@ TEST_F(UpdateClientTest, ActionRun_Install) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -3693,8 +3667,6 @@ TEST_F(UpdateClientTest, ActionRun_Install) { result.error = 0; result.response = path; - result.downloaded_bytes = 1843; - result.total_bytes = 1843; } else { NOTREACHED(); } @@ -3742,14 +3714,13 @@ TEST_F(UpdateClientTest, ActionRun_Install) { update_client->Install( std::string("gjpmebpgbhcamgdgjcmnjfhggjpgcimm"), base::BindOnce([](const std::vector<std::string>& ids) { - auto crx = std::make_unique<CrxComponent>(); - crx->name = "test_niea"; - crx->pk_hash.assign(gjpm_hash, gjpm_hash + base::size(gjpm_hash)); - crx->version = base::Version("0.0"); - crx->installer = base::MakeRefCounted<VersionedTestInstaller>(); - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx)); - return component; + CrxComponent crx; + crx.name = "test_niea"; + crx.pk_hash.assign(gjpm_hash, gjpm_hash + base::size(gjpm_hash)); + crx.version = base::Version("0.0"); + crx.installer = base::MakeRefCounted<VersionedTestInstaller>(); + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + return std::vector<base::Optional<CrxComponent>>{crx}; }), base::BindOnce( [](base::OnceClosure quit_closure, Error error) { @@ -3816,7 +3787,7 @@ TEST_F(UpdateClientTest, ActionRun_NoUpdate) { public: static std::unique_ptr<CrxDownloader> Create( bool is_background_download, - scoped_refptr<net::URLRequestContextGetter> context_getter) { + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { return std::make_unique<MockCrxDownloader>(); } @@ -3853,7 +3824,8 @@ TEST_F(UpdateClientTest, ActionRun_NoUpdate) { auto component_unpacker = base::MakeRefCounted<ComponentUnpacker>( std::vector<uint8_t>(std::begin(gjpm_hash), std::end(gjpm_hash)), TestFilePath("runaction_test_win.crx3"), nullptr, - config->CreateServiceManagerConnector()); + config->CreateServiceManagerConnector(), + crx_file::VerifierFormat::CRX2_OR_CRX3); component_unpacker->Unpack(base::BindOnce( [](base::FilePath* unpack_path, base::OnceClosure quit_closure, @@ -3890,15 +3862,14 @@ TEST_F(UpdateClientTest, ActionRun_NoUpdate) { base::BindOnce( [](const base::FilePath& unpack_path, const std::vector<std::string>& ids) { - auto crx = std::make_unique<CrxComponent>(); - crx->name = "test_niea"; - crx->pk_hash.assign(gjpm_hash, gjpm_hash + base::size(gjpm_hash)); - crx->version = base::Version("1.0"); - crx->installer = + CrxComponent crx; + crx.name = "test_niea"; + crx.pk_hash.assign(gjpm_hash, gjpm_hash + base::size(gjpm_hash)); + crx.version = base::Version("1.0"); + crx.installer = base::MakeRefCounted<ReadOnlyTestInstaller>(unpack_path); - std::vector<std::unique_ptr<CrxComponent>> component; - component.push_back(std::move(crx)); - return component; + crx.crx_format_requirement = crx_file::VerifierFormat::CRX2_OR_CRX3; + return std::vector<base::Optional<CrxComponent>>{crx}; }, unpack_path), false, diff --git a/chromium/components/update_client/update_engine.cc b/chromium/components/update_client/update_engine.cc index a778b7d9628..0e3dd3ff8b8 100644 --- a/chromium/components/update_client/update_engine.cc +++ b/chromium/components/update_client/update_engine.cc @@ -11,6 +11,7 @@ #include "base/guid.h" #include "base/location.h" #include "base/logging.h" +#include "base/optional.h" #include "base/stl_util.h" #include "base/threading/thread_task_runner_handle.h" #include "components/prefs/pref_service.h" @@ -103,7 +104,7 @@ void UpdateEngine::Update(bool is_foreground, // Calls out to get the corresponding CrxComponent data for the CRXs in this // update context. - std::vector<std::unique_ptr<CrxComponent>> crx_components = + const auto crx_components = std::move(update_context->crx_data_callback).Run(update_context->ids); DCHECK_EQ(update_context->ids.size(), crx_components.size()); @@ -112,12 +113,12 @@ void UpdateEngine::Update(bool is_foreground, DCHECK(update_context->components[id]->state() == ComponentState::kNew); - auto& crx_component = crx_components[i]; + const auto crx_component = crx_components[i]; if (crx_component) { // This component can be checked for updates. DCHECK_EQ(id, GetCrxComponentID(*crx_component)); auto& component = update_context->components[id]; - component->set_crx_component(std::move(crx_component)); + component->set_crx_component(*crx_component); component->set_previous_version(component->crx_component()->version); component->set_previous_fp(component->crx_component()->fingerprint); update_context->components_to_check_for_updates.push_back(id); @@ -379,7 +380,7 @@ bool UpdateEngine::GetUpdateState(const std::string& id, for (const auto& context : update_contexts_) { const auto& components = context.second->components; const auto it = components.find(id); - if (it != components.end() && it->second->crx_component()) { + if (it != components.end()) { *update_item = it->second->GetCrxUpdateItem(); return true; } diff --git a/chromium/components/update_client/url_fetcher_downloader.cc b/chromium/components/update_client/url_fetcher_downloader.cc index d181daa0202..6742c8105fb 100644 --- a/chromium/components/update_client/url_fetcher_downloader.cc +++ b/chromium/components/update_client/url_fetcher_downloader.cc @@ -12,52 +12,32 @@ #include "base/location.h" #include "base/logging.h" #include "base/sequenced_task_runner.h" -#include "base/task_scheduler/post_task.h" -#include "base/task_scheduler/task_traits.h" +#include "base/task/post_task.h" +#include "base/task/task_traits.h" #include "components/data_use_measurement/core/data_use_user_data.h" #include "components/update_client/utils.h" #include "net/base/load_flags.h" #include "net/traffic_annotation/network_traffic_annotation.h" -#include "net/url_request/url_fetcher.h" -#include "net/url_request/url_request_context_getter.h" +#include "services/network/public/cpp/resource_response.h" +#include "services/network/public/cpp/shared_url_loader_factory.h" +#include "services/network/public/cpp/simple_url_loader.h" #include "url/gurl.h" namespace { constexpr base::TaskTraits kTaskTraits = { - base::MayBlock(), base::TaskPriority::BACKGROUND, + base::MayBlock(), base::TaskPriority::BEST_EFFORT, base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}; } // namespace namespace update_client { -UrlFetcherDownloader::URLFetcherDelegate::URLFetcherDelegate( - UrlFetcherDownloader* downloader) - : downloader_(downloader) {} - -UrlFetcherDownloader::URLFetcherDelegate::~URLFetcherDelegate() = default; - -void UrlFetcherDownloader::URLFetcherDelegate::OnURLFetchComplete( - const net::URLFetcher* source) { - downloader_->OnURLFetchComplete(source); -} - -void UrlFetcherDownloader::URLFetcherDelegate::OnURLFetchDownloadProgress( - const net::URLFetcher* source, - int64_t current, - int64_t total, - int64_t current_network_bytes) { - downloader_->OnURLFetchDownloadProgress(source, current, total, - current_network_bytes); -} - UrlFetcherDownloader::UrlFetcherDownloader( std::unique_ptr<CrxDownloader> successor, - scoped_refptr<net::URLRequestContextGetter> context_getter) + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) : CrxDownloader(std::move(successor)), - delegate_(std::make_unique<URLFetcherDelegate>(this)), - context_getter_(context_getter) {} + url_loader_factory_(std::move(url_loader_factory)) {} UrlFetcherDownloader::~UrlFetcherDownloader() { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); @@ -114,15 +94,13 @@ void UrlFetcherDownloader::StartURLFetch(const GURL& url) { if (download_dir_.empty()) { Result result; result.error = -1; - result.downloaded_bytes = downloaded_bytes_; - result.total_bytes = total_bytes_; DownloadMetrics download_metrics; download_metrics.url = url; download_metrics.downloader = DownloadMetrics::kUrlFetcher; download_metrics.error = -1; - download_metrics.downloaded_bytes = downloaded_bytes_; - download_metrics.total_bytes = total_bytes_; + download_metrics.downloaded_bytes = -1; + download_metrics.total_bytes = -1; download_metrics.download_time_ms = 0; main_task_runner()->PostTask( @@ -134,27 +112,37 @@ void UrlFetcherDownloader::StartURLFetch(const GURL& url) { const base::FilePath response = download_dir_.AppendASCII(url.ExtractFileName()); - - url_fetcher_ = net::URLFetcher::Create(0, url, net::URLFetcher::GET, - delegate_.get(), traffic_annotation); - url_fetcher_->SetRequestContext(context_getter_.get()); - url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | - net::LOAD_DO_NOT_SAVE_COOKIES | - net::LOAD_DISABLE_CACHE); - url_fetcher_->SetAutomaticallyRetryOn5xx(false); - url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3); - url_fetcher_->SaveResponseToFileAtPath( - response, base::CreateSequencedTaskRunnerWithTraits(kTaskTraits)); - data_use_measurement::DataUseUserData::AttachToFetcher( - url_fetcher_.get(), data_use_measurement::DataUseUserData::UPDATE_CLIENT); + auto resource_request = std::make_unique<network::ResourceRequest>(); + resource_request->url = url; + resource_request->load_flags = net::LOAD_DO_NOT_SEND_COOKIES | + net::LOAD_DO_NOT_SAVE_COOKIES | + net::LOAD_DISABLE_CACHE; + url_loader_ = network::SimpleURLLoader::Create(std::move(resource_request), + traffic_annotation); + const int kMaxRetries = 3; + url_loader_->SetRetryOptions( + kMaxRetries, + network::SimpleURLLoader::RetryMode::RETRY_ON_NETWORK_CHANGE); + + url_loader_->SetOnResponseStartedCallback(base::BindOnce( + &UrlFetcherDownloader::OnResponseStarted, base::Unretained(this))); + + // For the end-to-end system it is important that the client reports the + // number of bytes it loaded from the server even in the case that the + // overall network transaction failed. + url_loader_->SetAllowPartialResults(true); VLOG(1) << "Starting background download: " << url.spec(); - url_fetcher_->Start(); + url_loader_->DownloadToFile( + url_loader_factory_.get(), + base::BindOnce(&UrlFetcherDownloader::OnURLLoadComplete, + base::Unretained(this)), + response); download_start_time_ = base::TimeTicks::Now(); } -void UrlFetcherDownloader::OnURLFetchComplete(const net::URLFetcher* source) { +void UrlFetcherDownloader::OnURLLoadComplete(base::FilePath file_path) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); const base::TimeTicks download_end_time(base::TimeTicks::Now()); @@ -166,28 +154,44 @@ void UrlFetcherDownloader::OnURLFetchComplete(const net::URLFetcher* source) { // Consider a 5xx response from the server as an indication to terminate // the request and avoid overloading the server in this case. // is not accepting requests for the moment. - const int fetch_error(GetFetchError(*url_fetcher_)); + int response_code = -1; + if (url_loader_->ResponseInfo() && url_loader_->ResponseInfo()->headers) { + response_code = url_loader_->ResponseInfo()->headers->response_code(); + } + + int fetch_error = -1; + if (!file_path.empty() && response_code == 200) { + fetch_error = 0; + } else if (response_code != -1) { + fetch_error = response_code; + } else { + fetch_error = url_loader_->NetError(); + } + const bool is_handled = fetch_error == 0 || IsHttpServerError(fetch_error); Result result; result.error = fetch_error; if (!fetch_error) { - source->GetResponseAsFilePath(true, &result.response); + result.response = file_path; } - result.downloaded_bytes = downloaded_bytes_; - result.total_bytes = total_bytes_; DownloadMetrics download_metrics; download_metrics.url = url(); download_metrics.downloader = DownloadMetrics::kUrlFetcher; download_metrics.error = fetch_error; - download_metrics.downloaded_bytes = downloaded_bytes_; + // Tests expected -1, in case of failures and no content is available. + download_metrics.downloaded_bytes = + fetch_error && !url_loader_->GetContentSize() + ? -1 + : url_loader_->GetContentSize(); download_metrics.total_bytes = total_bytes_; download_metrics.download_time_ms = download_time.InMilliseconds(); - VLOG(1) << "Downloaded " << downloaded_bytes_ << " bytes in " + VLOG(1) << "Downloaded " << url_loader_->GetContentSize() << " bytes in " << download_time.InMilliseconds() << "ms from " - << source->GetURL().spec() << " to " << result.response.value(); + << url_loader_->GetFinalURL().spec() << " to " + << result.response.value(); // Delete the download directory in the error cases. if (fetch_error && !download_dir_.empty()) @@ -201,21 +205,16 @@ void UrlFetcherDownloader::OnURLFetchComplete(const net::URLFetcher* source) { download_metrics)); } -void UrlFetcherDownloader::OnURLFetchDownloadProgress( - const net::URLFetcher* source, - int64_t current, - int64_t total, - int64_t current_network_bytes) { +// This callback is used to indicate that a download has been started. +void UrlFetcherDownloader::OnResponseStarted( + const GURL& final_url, + const network::ResourceResponseHead& response_head) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); - downloaded_bytes_ = current; - total_bytes_ = total; - - Result result; - result.downloaded_bytes = downloaded_bytes_; - result.total_bytes = total_bytes_; + if (response_head.content_length != -1) + total_bytes_ = response_head.content_length; - OnDownloadProgress(result); + OnDownloadProgress(); } } // namespace update_client diff --git a/chromium/components/update_client/url_fetcher_downloader.h b/chromium/components/update_client/url_fetcher_downloader.h index 442cbf2c339..03fee0ab672 100644 --- a/chromium/components/update_client/url_fetcher_downloader.h +++ b/chromium/components/update_client/url_fetcher_downloader.h @@ -15,65 +15,42 @@ #include "base/threading/thread_checker.h" #include "base/time/time.h" #include "components/update_client/crx_downloader.h" -#include "net/url_request/url_fetcher_delegate.h" -namespace net { -class URLFetcher; -class URLRequestContextGetter; -} +namespace network { +class SharedURLLoaderFactory; +class SimpleURLLoader; +struct ResourceResponseHead; +} // namespace network namespace update_client { -// Implements a CRX downloader in top of the URLFetcher. +// Implements a CRX downloader in top of the SimpleURLLoader. class UrlFetcherDownloader : public CrxDownloader { public: UrlFetcherDownloader( std::unique_ptr<CrxDownloader> successor, - scoped_refptr<net::URLRequestContextGetter> context_getter); + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory); ~UrlFetcherDownloader() override; private: - class URLFetcherDelegate : public net::URLFetcherDelegate { - public: - explicit URLFetcherDelegate(UrlFetcherDownloader* downloader); - ~URLFetcherDelegate() override; - - private: - // Overrides for URLFetcherDelegate. - void OnURLFetchComplete(const net::URLFetcher* source) override; - void OnURLFetchDownloadProgress(const net::URLFetcher* source, - int64_t current, - int64_t total, - int64_t current_network_bytes) override; - // Not owned by this class. - UrlFetcherDownloader* downloader_ = nullptr; - DISALLOW_COPY_AND_ASSIGN(URLFetcherDelegate); - }; - // Overrides for CrxDownloader. void DoStartDownload(const GURL& url) override; void CreateDownloadDir(); void StartURLFetch(const GURL& url); - void OnURLFetchComplete(const net::URLFetcher* source); - void OnURLFetchDownloadProgress(const net::URLFetcher* source, - int64_t current, - int64_t total, - int64_t current_network_bytes); - + void OnURLLoadComplete(base::FilePath file_path); + void OnResponseStarted(const GURL& final_url, + const network::ResourceResponseHead& response_head); THREAD_CHECKER(thread_checker_); - std::unique_ptr<URLFetcherDelegate> delegate_; - - std::unique_ptr<net::URLFetcher> url_fetcher_; - scoped_refptr<net::URLRequestContextGetter> context_getter_; + scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_; + std::unique_ptr<network::SimpleURLLoader> url_loader_; // Contains a temporary download directory for the downloaded file. base::FilePath download_dir_; base::TimeTicks download_start_time_; - int64_t downloaded_bytes_ = -1; int64_t total_bytes_ = -1; DISALLOW_COPY_AND_ASSIGN(UrlFetcherDownloader); diff --git a/chromium/components/update_client/utils.cc b/chromium/components/update_client/utils.cc index 85003a2808e..131288f3ce7 100644 --- a/chromium/components/update_client/utils.cc +++ b/chromium/components/update_client/utils.cc @@ -17,6 +17,7 @@ #include "base/files/file_util.h" #include "base/files/memory_mapped_file.h" #include "base/json/json_file_value_serializer.h" +#include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_piece.h" #include "base/strings/string_util.h" @@ -31,8 +32,6 @@ #include "crypto/sha2.h" #include "net/base/load_flags.h" #include "net/traffic_annotation/network_traffic_annotation.h" -#include "net/url_request/url_fetcher.h" -#include "net/url_request/url_request_status.h" #include "services/network/public/cpp/resource_request.h" #include "services/network/public/cpp/simple_url_loader.h" #include "url/gurl.h" @@ -95,38 +94,6 @@ std::unique_ptr<network::SimpleURLLoader> SendProtocolRequest( return simple_loader; } -bool FetchSuccess(const net::URLFetcher& fetcher) { - return GetFetchError(fetcher) == 0; -} - -int GetFetchError(const net::URLFetcher& fetcher) { - const net::URLRequestStatus::Status status(fetcher.GetStatus().status()); - switch (status) { - case net::URLRequestStatus::IO_PENDING: - case net::URLRequestStatus::CANCELED: - // Network status is a small positive number. - return status; - - case net::URLRequestStatus::SUCCESS: { - // Response codes are positive numbers, greater than 100. - const int response_code(fetcher.GetResponseCode()); - if (response_code == 200) - return 0; - else - return response_code ? response_code : -1; - } - - case net::URLRequestStatus::FAILED: { - // Network errors are small negative numbers. - const int error = fetcher.GetStatus().error(); - return error ? error : -1; - } - - default: - return -1; - } -} - bool HasDiffUpdate(const Component& component) { return !component.crx_diffurls().empty(); } @@ -224,10 +191,8 @@ bool IsValidInstallerAttribute(const InstallerAttribute& attr) { void RemoveUnsecureUrls(std::vector<GURL>* urls) { DCHECK(urls); - urls->erase(std::remove_if( - urls->begin(), urls->end(), - [](const GURL& url) { return !url.SchemeIsCryptographic(); }), - urls->end()); + base::EraseIf(*urls, + [](const GURL& url) { return !url.SchemeIsCryptographic(); }); } CrxInstaller::Result InstallFunctionWrapper( diff --git a/chromium/components/update_client/utils.h b/chromium/components/update_client/utils.h index 525b7ed8a60..e8ec3b7247d 100644 --- a/chromium/components/update_client/utils.h +++ b/chromium/components/update_client/utils.h @@ -22,10 +22,6 @@ class DictionaryValue; class FilePath; } -namespace net { -class URLFetcher; -} - namespace network { class SharedURLLoaderFactory; class SimpleURLLoader; @@ -54,15 +50,6 @@ std::unique_ptr<network::SimpleURLLoader> SendProtocolRequest( LoadCompleteCallback callback, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory); -// Returns true if the url request of |fetcher| was succesful. -bool FetchSuccess(const net::URLFetcher& fetcher); - -// Returns the error code which occured during the fetch. The function returns 0 -// if the fetch was successful. If errors happen, the function could return a -// network error, an http response code, or the status of the fetch, if the -// fetch is pending or canceled. -int GetFetchError(const net::URLFetcher& fetcher); - // Returns true if the |component| contains a valid differential update url. bool HasDiffUpdate(const Component& component); |