Commit 838ef3b2 authored by Scott Violet's avatar Scott Violet Committed by Chromium LUCI CQ

android: makes HistoryDeletionBridge properly remove observer

It looks like HistoryDeletionBridge is never destroyed. This ensures
the observer it adds to HistoryService is properly cleaned up.

BUG=1158388
TEST=none

Change-Id: Idc2f65405d277bb3b58fe3e821472f581d7df1fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2613645Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840860}
parent b741ffa7
...@@ -36,22 +36,16 @@ history::DeletionInfo HistoryDeletionBridge::SanitizeDeletionInfo( ...@@ -36,22 +36,16 @@ history::DeletionInfo HistoryDeletionBridge::SanitizeDeletionInfo(
} }
HistoryDeletionBridge::HistoryDeletionBridge(const JavaRef<jobject>& jobj) HistoryDeletionBridge::HistoryDeletionBridge(const JavaRef<jobject>& jobj)
: jobj_(ScopedJavaGlobalRef<jobject>(jobj)), : jobj_(ScopedJavaGlobalRef<jobject>(jobj)) {
profile_(ProfileManager::GetLastUsedProfile()->GetOriginalProfile()) { Profile* profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile();
history::HistoryService* history_service = history::HistoryService* history_service =
HistoryServiceFactory::GetForProfile(profile_, HistoryServiceFactory::GetForProfile(profile,
ServiceAccessType::IMPLICIT_ACCESS); ServiceAccessType::IMPLICIT_ACCESS);
if (history_service) if (history_service)
history_service->AddObserver(this); scoped_history_service_observer_.Observe(history_service);
} }
HistoryDeletionBridge::~HistoryDeletionBridge() { HistoryDeletionBridge::~HistoryDeletionBridge() = default;
history::HistoryService* history_service =
HistoryServiceFactory::GetForProfile(profile_,
ServiceAccessType::IMPLICIT_ACCESS);
if (history_service)
history_service->RemoveObserver(this);
}
void HistoryDeletionBridge::OnURLsDeleted( void HistoryDeletionBridge::OnURLsDeleted(
history::HistoryService* history_service, history::HistoryService* history_service,
...@@ -62,3 +56,8 @@ void HistoryDeletionBridge::OnURLsDeleted( ...@@ -62,3 +56,8 @@ void HistoryDeletionBridge::OnURLsDeleted(
Java_HistoryDeletionBridge_onURLsDeleted( Java_HistoryDeletionBridge_onURLsDeleted(
env, jobj_, CreateHistoryDeletionInfo(env, &sanitized_info)); env, jobj_, CreateHistoryDeletionInfo(env, &sanitized_info));
} }
void HistoryDeletionBridge::HistoryServiceBeingDeleted(
history::HistoryService* history_service) {
scoped_history_service_observer_.Reset();
}
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#define CHROME_BROWSER_ANDROID_HISTORY_HISTORY_DELETION_BRIDGE_H_ #define CHROME_BROWSER_ANDROID_HISTORY_HISTORY_DELETION_BRIDGE_H_
#include "base/macros.h" #include "base/macros.h"
#include "base/scoped_observation.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/history_service_observer.h" #include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/history_types.h" #include "components/history/core/browser/history_types.h"
...@@ -13,8 +15,6 @@ namespace history { ...@@ -13,8 +15,6 @@ namespace history {
class HistoryService; class HistoryService;
} // namespace history } // namespace history
class Profile;
// Native counterpart of HistoryDeletionBridge.java. Receives history deletion // Native counterpart of HistoryDeletionBridge.java. Receives history deletion
// events that originate in native code and forwards them to Java. // events that originate in native code and forwards them to Java.
class HistoryDeletionBridge : public history::HistoryServiceObserver { class HistoryDeletionBridge : public history::HistoryServiceObserver {
...@@ -24,6 +24,8 @@ class HistoryDeletionBridge : public history::HistoryServiceObserver { ...@@ -24,6 +24,8 @@ class HistoryDeletionBridge : public history::HistoryServiceObserver {
// history::HistoryServiceObserver. // history::HistoryServiceObserver.
void OnURLsDeleted(history::HistoryService* history_service, void OnURLsDeleted(history::HistoryService* history_service,
const history::DeletionInfo& deletion_info) override; const history::DeletionInfo& deletion_info) override;
void HistoryServiceBeingDeleted(
history::HistoryService* history_service) override;
// Sanitize the DeletionInfo of empty/invalid urls before passing to java. // Sanitize the DeletionInfo of empty/invalid urls before passing to java.
// Fix for empty java strings being passed to the content capture service // Fix for empty java strings being passed to the content capture service
...@@ -37,7 +39,9 @@ class HistoryDeletionBridge : public history::HistoryServiceObserver { ...@@ -37,7 +39,9 @@ class HistoryDeletionBridge : public history::HistoryServiceObserver {
// Reference to the Java half of this bridge. Always valid. // Reference to the Java half of this bridge. Always valid.
base::android::ScopedJavaGlobalRef<jobject> jobj_; base::android::ScopedJavaGlobalRef<jobject> jobj_;
Profile* profile_; base::ScopedObservation<history::HistoryService,
history::HistoryServiceObserver>
scoped_history_service_observer_{this};
DISALLOW_COPY_AND_ASSIGN(HistoryDeletionBridge); DISALLOW_COPY_AND_ASSIGN(HistoryDeletionBridge);
}; };
......
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