#include "chrome/browser/extensions/activity_log/counting_policy.h"
#include <stddef.h>
#include <map>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/json/json_reader.h"
#include "base/json/json_string_value_serializer.h"
#include "base/memory/ptr_util.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/extensions/activity_log/activity_log_task_runner.h"
#include "chrome/common/chrome_constants.h"
#include "sql/statement.h"
#include "sql/transaction.h"
namespace {
Action;
constexpr base::TimeDelta kCleaningDelay = …;
struct ApiList { … };
const ApiList kAlwaysLog[] = …;
const char* const kTableContentFields[] = …;
const char* const kTableFieldTypes[] = …;
static const char kPolicyMiscSetup[] = …
"DROP VIEW IF EXISTS activitylog_uncompressed;\n"
"CREATE VIEW activitylog_uncompressed AS\n"
"SELECT count,\n"
" x1.value AS extension_id,\n"
" time,\n"
" action_type,\n"
" x2.value AS api_name,\n"
" x3.value AS args,\n"
" x4.value AS page_url,\n"
" x5.value AS page_title,\n"
" x6.value AS arg_url,\n"
" x7.value AS other,\n"
" activitylog_compressed.rowid AS activity_id\n"
"FROM activitylog_compressed\n"
" LEFT JOIN string_ids AS x1 ON (x1.id = extension_id_x)\n"
" LEFT JOIN string_ids AS x2 ON (x2.id = api_name_x)\n"
" LEFT JOIN string_ids AS x3 ON (x3.id = args_x)\n"
" LEFT JOIN url_ids AS x4 ON (x4.id = page_url_x)\n"
" LEFT JOIN string_ids AS x5 ON (x5.id = page_title_x)\n"
" LEFT JOIN url_ids AS x6 ON (x6.id = arg_url_x)\n"
" LEFT JOIN string_ids AS x7 ON (x7.id = other_x);\n"
"CREATE INDEX IF NOT EXISTS activitylog_compressed_index\n"
"ON activitylog_compressed(extension_id_x, action_type, api_name_x,\n"
" args_x, page_url_x, page_title_x, arg_url_x, other_x)";
static const char kStringTableCleanup[] = …;
static const char kUrlTableCleanup[] = …;
}
namespace extensions {
const char CountingPolicy::kReadViewName[] = …;
CountingPolicy::CountingPolicy(Profile* profile)
: … { … }
CountingPolicy::~CountingPolicy() { … }
bool CountingPolicy::InitDatabase(sql::Database* db) { … }
void CountingPolicy::ProcessAction(scoped_refptr<Action> action) { … }
void CountingPolicy::QueueAction(scoped_refptr<Action> action) { … }
bool CountingPolicy::FlushDatabase(sql::Database* db) { … }
std::unique_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData(
const std::string& extension_id,
const Action::ActionType type,
const std::string& api_name,
const std::string& page_url,
const std::string& arg_url,
const int days_ago) { … }
void CountingPolicy::DoRemoveActions(const std::vector<int64_t>& action_ids) { … }
void CountingPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) { … }
void CountingPolicy::DoRemoveExtensionData(const std::string& extension_id) { … }
void CountingPolicy::DoDeleteDatabase() { … }
void CountingPolicy::ReadFilteredData(
const std::string& extension_id,
const Action::ActionType type,
const std::string& api_name,
const std::string& page_url,
const std::string& arg_url,
const int days_ago,
base::OnceCallback<void(std::unique_ptr<Action::ActionVector>)> callback) { … }
void CountingPolicy::RemoveActions(const std::vector<int64_t>& action_ids) { … }
void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { … }
void CountingPolicy::RemoveExtensionData(const std::string& extension_id) { … }
void CountingPolicy::DeleteDatabase() { … }
void CountingPolicy::OnDatabaseFailure() { … }
void CountingPolicy::OnDatabaseClose() { … }
bool CountingPolicy::CleanOlderThan(sql::Database* db,
const base::Time& cutoff) { … }
bool CountingPolicy::CleanStringTables(sql::Database* db) { … }
void CountingPolicy::Close() { … }
}