#include "chrome/browser/extensions/cws_info_service.h"
#include <string_view>
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_map.h"
#include "base/containers/queue.h"
#include "base/i18n/time_formatting.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chrome/browser/extensions/cws_info_service_factory.h"
#include "chrome/browser/extensions/cws_item_service.pb.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/pref_names.h"
#include "google_apis/common/api_key_request_util.h"
#include "google_apis/google_api_keys.h"
#include "net/base/load_flags.h"
#include "net/http/http_status_code.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace {
constexpr int kMaxExtensionIdsPerRequest = …;
constexpr int kMaxRetriesPerRequest = …;
constexpr int kCheckIntervalSeconds = …;
constexpr int kFetchIntervalSeconds = …;
constexpr int kFastStartupCheckDelaySeconds = …;
constexpr int kFastCheckIntervalSeconds = …;
constexpr int kFastFetchIntervalSeconds = …;
constexpr char kRequestUrl[] = …;
constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation = …;
constexpr char kCWSInfo[] = …;
constexpr char kIsPresent[] = …;
constexpr char kIsLive[] = …;
constexpr char kLastUpdateTimeMillis[] = …;
constexpr char kViolationType[] = …;
constexpr char kUnpublishedLongAgo[] = …;
constexpr char kNoPrivacyPractice[] = …;
constexpr const char* kLabels[] = …;
std::string GetIdFromName(const std::string& name) { … }
std::string GetNameFromId(const std::string& id) { … }
bool skip_api_key_check_for_testing = …;
void RecordFetchSuccess(bool success) { … }
void RecordMetadataChanged(bool changed) { … }
void RecordNumRequestsInFetch(int num_requests) { … }
void RecordNetworkHistograms(const network::SimpleURLLoader* url_loader) { … }
}
namespace extensions {
BASE_FEATURE(…);
BASE_FEATURE(…);
namespace {
base::Value::Dict GetDictFromStoreMetadataProto(const StoreMetadata* metadata) { … }
bool SaveInfoIfChanged(ExtensionPrefs* extension_prefs,
const std::string& id,
const StoreMetadata* new_info) { … }
int GetNextFetchInterval() { … }
}
struct CWSInfoService::FetchContext { … };
CWSInfoService* CWSInfoService::Get(Profile* profile) { … }
CWSInfoService::CWSInfoService(Profile* profile)
: … { … }
CWSInfoService::CWSInfoService() = default;
CWSInfoService::~CWSInfoService() = default;
void CWSInfoService::Shutdown() { … }
std::optional<bool> CWSInfoService::IsLiveInCWS(
const Extension& extension) const { … }
std::optional<CWSInfoService::CWSInfo> CWSInfoService::GetCWSInfo(
const Extension& extension) const { … }
void CWSInfoService::CheckAndMaybeFetchInfo() { … }
void CWSInfoService::ScheduleCheck(int seconds) { … }
std::unique_ptr<CWSInfoService::FetchContext> CWSInfoService::CreateRequests(
bool& new_info_requested) { … }
void CWSInfoService::SendRequest() { … }
void CWSInfoService::OnResponseReceived(std::unique_ptr<std::string> response) { … }
bool CWSInfoService::MaybeSaveResponseToPrefs(
const BatchGetStoreMetadatasResponse& response_proto) { … }
void CWSInfoService::AddObserver(Observer* observer) { … }
void CWSInfoService::RemoveObserver(Observer* observer) { … }
static_assert …;
CWSInfoService::CWSViolationType CWSInfoService::GetViolationTypeFromString(
const std::string& violation_type_str) { … }
void CWSInfoService::SetMaxExtensionIdsPerRequestForTesting(int max) { … }
std::string CWSInfoService::GetRequestURLForTesting() const { … }
int CWSInfoService::GetFetchIntervalForTesting() const { … }
int CWSInfoService::GetStartupDelayForTesting() const { … }
int CWSInfoService::GetCheckIntervalForTesting() const { … }
base::Time CWSInfoService::GetCWSInfoTimestampForTesting() const { … }
base::Time CWSInfoService::GetCWSInfoFetchErrorTimestampForTesting() const { … }
void CWSInfoService::SetSkipApiCheckForTesting(bool skip_api_key_check) { … }
}