#include "components/gcm_driver/gcm_driver_desktop.h"
#include <memory>
#include <utility>
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/observer_list.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "base/trace_event/trace_event.h"
#include "components/gcm_driver/gcm_account_mapper.h"
#include "components/gcm_driver/gcm_app_handler.h"
#include "components/gcm_driver/gcm_client_factory.h"
#include "components/gcm_driver/gcm_delayed_task_controller.h"
#include "components/gcm_driver/instance_id/instance_id_impl.h"
#include "components/gcm_driver/system_encryptor.h"
#include "google_apis/gcm/engine/account_mapping.h"
#include "net/base/ip_endpoint.h"
#include "services/network/public/cpp/network_connection_tracker.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace gcm {
class GCMDriverDesktop::IOWorker : public GCMClient::Delegate { … };
GCMDriverDesktop::IOWorker::IOWorker(
const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
const scoped_refptr<base::SequencedTaskRunner>& io_thread)
: … { … }
GCMDriverDesktop::IOWorker::~IOWorker() { … }
void GCMDriverDesktop::IOWorker::Initialize(
std::unique_ptr<GCMClientFactory> gcm_client_factory,
const GCMClient::ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
base::RepeatingCallback<void(
mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
get_socket_factory_callback,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_loader_factory,
network::NetworkConnectionTracker* network_connection_tracker,
const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) { … }
void GCMDriverDesktop::IOWorker::OnRegisterFinished(
scoped_refptr<RegistrationInfo> registration_info,
const std::string& registration_id,
GCMClient::Result result) { … }
void GCMDriverDesktop::IOWorker::OnUnregisterFinished(
scoped_refptr<RegistrationInfo> registration_info,
GCMClient::Result result) { … }
void GCMDriverDesktop::IOWorker::OnSendFinished(const std::string& app_id,
const std::string& message_id,
GCMClient::Result result) { … }
void GCMDriverDesktop::IOWorker::OnMessageReceived(
const std::string& app_id,
const IncomingMessage& message) { … }
void GCMDriverDesktop::IOWorker::OnMessagesDeleted(const std::string& app_id) { … }
void GCMDriverDesktop::IOWorker::OnMessageSendError(
const std::string& app_id,
const GCMClient::SendErrorDetails& send_error_details) { … }
void GCMDriverDesktop::IOWorker::OnSendAcknowledged(
const std::string& app_id,
const std::string& message_id) { … }
void GCMDriverDesktop::IOWorker::OnGCMReady(
const std::vector<AccountMapping>& account_mappings,
const base::Time& last_token_fetch_time) { … }
void GCMDriverDesktop::IOWorker::OnActivityRecorded() { … }
void GCMDriverDesktop::IOWorker::OnConnected(
const net::IPEndPoint& ip_endpoint) { … }
void GCMDriverDesktop::IOWorker::OnDisconnected() { … }
void GCMDriverDesktop::IOWorker::OnStoreReset() { … }
void GCMDriverDesktop::IOWorker::Start(
GCMClient::StartMode start_mode,
const base::WeakPtr<GCMDriverDesktop>& service,
base::TimeTicks time_task_posted) { … }
void GCMDriverDesktop::IOWorker::Stop() { … }
void GCMDriverDesktop::IOWorker::Register(
const std::string& app_id,
const std::vector<std::string>& sender_ids) { … }
bool GCMDriverDesktop::IOWorker::ValidateRegistration(
scoped_refptr<RegistrationInfo> registration_info,
const std::string& registration_id) { … }
void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) { … }
void GCMDriverDesktop::IOWorker::Send(const std::string& app_id,
const std::string& receiver_id,
const OutgoingMessage& message) { … }
void GCMDriverDesktop::IOWorker::GetGCMStatistics(
GetGCMStatisticsCallback callback,
ClearActivityLogs clear_logs) { … }
void GCMDriverDesktop::IOWorker::SetGCMRecording(
GetGCMStatisticsCallback callback,
bool recording) { … }
void GCMDriverDesktop::IOWorker::SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { … }
void GCMDriverDesktop::IOWorker::UpdateAccountMapping(
const AccountMapping& account_mapping) { … }
void GCMDriverDesktop::IOWorker::RemoveAccountMapping(
const CoreAccountId& account_id) { … }
void GCMDriverDesktop::IOWorker::SetLastTokenFetchTime(const base::Time& time) { … }
void GCMDriverDesktop::IOWorker::AddInstanceIDData(
const std::string& app_id,
const std::string& instance_id,
const std::string& extra_data) { … }
void GCMDriverDesktop::IOWorker::RemoveInstanceIDData(
const std::string& app_id) { … }
void GCMDriverDesktop::IOWorker::GetInstanceIDData(const std::string& app_id) { … }
void GCMDriverDesktop::IOWorker::GetToken(const std::string& app_id,
const std::string& authorized_entity,
const std::string& scope,
base::TimeDelta time_to_live) { … }
void GCMDriverDesktop::IOWorker::DeleteToken(
const std::string& app_id,
const std::string& authorized_entity,
const std::string& scope) { … }
void GCMDriverDesktop::IOWorker::AddHeartbeatInterval(const std::string& scope,
int interval_ms) { … }
void GCMDriverDesktop::IOWorker::RemoveHeartbeatInterval(
const std::string& scope) { … }
void GCMDriverDesktop::IOWorker::RecordDecryptionFailure(
const std::string& app_id,
GCMDecryptionResult result) { … }
GCMDriverDesktop::GCMDriverDesktop(
std::unique_ptr<GCMClientFactory> gcm_client_factory,
const GCMClient::ChromeBuildInfo& chrome_build_info,
PrefService* prefs,
const base::FilePath& store_path,
base::RepeatingCallback<void(
mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>
get_socket_factory_callback,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_for_ui,
network::NetworkConnectionTracker* network_connection_tracker,
const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
const scoped_refptr<base::SequencedTaskRunner>& io_thread,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner)
: … { … }
GCMDriverDesktop::~GCMDriverDesktop() = default;
void GCMDriverDesktop::ValidateRegistration(
const std::string& app_id,
const std::vector<std::string>& sender_ids,
const std::string& registration_id,
ValidateRegistrationCallback callback) { … }
void GCMDriverDesktop::DoValidateRegistration(
scoped_refptr<RegistrationInfo> registration_info,
const std::string& registration_id,
ValidateRegistrationCallback callback) { … }
void GCMDriverDesktop::Shutdown() { … }
void GCMDriverDesktop::AddAppHandler(const std::string& app_id,
GCMAppHandler* handler) { … }
void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) { … }
void GCMDriverDesktop::AddConnectionObserver(GCMConnectionObserver* observer) { … }
void GCMDriverDesktop::RemoveConnectionObserver(
GCMConnectionObserver* observer) { … }
void GCMDriverDesktop::Stop() { … }
void GCMDriverDesktop::RegisterImpl(
const std::string& app_id,
const std::vector<std::string>& sender_ids) { … }
void GCMDriverDesktop::DoRegister(const std::string& app_id,
const std::vector<std::string>& sender_ids) { … }
void GCMDriverDesktop::UnregisterImpl(const std::string& app_id) { … }
void GCMDriverDesktop::DoUnregister(const std::string& app_id) { … }
void GCMDriverDesktop::SendImpl(const std::string& app_id,
const std::string& receiver_id,
const OutgoingMessage& message) { … }
void GCMDriverDesktop::DoSend(const std::string& app_id,
const std::string& receiver_id,
const OutgoingMessage& message) { … }
void GCMDriverDesktop::RecordDecryptionFailure(const std::string& app_id,
GCMDecryptionResult result) { … }
GCMClient* GCMDriverDesktop::GetGCMClientForTesting() const { … }
bool GCMDriverDesktop::IsStarted() const { … }
bool GCMDriverDesktop::IsConnected() const { … }
void GCMDriverDesktop::GetGCMStatistics(GetGCMStatisticsCallback callback,
ClearActivityLogs clear_logs) { … }
void GCMDriverDesktop::SetGCMRecording(
const GCMStatisticsRecordingCallback& callback,
bool recording) { … }
void GCMDriverDesktop::UpdateAccountMapping(
const AccountMapping& account_mapping) { … }
void GCMDriverDesktop::RemoveAccountMapping(const CoreAccountId& account_id) { … }
base::Time GCMDriverDesktop::GetLastTokenFetchTime() { … }
void GCMDriverDesktop::SetLastTokenFetchTime(const base::Time& time) { … }
InstanceIDHandler* GCMDriverDesktop::GetInstanceIDHandlerInternal() { … }
void GCMDriverDesktop::GetToken(const std::string& app_id,
const std::string& authorized_entity,
const std::string& scope,
base::TimeDelta time_to_live,
GetTokenCallback callback) { … }
void GCMDriverDesktop::DoGetToken(const std::string& app_id,
const std::string& authorized_entity,
const std::string& scope,
base::TimeDelta time_to_live) { … }
void GCMDriverDesktop::ValidateToken(const std::string& app_id,
const std::string& authorized_entity,
const std::string& scope,
const std::string& token,
ValidateTokenCallback callback) { … }
void GCMDriverDesktop::DeleteToken(const std::string& app_id,
const std::string& authorized_entity,
const std::string& scope,
DeleteTokenCallback callback) { … }
void GCMDriverDesktop::DoDeleteToken(const std::string& app_id,
const std::string& authorized_entity,
const std::string& scope) { … }
void GCMDriverDesktop::AddInstanceIDData(const std::string& app_id,
const std::string& instance_id,
const std::string& extra_data) { … }
void GCMDriverDesktop::DoAddInstanceIDData(const std::string& app_id,
const std::string& instance_id,
const std::string& extra_data) { … }
void GCMDriverDesktop::RemoveInstanceIDData(const std::string& app_id) { … }
void GCMDriverDesktop::DoRemoveInstanceIDData(const std::string& app_id) { … }
void GCMDriverDesktop::GetInstanceIDData(const std::string& app_id,
GetInstanceIDDataCallback callback) { … }
void GCMDriverDesktop::DoGetInstanceIDData(const std::string& app_id) { … }
void GCMDriverDesktop::GetInstanceIDDataFinished(
const std::string& app_id,
const std::string& instance_id,
const std::string& extra_data) { … }
void GCMDriverDesktop::GetTokenFinished(const std::string& app_id,
const std::string& authorized_entity,
const std::string& scope,
const std::string& token,
GCMClient::Result result) { … }
void GCMDriverDesktop::DeleteTokenFinished(const std::string& app_id,
const std::string& authorized_entity,
const std::string& scope,
GCMClient::Result result) { … }
void GCMDriverDesktop::AddHeartbeatInterval(const std::string& scope,
int interval_ms) { … }
void GCMDriverDesktop::RemoveHeartbeatInterval(const std::string& scope) { … }
void GCMDriverDesktop::SetAccountTokens(
const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { … }
GCMClient::Result GCMDriverDesktop::EnsureStarted(
GCMClient::StartMode start_mode) { … }
void GCMDriverDesktop::RemoveCachedData() { … }
void GCMDriverDesktop::MessageReceived(const std::string& app_id,
const IncomingMessage& message) { … }
void GCMDriverDesktop::MessagesDeleted(const std::string& app_id) { … }
void GCMDriverDesktop::MessageSendError(
const std::string& app_id,
const GCMClient::SendErrorDetails& send_error_details) { … }
void GCMDriverDesktop::SendAcknowledged(const std::string& app_id,
const std::string& message_id) { … }
void GCMDriverDesktop::GCMClientReady(
const std::vector<AccountMapping>& account_mappings,
const base::Time& last_token_fetch_time) { … }
void GCMDriverDesktop::OnConnected(const net::IPEndPoint& ip_endpoint) { … }
void GCMDriverDesktop::OnDisconnected() { … }
void GCMDriverDesktop::OnStoreReset() { … }
void GCMDriverDesktop::OnActivityRecorded(
const GCMClient::GCMStatistics& stats) { … }
bool GCMDriverDesktop::TokenTupleComparer::operator()(
const TokenTuple& a,
const TokenTuple& b) const { … }
}