chromium/components/offline_pages/core/model/get_pages_task.cc

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

#include "components/offline_pages/core/model/get_pages_task.h"

#include <algorithm>
#include <string>
#include <utility>

#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "components/offline_pages/core/offline_page_client_policy.h"
#include "components/offline_pages/core/offline_page_item_utils.h"
#include "components/offline_pages/core/offline_store_utils.h"
#include "sql/database.h"
#include "sql/statement.h"
#include "sql/transaction.h"
#include "url/gurl.h"

namespace offline_pages {
namespace {

ReadResult;

#define OFFLINE_PAGE_PROJECTION

ClientId OfflinePageClientId(sql::Statement& statement) {}

// Create an offline page item from a SQL result.
// Expects the order of columns as defined by OFFLINE_PAGE_PROJECTION macro.
OfflinePageItem MakeOfflinePageItem(sql::Statement& statement) {}

// Returns a pattern to be used in an SQLite LIKE expression to match a
// a URL ignoring the fragment. Warning: this match produces false positives,
// so the URL match must be verified by doing
// UrlWithoutFragment(a)==UrlWithoutFragment(b).
std::string RelaxedLikePattern(const GURL& url) {}

}  // namespace

GetPagesTask::ReadResult::ReadResult() = default;
GetPagesTask::ReadResult::ReadResult(const ReadResult& other) = default;
GetPagesTask::ReadResult::~ReadResult() = default;

GetPagesTask::GetPagesTask(OfflinePageMetadataStore* store,
                           const PageCriteria& criteria,
                           MultipleOfflinePageItemCallback callback)
    :{}

GetPagesTask::~GetPagesTask() = default;

void GetPagesTask::Run() {}

void GetPagesTask::CompleteWithResult(ReadResult result) {}

// Some comments on query performance as of March 2019:
// - SQLite stores data in row-oriented fashion, so there's little cost to
//   querying additional columns.
// - SQLite supports REGEXP, but it's slow, seems hardly worth using. LIKE is
//   fast.
// - Adding more simple conditions to the WHERE clause seems to hardly increase
//   runtime, so it's advantageous to add new conditions if they are likely to
//   eliminate output.
// - When a single item is returned from a query, using a WHERE clause is about
//   10x faster compared to just querying all rows and filtering the output in
//   C++.
// - The below query can process 10K rows in ~1ms (in-memory db).
// - If offline_id is in criteria, SQLite will use the index to evaluate the
//   query quickly. Otherwise, we need to read the whole table anyway. Unless
//   the db is loaded to memory, and disk access will likely dwarf any
//   other query optimizations.
ReadResult GetPagesTask::ReadPagesWithCriteriaSync(
    const PageCriteria& criteria,
    sql::Database* db) {}

}  // namespace offline_pages