1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_USAGE_STATS_USAGE_STATS_BRIDGE_H_
#define CHROME_BROWSER_ANDROID_USAGE_STATS_USAGE_STATS_BRIDGE_H_
#include <memory>
#include <string>
#include <vector>
#include "base/android/scoped_java_ref.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "chrome/browser/android/usage_stats/usage_stats_database.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/history_service_observer.h"
namespace history {
class HistoryService;
}
namespace user_prefs {
class PrefRegistrySyncable;
}
namespace usage_stats {
using base::android::JavaParamRef;
using base::android::JavaRef;
using base::android::ScopedJavaGlobalRef;
/* Native counterpart of UsageStatsBridge.java. Holds non-owning pointers to
* native implementation to which operations are delegated. This bridge is
* instantiated, owned, and destroyed from Java.
*/
class UsageStatsBridge : public history::HistoryServiceObserver {
public:
explicit UsageStatsBridge(
std::unique_ptr<UsageStatsDatabase> usage_stats_database,
Profile* profile,
const JavaRef<jobject>& j_this);
UsageStatsBridge(const UsageStatsBridge&) = delete;
UsageStatsBridge& operator=(const UsageStatsBridge&) = delete;
~UsageStatsBridge() override;
void Destroy(JNIEnv* j_env, const JavaRef<jobject>& j_this);
void GetAllEvents(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jobject>& j_callback);
void QueryEventsInRange(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const jlong j_start,
const jlong j_end,
const JavaRef<jobject>& j_callback);
void AddEvents(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jobjectArray>& j_events,
const JavaRef<jobject>& j_callback);
void DeleteAllEvents(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jobject>& j_callback);
void DeleteEventsInRange(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const jlong j_start,
const jlong j_end,
const JavaRef<jobject>& j_callback);
void DeleteEventsWithMatchingDomains(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jobjectArray>& j_domains,
const JavaRef<jobject>& j_callback);
void GetAllSuspensions(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jobject>& j_callback);
void SetSuspensions(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jobjectArray>& j_domains,
const JavaRef<jobject>& j_callback);
void GetAllTokenMappings(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jobject>& j_callback);
void SetTokenMappings(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jobjectArray>& j_tokens,
const JavaRef<jobjectArray>& j_fqdns,
const JavaRef<jobject>& j_callback);
// Overridden from history::HistoryServiceObserver.
void OnHistoryDeletions(history::HistoryService* history_service,
const history::DeletionInfo& deletion_info) override;
void HistoryServiceBeingDeleted(
history::HistoryService* history_service) override;
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
private:
void OnGetEventsDone(ScopedJavaGlobalRef<jobject> callback,
UsageStatsDatabase::Error error,
std::vector<WebsiteEvent> events);
void OnGetAllSuspensionsDone(ScopedJavaGlobalRef<jobject> callback,
UsageStatsDatabase::Error error,
std::vector<std::string> suspensions);
void OnGetAllTokenMappingsDone(ScopedJavaGlobalRef<jobject> callback,
UsageStatsDatabase::Error error,
UsageStatsDatabase::TokenMap mappings);
void OnUpdateDone(ScopedJavaGlobalRef<jobject> callback,
UsageStatsDatabase::Error error);
std::unique_ptr<UsageStatsDatabase> usage_stats_database_;
raw_ptr<Profile> profile_;
base::android::ScopedJavaGlobalRef<jobject> j_this_;
base::ScopedObservation<history::HistoryService,
history::HistoryServiceObserver>
scoped_history_service_observer_{this};
base::WeakPtrFactory<UsageStatsBridge> weak_ptr_factory_{this};
};
} // namespace usage_stats
#endif // CHROME_BROWSER_ANDROID_USAGE_STATS_USAGE_STATS_BRIDGE_H_
|