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 { ...@@ -43,11 +43,11 @@ public final class ProfileImpl extends IProfile.Stub {
} }
@Override @Override
public void clearBrowsingData(@NonNull @BrowsingDataType int[] dataTypes, public void clearBrowsingData(@NonNull @BrowsingDataType int[] dataTypes, long fromMillis,
@NonNull IObjectWrapper completionCallback) { long toMillis, @NonNull IObjectWrapper completionCallback) {
Runnable callback = ObjectWrapper.unwrap(completionCallback, Runnable.class); Runnable callback = ObjectWrapper.unwrap(completionCallback, Runnable.class);
ProfileImplJni.get().clearBrowsingData( ProfileImplJni.get().clearBrowsingData(
mNativeProfile, mapBrowsingDataTypes(dataTypes), callback); mNativeProfile, mapBrowsingDataTypes(dataTypes), fromMillis, toMillis, callback);
} }
private static @ImplBrowsingDataType int[] mapBrowsingDataTypes( private static @ImplBrowsingDataType int[] mapBrowsingDataTypes(
...@@ -78,7 +78,7 @@ public final class ProfileImpl extends IProfile.Stub { ...@@ -78,7 +78,7 @@ public final class ProfileImpl extends IProfile.Stub {
interface Natives { interface Natives {
long createProfile(String path); long createProfile(String path);
void deleteProfile(long profile); void deleteProfile(long profile);
void clearBrowsingData( void clearBrowsingData(long nativeProfileImpl, @ImplBrowsingDataType int[] dataTypes,
long nativeProfileImpl, @ImplBrowsingDataType int[] dataTypes, Runnable callback); long fromMillis, long toMillis, Runnable callback);
} }
} }
...@@ -7,7 +7,8 @@ package org.chromium.weblayer_private.aidl; ...@@ -7,7 +7,8 @@ package org.chromium.weblayer_private.aidl;
interface IProfile { interface IProfile {
void destroy() = 0; 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; String getPath() = 2;
} }
...@@ -9,4 +9,4 @@ package org.chromium.weblayer_private.aidl; ...@@ -9,4 +9,4 @@ package org.chromium.weblayer_private.aidl;
* *
* Whenever any AIDL file is changed, sVersionNumber must be incremented. * 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 @@ ...@@ -5,7 +5,7 @@
#include "weblayer/browser/profile_impl.h" #include "weblayer/browser/profile_impl.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback_forward.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browsing_data_remover.h" #include "content/public/browser/browsing_data_remover.h"
...@@ -172,12 +172,13 @@ class ProfileImpl::DataClearer : public content::BrowsingDataRemover::Observer { ...@@ -172,12 +172,13 @@ class ProfileImpl::DataClearer : public content::BrowsingDataRemover::Observer {
~DataClearer() override { remover_->RemoveObserver(this); } ~DataClearer() override { remover_->RemoveObserver(this); }
void ClearData(int mask) { void ClearData(int mask,
base::Time from_time,
base::Time to_time) {
int origin_types = int origin_types =
content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB | content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB |
content::BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB; content::BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB;
remover_->RemoveAndReply(base::Time(), base::Time::Max(), mask, remover_->RemoveAndReply(from_time, to_time, mask, origin_types, this);
origin_types, this);
} }
void OnBrowsingDataRemoverDone() override { void OnBrowsingDataRemoverDone() override {
...@@ -202,8 +203,11 @@ content::BrowserContext* ProfileImpl::GetBrowserContext() { ...@@ -202,8 +203,11 @@ content::BrowserContext* ProfileImpl::GetBrowserContext() {
return browser_context_.get(); return browser_context_.get();
} }
void ProfileImpl::ClearBrowsingData(std::vector<BrowsingDataType> data_types, void ProfileImpl::ClearBrowsingData(
base::OnceCallback<void()> callback) { 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)); auto* clearer = new DataClearer(browser_context_.get(), std::move(callback));
// DataClearer will delete itself in OnBrowsingDataRemoverDone(). // DataClearer will delete itself in OnBrowsingDataRemoverDone().
// If Profile is destroyed during clearing, it would lead to destroying // If Profile is destroyed during clearing, it would lead to destroying
...@@ -226,7 +230,7 @@ void ProfileImpl::ClearBrowsingData(std::vector<BrowsingDataType> data_types, ...@@ -226,7 +230,7 @@ void ProfileImpl::ClearBrowsingData(std::vector<BrowsingDataType> data_types,
NOTREACHED(); NOTREACHED();
} }
} }
clearer->ClearData(remove_mask); clearer->ClearData(remove_mask, from_time, to_time);
} }
std::unique_ptr<Profile> Profile::Create(const base::FilePath& path) { std::unique_ptr<Profile> Profile::Create(const base::FilePath& path) {
...@@ -251,6 +255,8 @@ static void JNI_ProfileImpl_DeleteProfile(JNIEnv* env, jlong profile) { ...@@ -251,6 +255,8 @@ static void JNI_ProfileImpl_DeleteProfile(JNIEnv* env, jlong profile) {
void ProfileImpl::ClearBrowsingData( void ProfileImpl::ClearBrowsingData(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jintArray>& j_data_types, 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) { const base::android::JavaRef<jobject>& j_callback) {
std::vector<int> data_type_ints; std::vector<int> data_type_ints;
base::android::JavaIntArrayToIntVector(env, j_data_types, &data_type_ints); base::android::JavaIntArrayToIntVector(env, j_data_types, &data_type_ints);
...@@ -261,6 +267,8 @@ void ProfileImpl::ClearBrowsingData( ...@@ -261,6 +267,8 @@ void ProfileImpl::ClearBrowsingData(
} }
ClearBrowsingData( ClearBrowsingData(
data_types, 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::BindOnce(base::android::RunRunnableAndroid,
base::android::ScopedJavaGlobalRef<jobject>(j_callback))); base::android::ScopedJavaGlobalRef<jobject>(j_callback)));
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#ifndef WEBLAYER_BROWSER_PROFILE_IMPL_H_ #ifndef WEBLAYER_BROWSER_PROFILE_IMPL_H_
#define WEBLAYER_BROWSER_PROFILE_IMPL_H_ #define WEBLAYER_BROWSER_PROFILE_IMPL_H_
#include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -30,8 +29,10 @@ class ProfileImpl : public Profile { ...@@ -30,8 +29,10 @@ class ProfileImpl : public Profile {
content::BrowserContext* GetBrowserContext(); content::BrowserContext* GetBrowserContext();
// Profile implementation: // Profile implementation:
void ClearBrowsingData(std::vector<BrowsingDataType> data_types, void ClearBrowsingData(const std::vector<BrowsingDataType>& data_types,
base::OnceCallback<void()> callback) override; base::Time from_time,
base::Time to_time,
base::OnceClosure callback) override;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
ProfileImpl(JNIEnv* env, const base::android::JavaParamRef<jstring>& path); ProfileImpl(JNIEnv* env, const base::android::JavaParamRef<jstring>& path);
...@@ -39,6 +40,8 @@ class ProfileImpl : public Profile { ...@@ -39,6 +40,8 @@ class ProfileImpl : public Profile {
void ClearBrowsingData( void ClearBrowsingData(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jintArray>& j_data_types, 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); const base::android::JavaRef<jobject>& j_callback);
#endif #endif
......
...@@ -66,22 +66,36 @@ public final class Profile { ...@@ -66,22 +66,36 @@ public final class Profile {
* call this method repeatedly without waiting for callback. * call this method repeatedly without waiting for callback.
* *
* @param dataTypes See {@link BrowsingDataType}. * @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 * @return {@link ListenableResult} into which a "null" will be supplied when clearing is
* finished. * finished.
*/ */
@NonNull @NonNull
public ListenableResult<Void> clearBrowsingData(@NonNull @BrowsingDataType int[] dataTypes) { public ListenableResult<Void> clearBrowsingData(
@NonNull @BrowsingDataType int[] dataTypes, long fromMillis, long toMillis) {
ThreadCheck.ensureOnUiThread(); ThreadCheck.ensureOnUiThread();
try { try {
ListenableResult<Void> result = new ListenableResult<>(); ListenableResult<Void> result = new ListenableResult<>();
mImpl.clearBrowsingData( mImpl.clearBrowsingData(dataTypes, fromMillis, toMillis,
dataTypes, ObjectWrapper.wrap((Runnable) () -> result.supplyResult(null))); ObjectWrapper.wrap((Runnable) () -> result.supplyResult(null)));
return result; return result;
} catch (RemoteException e) { } catch (RemoteException e) {
throw new APICallException(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() { public void destroy() {
ThreadCheck.ensureOnUiThread(); ThreadCheck.ensureOnUiThread();
try { try {
......
...@@ -26,9 +26,11 @@ class Profile { ...@@ -26,9 +26,11 @@ class Profile {
virtual ~Profile() {} virtual ~Profile() {}
// TODO: add parameters to control which time range gets deleted. virtual void ClearBrowsingData(
virtual void ClearBrowsingData(std::vector<BrowsingDataType> data_types, const std::vector<BrowsingDataType>& data_types,
base::OnceCallback<void()> callback) = 0; base::Time from_time,
base::Time to_time,
base::OnceClosure callback) = 0;
}; };
} // namespace weblayer } // 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