chromium/chrome/browser/download/download_query.cc

// Copyright 2012 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/download/download_query.h"

#include <stdint.h>

#include <algorithm>
#include <limits>
#include <memory>
#include <string>
#include <vector>

#include "base/check_op.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/i18n/case_conversion.h"
#include "base/i18n/string_search.h"
#include "base/i18n/time_formatting.h"
#include "base/memory/raw_ref.h"
#include "base/notreached.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/download/public/common/download_item.h"
#include "components/url_formatter/url_formatter.h"
#include "content/public/browser/content_browser_client.h"
#include "third_party/re2/src/re2/re2.h"
#include "url/gurl.h"

DownloadDangerType;
DownloadItem;

namespace {

// Templatized base::Value::GetAs*().
template <typename T> bool GetAs(const base::Value& in, T* out);
template<> bool GetAs(const base::Value& in, bool* out) {}
template <>
bool GetAs(const base::Value& in, double* out) {}
template<> bool GetAs(const base::Value& in, std::string* out) {}
template <>
bool GetAs(const base::Value& in, std::u16string* out) {}
template <>
bool GetAs(const base::Value& in, std::vector<std::u16string>* out) {}

// The next several functions are helpers for making Callbacks that access
// DownloadItem fields.

int64_t GetStartTimeMsEpoch(const DownloadItem& item) {}

int64_t GetEndTimeMsEpoch(const DownloadItem& item) {}

std::string GetStartTime(const DownloadItem& item) {}

std::string GetEndTime(const DownloadItem& item) {}

bool GetDangerAccepted(const DownloadItem& item) {}

bool GetExists(const DownloadItem& item) {}

std::u16string GetFilename(const DownloadItem& item) {}

std::string GetFilenameUTF8(const DownloadItem& item) {}

std::string GetOriginalUrl(const DownloadItem& item) {}

std::string GetUrl(const DownloadItem& item) {}

DownloadItem::DownloadState GetState(const DownloadItem& item) {}

DownloadDangerType GetDangerType(const DownloadItem& item) {}

double GetReceivedBytes(const DownloadItem& item) {}

double GetTotalBytes(const DownloadItem& item) {}

std::string GetMimeType(const DownloadItem& item) {}

bool IsPaused(const DownloadItem& item) {}

enum ComparisonType {};

// Returns true if |item| matches the filter specified by |value|, |cmptype|,
// and |accessor|. |accessor| is conceptually a function that takes a
// DownloadItem and returns one of its fields, which is then compared to
// |value|.
template <typename ValueType>
bool FieldMatches(
    const ValueType& value,
    ComparisonType cmptype,
    const base::RepeatingCallback<ValueType(const DownloadItem&)>& accessor,
    const DownloadItem& item) {}

// Helper for building a Callback to FieldMatches<>().
template <typename ValueType> DownloadQuery::FilterCallback BuildFilter(
    const base::Value& value, ComparisonType cmptype,
    ValueType (*accessor)(const DownloadItem&)) {}

// Returns true if |accessor.Run(item)| matches |pattern|.
bool FindRegex(
    RE2* pattern,
    const base::RepeatingCallback<std::string(const DownloadItem&)>& accessor,
    const DownloadItem& item) {}

// Helper for building a Callback to FindRegex().
DownloadQuery::FilterCallback BuildRegexFilter(
    const base::Value& regex_value,
    std::string (*accessor)(const DownloadItem&)) {}

// Returns a ComparisonType to indicate whether a field in |left| is less than,
// greater than or equal to the same field in |right|.
template <typename ValueType>
ComparisonType Compare(
    const base::RepeatingCallback<ValueType(const DownloadItem&)>& accessor,
    const DownloadItem& left,
    const DownloadItem& right) {}

}  // anonymous namespace

// AddSorter() creates a Sorter and pushes it onto sorters_. A Sorter is a
// direction and a Callback to Compare<>(). After filtering, Search() makes a
// DownloadComparator functor from the sorters_ and passes the
// DownloadComparator to std::partial_sort. std::partial_sort calls the
// DownloadComparator with different pairs of DownloadItems.  DownloadComparator
// iterates over the sorters until a callback returns ComparisonType LT or GT.
// DownloadComparator returns true or false depending on that ComparisonType and
// the sorter's direction in order to indicate to std::partial_sort whether the
// left item is after or before the right item. If all sorters return EQ, then
// DownloadComparator compares GetId. A DownloadQuery may have zero or more
// Sorters, but there is one DownloadComparator per call to Search().

struct DownloadQuery::Sorter {};

class DownloadQuery::DownloadComparator {};

bool DownloadQuery::DownloadComparator::operator()(const DownloadItem* left,
                                                   const DownloadItem* right) {}

// static
bool DownloadQuery::MatchesQuery(const std::vector<std::u16string>& query_terms,
                                 const DownloadItem& item) {}

DownloadQuery::DownloadQuery() :{}
DownloadQuery::~DownloadQuery() {}

// AddFilter() pushes a new FilterCallback to filters_. Most FilterCallbacks are
// Callbacks to FieldMatches<>(). Search() iterates over given DownloadItems,
// discarding items for which any filter returns false. A DownloadQuery may have
// zero or more FilterCallbacks.

bool DownloadQuery::AddFilter(const DownloadQuery::FilterCallback& value) {}

void DownloadQuery::AddFilter(DownloadItem::DownloadState state) {}

void DownloadQuery::AddFilter(DownloadDangerType danger) {}

bool DownloadQuery::AddFilter(DownloadQuery::FilterType type,
                              const base::Value& value) {}

bool DownloadQuery::Matches(const DownloadItem& item) const {}

void DownloadQuery::AddSorter(DownloadQuery::SortType type,
                              DownloadQuery::SortDirection direction) {}

void DownloadQuery::FinishSearch(DownloadQuery::DownloadVector* results) const {}