chromium/chrome/browser/extensions/cws_info_service.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 =;

// Default check and fetch intervals.
constexpr int kCheckIntervalSeconds =;
constexpr int kFetchIntervalSeconds =;
// Fast mode check and fetch intervals. These intervals are used to
// facilitate end-end testing.
constexpr int kFastStartupCheckDelaySeconds =;
constexpr int kFastCheckIntervalSeconds =;
constexpr int kFastFetchIntervalSeconds =;

constexpr char kRequestUrl[] =;
constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation =;

// CWS Info pref keys.
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[] =;

// Proto conversion helpers.
// Helpers to convert extension id <-> name field in protos.
// name format: items/{itemId}/storeMetadata
std::string GetIdFromName(const std::string& name) {}
std::string GetNameFromId(const std::string& id) {}

// Whether or not to skip the check if the build includes the Google Chrome API
// key. Used for testing.
bool skip_api_key_check_for_testing =;

// Histogram helpers.
void RecordFetchSuccess(bool success) {}
void RecordMetadataChanged(bool changed) {}
void RecordNumRequestsInFetch(int num_requests) {}
void RecordNetworkHistograms(const network::SimpleURLLoader* url_loader) {}

}  // namespace

namespace extensions {

// Allow periodic retrieval of extensions metadata from the Chrome Web Store
// (CWS). This is effectively a kill-switch for the feature.
BASE_FEATURE();

// Increase the frequency of periodic retrieval of extensions metadata from
// CWS. This feature is used only for testing purposes.
BASE_FEATURE();

namespace {

base::Value::Dict GetDictFromStoreMetadataProto(const StoreMetadata* metadata) {}

// Saves CWS info if it is different from that currently saved in extension
// prefs.
bool SaveInfoIfChanged(ExtensionPrefs* extension_prefs,
                       const std::string& id,
                       const StoreMetadata* new_info) {}

int GetNextFetchInterval() {}

}  // namespace

// Stores context information about a CWS info fetch operation.
struct CWSInfoService::FetchContext {};

// static
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;
// static:
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 {}

// static
void CWSInfoService::SetSkipApiCheckForTesting(bool skip_api_key_check) {}

}  // namespace extensions