#include "extensions/browser/content_verifier/content_hash.h"
#include <set>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/sequence_checker.h"
#include "base/timer/elapsed_timer.h"
#include "content/public/browser/browser_thread.h"
#include "crypto/sha2.h"
#include "extensions/browser/content_hash_fetcher.h"
#include "extensions/browser/content_hash_tree.h"
#include "extensions/browser/content_verifier/content_verifier_utils.h"
#include "extensions/browser/extension_file_task_runner.h"
#include "extensions/common/file_util.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace extensions {
namespace {
bool CreateDirAndWriteFile(const base::FilePath& destination,
const std::string& content) { … }
std::unique_ptr<VerifiedContents> ReadVerifiedContents(
const ContentHash::FetchKey& key,
bool delete_invalid_file) { … }
}
ContentHash::FetchKey::FetchKey(
const ExtensionId& extension_id,
const base::FilePath& extension_root,
const base::Version& extension_version,
mojo::PendingRemote<network::mojom::URLLoaderFactory>
url_loader_factory_remote,
const GURL& fetch_url,
ContentVerifierKey verifier_key)
: … { … }
ContentHash::FetchKey::~FetchKey() = default;
ContentHash::FetchKey::FetchKey(ContentHash::FetchKey&& other) = default;
ContentHash::FetchKey& ContentHash::FetchKey::operator=(
ContentHash::FetchKey&& other) = default;
void ContentHash::Create(
FetchKey key,
ContentVerifierDelegate::VerifierSourceType source_type,
const IsCancelledCallback& is_cancelled,
CreatedCallback created_callback) { … }
void ContentHash::ForceBuildComputedHashes(
const IsCancelledCallback& is_cancelled,
CreatedCallback created_callback) { … }
ContentHash::TreeHashVerificationResult ContentHash::VerifyTreeHashRoot(
const base::FilePath& relative_path,
const std::string* root) const { … }
const ComputedHashes& ContentHash::computed_hashes() const { … }
std::string ContentHash::ComputeTreeHashForContent(const std::string& contents,
int block_size) { … }
ContentHash::ContentHash(
const ExtensionId& id,
const base::FilePath& root,
ContentVerifierDelegate::VerifierSourceType source_type,
std::unique_ptr<const VerifiedContents> verified_contents)
: … { … }
ContentHash::~ContentHash() = default;
void ContentHash::GetVerifiedContents(
FetchKey key,
ContentVerifierDelegate::VerifierSourceType source_type,
const IsCancelledCallback& is_cancelled,
GetVerifiedContentsCallback verified_contents_callback) { … }
void ContentHash::FetchVerifiedContents(ContentHash::FetchKey key,
const IsCancelledCallback& is_cancelled,
GetVerifiedContentsCallback callback) { … }
std::unique_ptr<VerifiedContents> ContentHash::StoreAndRetrieveVerifiedContents(
std::unique_ptr<std::string> fetched_contents,
const FetchKey& key) { … }
void ContentHash::DidFetchVerifiedContents(
GetVerifiedContentsCallback verified_contents_callback,
FetchKey key,
std::unique_ptr<std::string> fetched_contents,
FetchErrorCode fetch_error) { … }
void ContentHash::GetComputedHashes(
ContentVerifierDelegate::VerifierSourceType source_type,
const IsCancelledCallback& is_cancelled,
CreatedCallback created_callback,
FetchKey key,
std::unique_ptr<VerifiedContents> verified_contents,
bool did_attempt_fetch,
FetchErrorCode fetch_error) { … }
void ContentHash::DispatchFetchFailure(
const ExtensionId& extension_id,
const base::FilePath& extension_root,
ContentVerifierDelegate::VerifierSourceType source_type,
CreatedCallback created_callback,
const IsCancelledCallback& is_cancelled,
FetchErrorCode fetch_error) { … }
void ContentHash::RecordFetchResult(bool success, int fetch_error) { … }
bool ContentHash::ShouldComputeHashesForResource(
const base::FilePath& relative_unix_path) { … }
std::set<base::FilePath> ContentHash::GetMismatchedComputedHashes(
ComputedHashes::Data* computed_hashes_data) { … }
bool ContentHash::CreateHashes(const base::FilePath& hashes_file,
const IsCancelledCallback& is_cancelled) { … }
void ContentHash::BuildComputedHashes(bool attempted_fetching_verified_contents,
bool force_build,
const IsCancelledCallback& is_cancelled) { … }
}