#include "chrome/browser/new_tab_page/one_google_bar/one_google_bar_loader_impl.h"
#include <string>
#include <utility>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/json/json_writer.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/new_tab_page/one_google_bar/one_google_bar_data.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/webui_url_constants.h"
#include "components/google/core/common/google_util.h"
#include "components/signin/public/identity_manager/tribool.h"
#include "components/variations/net/variations_http_headers.h"
#include "net/base/load_flags.h"
#include "net/base/url_util.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/data_decoder/public/cpp/data_decoder.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 "url/gurl.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/signin/chrome_signin_helper.h"
#include "components/signin/core/browser/chrome_connected_header_helper.h"
#include "components/signin/core/browser/signin_header_helper.h"
#endif
namespace {
const char kNewTabOgbApiPath[] = …;
const char kResponsePreamble[] = …;
namespace safe_html {
bool GetImpl(const base::Value::Dict& dict,
const std::string& name,
const std::string& wrapped_field_name,
std::string* out) { … }
bool GetHtml(const base::Value::Dict& dict,
const std::string& name,
std::string* out) { … }
bool GetScript(const base::Value::Dict& dict,
const std::string& name,
std::string* out) { … }
bool GetStyleSheet(const base::Value::Dict& dict,
const std::string& name,
std::string* out) { … }
}
std::optional<OneGoogleBarData> JsonToOGBData(const base::Value& value) { … }
}
class OneGoogleBarLoaderImpl::AuthenticatedURLLoader { … };
OneGoogleBarLoaderImpl::AuthenticatedURLLoader::AuthenticatedURLLoader(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
GURL api_url,
bool account_consistency_mirror_required,
LoadDoneCallback callback)
: … { … }
void OneGoogleBarLoaderImpl::AuthenticatedURLLoader::SetRequestHeaders(
network::ResourceRequest* request) const { … }
void OneGoogleBarLoaderImpl::AuthenticatedURLLoader::Start() { … }
void OneGoogleBarLoaderImpl::AuthenticatedURLLoader::OnURLLoaderComplete(
std::unique_ptr<std::string> response_body) { … }
OneGoogleBarLoaderImpl::OneGoogleBarLoaderImpl(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::string& application_locale,
bool account_consistency_mirror_required)
: … { … }
OneGoogleBarLoaderImpl::~OneGoogleBarLoaderImpl() = default;
void OneGoogleBarLoaderImpl::Load(OneGoogleCallback callback) { … }
GURL OneGoogleBarLoaderImpl::GetLoadURLForTesting() const { … }
bool OneGoogleBarLoaderImpl::SetAdditionalQueryParams(
const std::string& value) { … }
GURL OneGoogleBarLoaderImpl::GetApiUrl() const { … }
void OneGoogleBarLoaderImpl::LoadDone(
const network::SimpleURLLoader* simple_loader,
std::unique_ptr<std::string> response_body) { … }
void OneGoogleBarLoaderImpl::JsonParsed(
data_decoder::DataDecoder::ValueOrError result) { … }
void OneGoogleBarLoaderImpl::Respond(
Status status,
const std::optional<OneGoogleBarData>& data) { … }