Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Unified Diff: chrome/browser/android/webapps/webapp_registry.cc

Issue 2397623004: Revert of [Reland] Refactor WebappRegistry into a singleton instance. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/webapps/webapp_registry.cc
diff --git a/chrome/browser/android/webapps/webapp_registry.cc b/chrome/browser/android/webapps/webapp_registry.cc
index bb909c8cade7991cfb36e0146ed2dcea4282fdf2..3b3616b142f69c75176d988117f40d85d984b678 100644
--- a/chrome/browser/android/webapps/webapp_registry.cc
+++ b/chrome/browser/android/webapps/webapp_registry.cc
@@ -4,26 +4,70 @@
#include "chrome/browser/android/webapps/webapp_registry.h"
+#include <jni.h>
+
+#include "base/android/context_utils.h"
#include "base/android/jni_android.h"
+#include "base/callback.h"
#include "chrome/browser/android/browsing_data/url_filter_bridge.h"
+#include "chrome/browser/io_thread.h"
+#include "content/public/browser/browser_thread.h"
#include "jni/WebappRegistry_jni.h"
using base::android::JavaParamRef;
void WebappRegistry::UnregisterWebappsForUrls(
- const base::Callback<bool(const GURL&)>& url_filter) {
- // |filter_bridge| is destroyed from its Java counterpart.
+ const base::Callback<bool(const GURL&)>& url_filter,
+ const base::Closure& callback) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ // TODO(msramek): Consider implementing a wrapper class that will call and
+ // destroy this closure from Java, eliminating the need for
+ // OnWebappsUnregistered() and OnClearedWebappHistory() callbacks.
+ uintptr_t callback_pointer = reinterpret_cast<uintptr_t>(
+ new base::Closure(callback));
+
+ // We will destroy |filter_bridge| from its Java counterpart before calling
+ // back OnWebappsUnregistered().
UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter);
- Java_WebappRegistry_unregisterWebappsForUrls(
- base::android::AttachCurrentThread(), filter_bridge->j_bridge());
+ Java_WebappRegistry_unregisterWebappsForUrls(env, filter_bridge->j_bridge(),
+ callback_pointer);
}
void WebappRegistry::ClearWebappHistoryForUrls(
- const base::Callback<bool(const GURL&)>& url_filter) {
- // |filter_bridge| is destroyed from its Java counterpart.
+ const base::Callback<bool(const GURL&)>& url_filter,
+ const base::Closure& callback) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ uintptr_t callback_pointer = reinterpret_cast<uintptr_t>(
+ new base::Closure(callback));
+
+ // We will destroy |filter_bridge| from its Java counterpart before calling
+ // back OnClearedWebappHistory().
UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter);
- Java_WebappRegistry_clearWebappHistoryForUrls(
- base::android::AttachCurrentThread(), filter_bridge->j_bridge());
+ Java_WebappRegistry_clearWebappHistoryForUrls(env, filter_bridge->j_bridge(),
+ callback_pointer);
}
+
+// Callback used by Java when all web apps have been unregistered.
+void OnWebappsUnregistered(JNIEnv* env,
+ const JavaParamRef<jclass>& clazz,
+ jlong jcallback) {
+ base::Closure* callback = reinterpret_cast<base::Closure*>(jcallback);
+ callback->Run();
+ delete callback;
+}
+
+// Callback used by Java when all web app last used times have been cleared.
+void OnClearedWebappHistory(JNIEnv* env,
+ const JavaParamRef<jclass>& clazz,
+ jlong jcallback) {
+ base::Closure* callback = reinterpret_cast<base::Closure*>(jcallback);
+ callback->Run();
+ delete callback;
+}
+
+// static
+bool WebappRegistry::RegisterWebappRegistry(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
« no previous file with comments | « chrome/browser/android/webapps/webapp_registry.h ('k') | chrome/browser/browsing_data/browsing_data_remover.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698