#include "chrome/browser/share/share_history.h"
#include "base/containers/flat_map.h"
#include "base/memory/ptr_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/share/proto/share_history_message.pb.h"
#include "components/leveldb_proto/public/proto_database_provider.h"
#include "content/public/browser/storage_partition.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/jni_string.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/share/jni_headers/ShareHistoryBridge_jni.h"
using base::android::JavaParamRef;
#endif
namespace sharing {
namespace {
const char* const kShareHistoryFolder = …;
const char* const kShareHistoryKey = …;
constexpr auto kMaxHistoryAge = …;
int TodaysDay() { … }
std::unique_ptr<ShareHistory::BackingDb> MakeDefaultDbForProfile(
Profile* profile) { … }
bool DayOverlapsTimeRange(base::Time day_start,
base::Time start,
base::Time end) { … }
}
void ShareHistory::CreateForProfile(Profile* profile) { … }
ShareHistory* ShareHistory::Get(Profile* profile) { … }
ShareHistory::~ShareHistory() = default;
ShareHistory::ShareHistory() = default;
ShareHistory::ShareHistory(Profile* profile,
std::unique_ptr<BackingDb> backing_db)
: … { … }
void ShareHistory::AddShareEntry(const std::string& component_name) { … }
void ShareHistory::GetFlatShareHistory(GetFlatHistoryCallback callback,
int window) { … }
void ShareHistory::Clear(const base::Time& start, const base::Time& end) { … }
void ShareHistory::Init() { … }
void ShareHistory::OnInitDone(leveldb_proto::Enums::InitStatus status) { … }
void ShareHistory::OnInitialReadDone(
bool ok,
std::unique_ptr<mojom::ShareHistory> history) { … }
void ShareHistory::FlushToBackingDb() { … }
mojom::DayShareHistory* ShareHistory::DayShareHistoryForToday() { … }
mojom::TargetShareHistory* ShareHistory::TargetShareHistoryByName(
mojom::DayShareHistory* history,
const std::string& target_name) { … }
}
#if BUILDFLAG(IS_ANDROID)
void JNI_ShareHistoryBridge_AddShareEntry(JNIEnv* env,
Profile* profile,
const JavaParamRef<jstring>& name) {
auto* instance = sharing::ShareHistory::Get(profile);
if (instance)
instance->AddShareEntry(base::android::ConvertJavaStringToUTF8(env, name));
}
void JNI_ShareHistoryBridge_Clear(JNIEnv* env, Profile* profile) {
auto* instance = sharing::ShareHistory::Get(profile);
if (instance)
instance->Clear();
}
#endif