#include "components/invalidation/impl/per_user_topic_subscription_manager.h"
#include <stdint.h>
#include <algorithm>
#include <cstddef>
#include <iterator>
#include <memory>
#include <string>
#include <utility>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/observer_list.h"
#include "base/rand_util.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "components/gcm_driver/instance_id/instance_id_driver.h"
#include "components/invalidation/public/identity_provider.h"
#include "components/invalidation/public/invalidation_util.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "google_apis/gaia/gaia_constants.h"
namespace invalidation {
namespace {
constexpr char kDeprecatedSyncInvalidationGCMSenderId[] = …;
const char kTypeSubscribedForInvalidations[] = …;
const char kActiveRegistrationTokens[] = …;
const char kInvalidationRegistrationScope[] = …;
SubscriptionFinishedCallback;
static const net::BackoffEntry::Policy kBackoffPolicy = …;
class PerProjectDictionaryPrefUpdate { … };
enum class TokenStateOnSubscriptionRequest { … };
void ReportTokenState(TokenStateOnSubscriptionRequest token_state) { … }
}
void PerUserTopicSubscriptionManager::RegisterProfilePrefs(
PrefRegistrySimple* registry) { … }
void PerUserTopicSubscriptionManager::RegisterPrefs(
PrefRegistrySimple* registry) { … }
void PerUserTopicSubscriptionManager::ClearDeprecatedPrefs(PrefService* prefs) { … }
struct PerUserTopicSubscriptionManager::SubscriptionEntry { … };
PerUserTopicSubscriptionManager::SubscriptionEntry::SubscriptionEntry(
const Topic& topic,
SubscriptionFinishedCallback completion_callback,
PerUserTopicSubscriptionRequest::RequestType type,
bool topic_is_public)
: … { … }
PerUserTopicSubscriptionManager::SubscriptionEntry::~SubscriptionEntry() =
default;
void PerUserTopicSubscriptionManager::SubscriptionEntry::SubscriptionFinished(
const Status& code,
const std::string& topic_name) { … }
PerUserTopicSubscriptionManager::PerUserTopicSubscriptionManager(
IdentityProvider* identity_provider,
PrefService* pref_service,
network::mojom::URLLoaderFactory* url_loader_factory,
const std::string& project_id)
: … { … }
PerUserTopicSubscriptionManager::~PerUserTopicSubscriptionManager() = default;
std::unique_ptr<PerUserTopicSubscriptionManager>
PerUserTopicSubscriptionManager::Create(
network::mojom::URLLoaderFactory* url_loader_factory,
IdentityProvider* identity_provider,
PrefService* pref_service,
const std::string& project_id) { … }
void PerUserTopicSubscriptionManager::Init() { … }
void PerUserTopicSubscriptionManager::UpdateSubscribedTopics(
const TopicMap& topics,
const std::string& new_instance_id_token) { … }
void PerUserTopicSubscriptionManager::ClearInstanceIDToken() { … }
void PerUserTopicSubscriptionManager::StartPendingSubscriptions() { … }
void PerUserTopicSubscriptionManager::StartPendingSubscriptionRequest(
const Topic& topic) { … }
void PerUserTopicSubscriptionManager::ActOnSuccessfulSubscription(
const Topic& topic,
const std::string& private_topic_name,
PerUserTopicSubscriptionRequest::RequestType type) { … }
void PerUserTopicSubscriptionManager::ScheduleRequestForRepetition(
const Topic& topic) { … }
void PerUserTopicSubscriptionManager::SubscriptionFinishedForTopic(
Topic topic,
Status code,
std::string private_topic_name,
PerUserTopicSubscriptionRequest::RequestType type) { … }
TopicSet PerUserTopicSubscriptionManager::GetSubscribedTopicsForTest() const { … }
void PerUserTopicSubscriptionManager::AddObserver(Observer* observer) { … }
void PerUserTopicSubscriptionManager::RemoveObserver(Observer* observer) { … }
void PerUserTopicSubscriptionManager::RequestAccessToken() { … }
void PerUserTopicSubscriptionManager::OnAccessTokenRequestCompleted(
GoogleServiceAuthError error,
std::string access_token) { … }
void PerUserTopicSubscriptionManager::OnAccessTokenRequestSucceeded(
const std::string& access_token) { … }
void PerUserTopicSubscriptionManager::OnAccessTokenRequestFailed(
GoogleServiceAuthError error) { … }
void PerUserTopicSubscriptionManager::ReportNewInstanceIdTokenState(
const std::string& new_instance_id_token) const { … }
void PerUserTopicSubscriptionManager::StoreNewToken(
const std::string& new_instance_id_token) { … }
void PerUserTopicSubscriptionManager::DropAllSavedSubscriptionsOnTokenChange(
const std::string& new_instance_id_token) { … }
void PerUserTopicSubscriptionManager::NotifySubscriptionChannelStateChange(
SubscriptionChannelState state) { … }
void PerUserTopicSubscriptionManager::NotifySubscriptionRequestFinished(
Topic topic,
RequestType request_type,
Status code) { … }
std::optional<Topic>
PerUserTopicSubscriptionManager::LookupSubscribedPublicTopicByPrivateTopic(
const std::string& private_topic) const { … }
}