diff options
Diffstat (limited to 'chromium/components/update_client')
14 files changed, 37 insertions, 14 deletions
diff --git a/chromium/components/update_client/action_runner.cc b/chromium/components/update_client/action_runner.cc index 6bf6d808ade..6858fcb535e 100644 --- a/chromium/components/update_client/action_runner.cc +++ b/chromium/components/update_client/action_runner.cc @@ -9,6 +9,7 @@ #include "base/bind.h" #include "base/files/file_path.h" #include "base/location.h" +#include "base/logging.h" #include "base/task/thread_pool.h" #include "base/threading/thread_task_runner_handle.h" #include "components/update_client/component.h" diff --git a/chromium/components/update_client/background_downloader_win.cc b/chromium/components/update_client/background_downloader_win.cc index c59a5068597..76306727d7e 100644 --- a/chromium/components/update_client/background_downloader_win.cc +++ b/chromium/components/update_client/background_downloader_win.cc @@ -19,6 +19,7 @@ #include "base/bind.h" #include "base/files/file_util.h" #include "base/location.h" +#include "base/logging.h" #include "base/macros.h" #include "base/metrics/histogram_macros.h" #include "base/sequenced_task_runner.h" diff --git a/chromium/components/update_client/component.cc b/chromium/components/update_client/component.cc index d764317f18b..541a159b21c 100644 --- a/chromium/components/update_client/component.cc +++ b/chromium/components/update_client/component.cc @@ -14,6 +14,7 @@ #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" #include "base/location.h" +#include "base/logging.h" #include "base/notreached.h" #include "base/strings/string_number_conversions.h" #include "base/task/post_task.h" diff --git a/chromium/components/update_client/net/network_impl.cc b/chromium/components/update_client/net/network_impl.cc index d2a99abddd9..12661a7f569 100644 --- a/chromium/components/update_client/net/network_impl.cc +++ b/chromium/components/update_client/net/network_impl.cc @@ -102,6 +102,7 @@ NetworkFetcherImpl::~NetworkFetcherImpl() = default; void NetworkFetcherImpl::PostRequest( const GURL& url, const std::string& post_data, + const std::string& content_type, const base::flat_map<std::string, std::string>& post_additional_headers, ResponseStartedCallback response_started_callback, ProgressCallback progress_callback, @@ -119,7 +120,9 @@ void NetworkFetcherImpl::PostRequest( simple_url_loader_->SetRetryOptions( kMaxRetriesOnNetworkChange, network::SimpleURLLoader::RETRY_ON_NETWORK_CHANGE); - simple_url_loader_->AttachStringForUpload(post_data, "application/json"); + // The `Content-Type` header set by |AttachStringForUpload| overwrites any + // `Content-Type` header present in the |ResourceRequest| above. + simple_url_loader_->AttachStringForUpload(post_data, content_type); simple_url_loader_->SetOnResponseStartedCallback(base::BindOnce( &NetworkFetcherImpl::OnResponseStartedCallback, base::Unretained(this), std::move(response_started_callback))); diff --git a/chromium/components/update_client/net/network_impl.h b/chromium/components/update_client/net/network_impl.h index 71d1c7bd181..f8d4f9c4e8f 100644 --- a/chromium/components/update_client/net/network_impl.h +++ b/chromium/components/update_client/net/network_impl.h @@ -34,6 +34,7 @@ class NetworkFetcherImpl : public NetworkFetcher { void PostRequest( const GURL& url, const std::string& post_data, + const std::string& content_type, const base::flat_map<std::string, std::string>& post_additional_headers, ResponseStartedCallback response_started_callback, ProgressCallback progress_callback, diff --git a/chromium/components/update_client/network.h b/chromium/components/update_client/network.h index 8f92d3f10c6..4afce03df36 100644 --- a/chromium/components/update_client/network.h +++ b/chromium/components/update_client/network.h @@ -55,6 +55,7 @@ class NetworkFetcher { virtual void PostRequest( const GURL& url, const std::string& post_data, + const std::string& content_type, const base::flat_map<std::string, std::string>& post_additional_headers, ResponseStartedCallback response_started_callback, ProgressCallback progress_callback, diff --git a/chromium/components/update_client/protocol_serializer_fuzzer.cc b/chromium/components/update_client/protocol_serializer_fuzzer.cc index 1b2de023c20..6d108c7d2d8 100644 --- a/chromium/components/update_client/protocol_serializer_fuzzer.cc +++ b/chromium/components/update_client/protocol_serializer_fuzzer.cc @@ -47,8 +47,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { std::string request_serialized = serializer->Serialize(request); // Any request we serialize should be valid JSON. - base::JSONReader json_reader; - CHECK(json_reader.Read(request_serialized)); + CHECK(base::JSONReader::Read(request_serialized)); return 0; } } // namespace update_client diff --git a/chromium/components/update_client/request_sender.cc b/chromium/components/update_client/request_sender.cc index 3f0ae03489d..4a8bc1dce1c 100644 --- a/chromium/components/update_client/request_sender.cc +++ b/chromium/components/update_client/request_sender.cc @@ -25,10 +25,13 @@ namespace { // This is an ECDSA prime256v1 named-curve key. constexpr int kKeyVersion = 10; -const char kKeyPubBytesBase64[] = +constexpr char kKeyPubBytesBase64[] = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzOqC8cKNUYIi0UkNu0smZKDW8w5/" "0EmEw1KQ6Aj/5JWBMdUVm13EIVwFwPlkO/U6vXa+iu4wyUB89GFaldJ7Bg=="; +// The content type for all protocol requests. +constexpr char kContentType[] = "application/json"; + } // namespace RequestSender::RequestSender(scoped_refptr<Configurator> config) @@ -96,7 +99,7 @@ void RequestSender::SendInternal() { std::string(), std::string(), 0)); } network_fetcher_->PostRequest( - url, request_body_, request_extra_headers_, + url, request_body_, kContentType, request_extra_headers_, base::BindOnce(&RequestSender::OnResponseStarted, base::Unretained(this)), base::BindRepeating([](int64_t current) {}), base::BindOnce(&RequestSender::OnNetworkFetcherComplete, diff --git a/chromium/components/update_client/request_sender_unittest.cc b/chromium/components/update_client/request_sender_unittest.cc index 790a98846b7..08150745cc1 100644 --- a/chromium/components/update_client/request_sender_unittest.cc +++ b/chromium/components/update_client/request_sender_unittest.cc @@ -159,9 +159,12 @@ TEST_P(RequestSenderTest, RequestSendSuccess) { const auto extra_request_headers = std::get<1>(post_interceptor_->GetRequests()[0]); EXPECT_TRUE(extra_request_headers.HasHeader("X-Goog-Update-Interactivity")); + EXPECT_TRUE(extra_request_headers.HasHeader("Content-Type")); std::string header; extra_request_headers.GetHeader("X-Goog-Update-Interactivity", &header); EXPECT_STREQ(is_foreground ? "fg" : "bg", header.c_str()); + extra_request_headers.GetHeader("Content-Type", &header); + EXPECT_STREQ("application/json", header.c_str()); } // Tests that the request succeeds using the second url after the first url diff --git a/chromium/components/update_client/task_update.cc b/chromium/components/update_client/task_update.cc index 733649b5711..4d78c55fbb3 100644 --- a/chromium/components/update_client/task_update.cc +++ b/chromium/components/update_client/task_update.cc @@ -57,9 +57,16 @@ std::vector<std::string> TaskUpdate::GetIds() const { void TaskUpdate::TaskComplete(Error error) { DCHECK(thread_checker_.CalledOnValidThread()); + // NOTE: Do not post the callback_ directly to the task thread to ensure the + // UpdateClient reference (to which the callback is bound) does not get + // released before the callback is run during shutdown, when the task runner + // gets destroyed. base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, - base::BindOnce(std::move(callback_), base::WrapRefCounted(this), error)); + FROM_HERE, base::BindOnce(&TaskUpdate::RunCallback, this, error)); +} + +void TaskUpdate::RunCallback(Error error) { + std::move(callback_).Run(this, error); } } // namespace update_client diff --git a/chromium/components/update_client/task_update.h b/chromium/components/update_client/task_update.h index 79b07c8d859..ee6522d1763 100644 --- a/chromium/components/update_client/task_update.h +++ b/chromium/components/update_client/task_update.h @@ -53,6 +53,9 @@ class TaskUpdate : public Task { // it has been canceled. void TaskComplete(Error error); + // Runs the task update callback. + void RunCallback(Error error); + base::ThreadChecker thread_checker_; scoped_refptr<UpdateEngine> update_engine_; const bool is_foreground_; diff --git a/chromium/components/update_client/update_checker_unittest.cc b/chromium/components/update_client/update_checker_unittest.cc index 9e571f1c0c7..91e126017a7 100644 --- a/chromium/components/update_client/update_checker_unittest.cc +++ b/chromium/components/update_client/update_checker_unittest.cc @@ -492,10 +492,10 @@ TEST_P(UpdateCheckerTest, UpdateCheckDownloadPreference) { // The request must contain dlpref="cacheable". const auto request = post_interceptor_->GetRequestBody(0); - const auto root = base::JSONReader().Read(request); - ASSERT_TRUE(root); - EXPECT_EQ("cacheable", - root->FindKey("request")->FindKey("dlpref")->GetString()); + const auto root = base::JSONReader::Read(request); + ASSERT_TRUE(root); + EXPECT_EQ("cacheable", + root->FindKey("request")->FindKey("dlpref")->GetString()); } // This test is checking that an update check signed with CUP fails, since there diff --git a/chromium/components/update_client/update_client.cc b/chromium/components/update_client/update_client.cc index 07873bb0a8f..d45af8bf3e9 100644 --- a/chromium/components/update_client/update_client.cc +++ b/chromium/components/update_client/update_client.cc @@ -238,7 +238,7 @@ void UpdateClientImpl::SendUninstallPing(const std::string& id, RunTask(base::MakeRefCounted<TaskSendUninstallPing>( update_engine_.get(), id, version, reason, - base::BindOnce(&UpdateClientImpl::OnTaskComplete, base::Unretained(this), + base::BindOnce(&UpdateClientImpl::OnTaskComplete, this, std::move(callback)))); } diff --git a/chromium/components/update_client/update_query_params.cc b/chromium/components/update_client/update_query_params.cc index 535d272b749..3336e37fb39 100644 --- a/chromium/components/update_client/update_query_params.cc +++ b/chromium/components/update_client/update_query_params.cc @@ -62,11 +62,11 @@ const char kArch[] = #error "unknown arch" #endif -const char kChrome[] = "chrome"; - #if BUILDFLAG(GOOGLE_CHROME_BRANDING) +const char kChrome[] = "chrome"; const char kCrx[] = "chromecrx"; #else +const char kChrome[] = "chromium"; const char kCrx[] = "chromiumcrx"; #endif // BUILDFLAG(GOOGLE_CHROME_BRANDING) |