Commit b5ac7229 authored by Pavel Shmakov's avatar Pavel Shmakov Committed by Commit Bot

Add time range to clear data API

Change-Id: Ib9fc6ab6deaa75a4a668b4a18cfc4650a1ce69d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1897655
Commit-Queue: Pavel Shmakov <pshmakov@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712532}
parent d81a214d
......@@ -43,11 +43,11 @@ public final class ProfileImpl extends IProfile.Stub {
}
@Override
public void clearBrowsingData(@NonNull @BrowsingDataType int[] dataTypes,
@NonNull IObjectWrapper completionCallback) {
public void clearBrowsingData(@NonNull @BrowsingDataType int[] dataTypes, long fromMillis,
long toMillis, @NonNull IObjectWrapper completionCallback) {
Runnable callback = ObjectWrapper.unwrap(completionCallback, Runnable.class);
ProfileImplJni.get().clearBrowsingData(
mNativeProfile, mapBrowsingDataTypes(dataTypes), callback);
mNativeProfile, mapBrowsingDataTypes(dataTypes), fromMillis, toMillis, callback);
}
private static @ImplBrowsingDataType int[] mapBrowsingDataTypes(
......@@ -78,7 +78,7 @@ public final class ProfileImpl extends IProfile.Stub {
interface Natives {
long createProfile(String path);
void deleteProfile(long profile);
void clearBrowsingData(
long nativeProfileImpl, @ImplBrowsingDataType int[] dataTypes, Runnable callback);
void clearBrowsingData(long nativeProfileImpl, @ImplBrowsingDataType int[] dataTypes,
long fromMillis, long toMillis, Runnable callback);
}
}
......@@ -7,7 +7,8 @@ package org.chromium.weblayer_private.aidl;
interface IProfile {
void destroy() = 0;
void clearBrowsingData(in int[] dataTypes, in IObjectWrapper completionCallback) = 1;
void clearBrowsingData(in int[] dataTypes, long fromMillis, long toMillis,
in IObjectWrapper completionCallback) = 1;
String getPath() = 2;
}
......@@ -9,4 +9,4 @@ package org.chromium.weblayer_private.aidl;
*
* Whenever any AIDL file is changed, sVersionNumber must be incremented.
* */
public final class WebLayerVersion { public static int sVersionNumber = 5; }
public final class WebLayerVersion { public static int sVersionNumber = 6; }
......@@ -5,7 +5,7 @@
#include "weblayer/browser/profile_impl.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/callback_forward.h"
#include "build/build_config.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browsing_data_remover.h"
......@@ -172,12 +172,13 @@ class ProfileImpl::DataClearer : public content::BrowsingDataRemover::Observer {
~DataClearer() override { remover_->RemoveObserver(this); }
void ClearData(int mask) {
void ClearData(int mask,
base::Time from_time,
base::Time to_time) {
int origin_types =
content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB |
content::BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB;
remover_->RemoveAndReply(base::Time(), base::Time::Max(), mask,
origin_types, this);
remover_->RemoveAndReply(from_time, to_time, mask, origin_types, this);
}
void OnBrowsingDataRemoverDone() override {
......@@ -202,8 +203,11 @@ content::BrowserContext* ProfileImpl::GetBrowserContext() {
return browser_context_.get();
}
void ProfileImpl::ClearBrowsingData(std::vector<BrowsingDataType> data_types,
base::OnceCallback<void()> callback) {
void ProfileImpl::ClearBrowsingData(
const std::vector<BrowsingDataType>& data_types,
base::Time from_time,
base::Time to_time,
base::OnceClosure callback) {
auto* clearer = new DataClearer(browser_context_.get(), std::move(callback));
// DataClearer will delete itself in OnBrowsingDataRemoverDone().
// If Profile is destroyed during clearing, it would lead to destroying
......@@ -226,7 +230,7 @@ void ProfileImpl::ClearBrowsingData(std::vector<BrowsingDataType> data_types,
NOTREACHED();
}
}
clearer->ClearData(remove_mask);
clearer->ClearData(remove_mask, from_time, to_time);
}
std::unique_ptr<Profile> Profile::Create(const base::FilePath& path) {
......@@ -251,6 +255,8 @@ static void JNI_ProfileImpl_DeleteProfile(JNIEnv* env, jlong profile) {
void ProfileImpl::ClearBrowsingData(
JNIEnv* env,
const base::android::JavaParamRef<jintArray>& j_data_types,
const jlong j_from_time_millis,
const jlong j_to_time_millis,
const base::android::JavaRef<jobject>& j_callback) {
std::vector<int> data_type_ints;
base::android::JavaIntArrayToIntVector(env, j_data_types, &data_type_ints);
......@@ -261,6 +267,8 @@ void ProfileImpl::ClearBrowsingData(
}
ClearBrowsingData(
data_types,
base::Time::FromJavaTime(static_cast<int64_t>(j_from_time_millis)),
base::Time::FromJavaTime(static_cast<int64_t>(j_to_time_millis)),
base::BindOnce(base::android::RunRunnableAndroid,
base::android::ScopedJavaGlobalRef<jobject>(j_callback)));
}
......
......@@ -5,7 +5,6 @@
#ifndef WEBLAYER_BROWSER_PROFILE_IMPL_H_
#define WEBLAYER_BROWSER_PROFILE_IMPL_H_
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "build/build_config.h"
......@@ -30,8 +29,10 @@ class ProfileImpl : public Profile {
content::BrowserContext* GetBrowserContext();
// Profile implementation:
void ClearBrowsingData(std::vector<BrowsingDataType> data_types,
base::OnceCallback<void()> callback) override;
void ClearBrowsingData(const std::vector<BrowsingDataType>& data_types,
base::Time from_time,
base::Time to_time,
base::OnceClosure callback) override;
#if defined(OS_ANDROID)
ProfileImpl(JNIEnv* env, const base::android::JavaParamRef<jstring>& path);
......@@ -39,6 +40,8 @@ class ProfileImpl : public Profile {
void ClearBrowsingData(
JNIEnv* env,
const base::android::JavaParamRef<jintArray>& j_data_types,
const jlong j_from_time_millis,
const jlong j_to_time_millis,
const base::android::JavaRef<jobject>& j_callback);
#endif
......
......@@ -66,22 +66,36 @@ public final class Profile {
* call this method repeatedly without waiting for callback.
*
* @param dataTypes See {@link BrowsingDataType}.
* @param fromMillis Defines the start (in milliseconds since epoch) of the time range to clear.
* @param toMillis Defines the end (in milliseconds since epoch) of the time range to clear.
* For clearing all data prefer using {@link Long#MAX_VALUE} to
* {@link System.currentTimeMillis()} to take into account possible system clock changes.
* @return {@link ListenableResult} into which a "null" will be supplied when clearing is
* finished.
*/
@NonNull
public ListenableResult<Void> clearBrowsingData(@NonNull @BrowsingDataType int[] dataTypes) {
public ListenableResult<Void> clearBrowsingData(
@NonNull @BrowsingDataType int[] dataTypes, long fromMillis, long toMillis) {
ThreadCheck.ensureOnUiThread();
try {
ListenableResult<Void> result = new ListenableResult<>();
mImpl.clearBrowsingData(
dataTypes, ObjectWrapper.wrap((Runnable) () -> result.supplyResult(null)));
mImpl.clearBrowsingData(dataTypes, fromMillis, toMillis,
ObjectWrapper.wrap((Runnable) () -> result.supplyResult(null)));
return result;
} catch (RemoteException e) {
throw new APICallException(e);
}
}
/**
* Clears the data associated with the Profile.
* Same as {@link #clearBrowsingData(int[], long, long)} with unbounded time range.
*/
@NonNull
public ListenableResult<Void> clearBrowsingData(@NonNull @BrowsingDataType int[] dataTypes) {
return clearBrowsingData(dataTypes, 0, Long.MAX_VALUE);
}
public void destroy() {
ThreadCheck.ensureOnUiThread();
try {
......
......@@ -26,9 +26,11 @@ class Profile {
virtual ~Profile() {}
// TODO: add parameters to control which time range gets deleted.
virtual void ClearBrowsingData(std::vector<BrowsingDataType> data_types,
base::OnceCallback<void()> callback) = 0;
virtual void ClearBrowsingData(
const std::vector<BrowsingDataType>& data_types,
base::Time from_time,
base::Time to_time,
base::OnceClosure callback) = 0;
};
} // namespace weblayer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment