1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/update_client/ping_manager.h"
#include <stddef.h>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/task/sequenced_task_runner.h"
#include "components/update_client/configurator.h"
#include "components/update_client/persisted_data.h"
#include "components/update_client/protocol_definition.h"
#include "components/update_client/protocol_handler.h"
#include "components/update_client/protocol_serializer.h"
#include "components/update_client/request_sender.h"
#include "components/update_client/update_client.h"
#include "components/update_client/utils.h"
#include "url/gurl.h"
namespace update_client {
PingManager::PingManager(scoped_refptr<Configurator> config)
: config_(config) {}
PingManager::~PingManager() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void PingManager::SendPing(const std::string& session_id,
const CrxComponent& component,
std::vector<base::Value::Dict> events,
base::OnceClosure callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (events.empty()) {
base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback)));
return;
}
auto urls(config_->PingUrl());
if (component.requires_network_encryption) {
RemoveUnsecureUrls(&urls);
}
if (urls.empty()) {
base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback)));
return;
}
// Install IDs are only sent on requests carrying an install event (2).
bool send_install_id = false;
for (const auto& event : events) {
if (event.FindInt("eventtype") == 2) {
send_install_id = true;
break;
}
}
const PersistedData& metadata = *config_->GetPersistedData();
std::vector<protocol_request::App> apps;
apps.push_back(MakeProtocolApp(
component.app_id, component.version, component.ap, component.brand,
send_install_id ? metadata.GetInstallId(component.app_id) : "",
component.lang.empty() ? config_->GetLang() : component.lang,
metadata.GetInstallDate(component.app_id), component.install_source,
component.install_location, component.installer_attributes,
metadata.GetCohort(component.app_id),
metadata.GetCohortHint(component.app_id),
metadata.GetCohortName(component.app_id), component.channel,
component.disabled_reasons, /*cached_hashes=*/{},
std::nullopt /* update check */, {} /* data */, std::nullopt /* ping */,
std::move(events)));
base::MakeRefCounted<RequestSender>(config_->GetNetworkFetcherFactory())
->Send(
urls, {},
config_->GetProtocolHandlerFactory()->CreateSerializer()->Serialize(
MakeProtocolRequest(
!config_->IsPerUserInstall(), session_id,
config_->GetProdId(),
config_->GetBrowserVersion().GetString(),
config_->GetChannel(), config_->GetOSLongName(),
config_->GetDownloadPreference(),
config_->IsMachineExternallyManaged(),
config_->ExtraRequestParams(), {}, std::move(apps))),
false,
base::BindOnce([](base::OnceClosure callback, int error,
const std::string& response,
int retry_after_sec) { std::move(callback).Run(); },
std::move(callback)));
}
} // namespace update_client
|