#include "components/history/core/browser/web_history_service.h"
#include <memory>
#include <optional>
#include <utility>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/history/core/browser/web_history_service_observer.h"
#include "components/signin/public/identity_manager/access_token_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/primary_account_access_token_fetcher.h"
#include "components/signin/public/identity_manager/scope_set.h"
#include "components/sync/base/features.h"
#include "components/sync/base/sync_util.h"
#include "components/sync/protocol/history_status.pb.h"
#include "google_apis/gaia/gaia_urls.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/base/url_util.h"
#include "net/http/http_status_code.h"
#include "net/http/http_util.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"
#include "url/gurl.h"
namespace history {
namespace {
const char kHistoryOAuthScope[] = …;
const char kHistoryQueryHistoryUrl[] = …;
const char kHistoryDeleteHistoryUrl[] = …;
const char kHistoryAudioHistoryUrl[] = …;
const char kHistoryAudioHistoryChangeUrl[] = …;
const char kQueryWebAndAppActivityUrl[] = …;
const char kQueryOtherFormsOfBrowsingHistoryUrlSuffix[] = …;
const char kPostDataMimeType[] = …;
const char kSyncProtoMimeType[] = …;
const size_t kMaxRetries = …;
class RequestImpl : public WebHistoryService::Request { … };
std::string ServerTimeString(base::Time time) { … }
GURL GetQueryUrl(const std::u16string& text_query,
const QueryOptions& options,
const std::string& version_info) { … }
base::Value::Dict CreateDeletion(const std::string& min_time,
const std::string& max_time,
const GURL& url) { … }
}
WebHistoryService::Request::Request() = default;
WebHistoryService::Request::~Request() = default;
WebHistoryService::WebHistoryService(
signin::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory)
: … { … }
WebHistoryService::~WebHistoryService() = default;
void WebHistoryService::AddObserver(WebHistoryServiceObserver* observer) { … }
void WebHistoryService::RemoveObserver(WebHistoryServiceObserver* observer) { … }
WebHistoryService::Request* WebHistoryService::CreateRequest(
const GURL& url,
CompletionCallback callback,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) { … }
std::optional<base::Value::Dict> WebHistoryService::ReadResponse(
WebHistoryService::Request* request) { … }
std::unique_ptr<WebHistoryService::Request> WebHistoryService::QueryHistory(
const std::u16string& text_query,
const QueryOptions& options,
WebHistoryService::QueryWebHistoryCallback callback,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) { … }
void WebHistoryService::ExpireHistory(
const std::vector<ExpireHistoryArgs>& expire_list,
ExpireWebHistoryCallback callback,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) { … }
void WebHistoryService::ExpireHistoryBetween(
const std::set<GURL>& restrict_urls,
base::Time begin_time,
base::Time end_time,
ExpireWebHistoryCallback callback,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) { … }
void WebHistoryService::GetAudioHistoryEnabled(
AudioWebHistoryCallback callback,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) { … }
void WebHistoryService::SetAudioHistoryEnabled(
bool new_enabled_value,
AudioWebHistoryCallback callback,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) { … }
size_t WebHistoryService::GetNumberOfPendingAudioHistoryRequests() { … }
void WebHistoryService::QueryWebAndAppActivity(
QueryWebAndAppActivityCallback callback,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) { … }
void WebHistoryService::QueryOtherFormsOfBrowsingHistory(
version_info::Channel channel,
QueryOtherFormsOfBrowsingHistoryCallback callback,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) { … }
void WebHistoryService::QueryHistoryCompletionCallback(
WebHistoryService::QueryWebHistoryCallback callback,
WebHistoryService::Request* request,
bool success) { … }
void WebHistoryService::ExpireHistoryCompletionCallback(
WebHistoryService::ExpireWebHistoryCallback callback,
WebHistoryService::Request* request,
bool success) { … }
void WebHistoryService::AudioHistoryCompletionCallback(
WebHistoryService::AudioWebHistoryCallback callback,
WebHistoryService::Request* request,
bool success) { … }
void WebHistoryService::QueryWebAndAppActivityCompletionCallback(
WebHistoryService::QueryWebAndAppActivityCallback callback,
WebHistoryService::Request* request,
bool success) { … }
void WebHistoryService::QueryOtherFormsOfBrowsingHistoryCompletionCallback(
WebHistoryService::QueryOtherFormsOfBrowsingHistoryCallback callback,
WebHistoryService::Request* request,
bool success) { … }
}