OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/android/webapps/webapp_registry.h" | 5 #include "chrome/browser/android/webapps/webapp_registry.h" |
6 | 6 |
| 7 #include <jni.h> |
| 8 |
| 9 #include "base/android/context_utils.h" |
7 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| 11 #include "base/callback.h" |
8 #include "chrome/browser/android/browsing_data/url_filter_bridge.h" | 12 #include "chrome/browser/android/browsing_data/url_filter_bridge.h" |
| 13 #include "chrome/browser/io_thread.h" |
| 14 #include "content/public/browser/browser_thread.h" |
9 #include "jni/WebappRegistry_jni.h" | 15 #include "jni/WebappRegistry_jni.h" |
10 | 16 |
11 using base::android::JavaParamRef; | 17 using base::android::JavaParamRef; |
12 | 18 |
13 void WebappRegistry::UnregisterWebappsForUrls( | 19 void WebappRegistry::UnregisterWebappsForUrls( |
14 const base::Callback<bool(const GURL&)>& url_filter) { | 20 const base::Callback<bool(const GURL&)>& url_filter, |
15 // |filter_bridge| is destroyed from its Java counterpart. | 21 const base::Closure& callback) { |
| 22 JNIEnv* env = base::android::AttachCurrentThread(); |
| 23 // TODO(msramek): Consider implementing a wrapper class that will call and |
| 24 // destroy this closure from Java, eliminating the need for |
| 25 // OnWebappsUnregistered() and OnClearedWebappHistory() callbacks. |
| 26 uintptr_t callback_pointer = reinterpret_cast<uintptr_t>( |
| 27 new base::Closure(callback)); |
| 28 |
| 29 // We will destroy |filter_bridge| from its Java counterpart before calling |
| 30 // back OnWebappsUnregistered(). |
16 UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter); | 31 UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter); |
17 | 32 |
18 Java_WebappRegistry_unregisterWebappsForUrls( | 33 Java_WebappRegistry_unregisterWebappsForUrls(env, filter_bridge->j_bridge(), |
19 base::android::AttachCurrentThread(), filter_bridge->j_bridge()); | 34 callback_pointer); |
20 } | 35 } |
21 | 36 |
22 void WebappRegistry::ClearWebappHistoryForUrls( | 37 void WebappRegistry::ClearWebappHistoryForUrls( |
23 const base::Callback<bool(const GURL&)>& url_filter) { | 38 const base::Callback<bool(const GURL&)>& url_filter, |
24 // |filter_bridge| is destroyed from its Java counterpart. | 39 const base::Closure& callback) { |
| 40 JNIEnv* env = base::android::AttachCurrentThread(); |
| 41 uintptr_t callback_pointer = reinterpret_cast<uintptr_t>( |
| 42 new base::Closure(callback)); |
| 43 |
| 44 // We will destroy |filter_bridge| from its Java counterpart before calling |
| 45 // back OnClearedWebappHistory(). |
25 UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter); | 46 UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter); |
26 | 47 |
27 Java_WebappRegistry_clearWebappHistoryForUrls( | 48 Java_WebappRegistry_clearWebappHistoryForUrls(env, filter_bridge->j_bridge(), |
28 base::android::AttachCurrentThread(), filter_bridge->j_bridge()); | 49 callback_pointer); |
29 } | 50 } |
| 51 |
| 52 // Callback used by Java when all web apps have been unregistered. |
| 53 void OnWebappsUnregistered(JNIEnv* env, |
| 54 const JavaParamRef<jclass>& clazz, |
| 55 jlong jcallback) { |
| 56 base::Closure* callback = reinterpret_cast<base::Closure*>(jcallback); |
| 57 callback->Run(); |
| 58 delete callback; |
| 59 } |
| 60 |
| 61 // Callback used by Java when all web app last used times have been cleared. |
| 62 void OnClearedWebappHistory(JNIEnv* env, |
| 63 const JavaParamRef<jclass>& clazz, |
| 64 jlong jcallback) { |
| 65 base::Closure* callback = reinterpret_cast<base::Closure*>(jcallback); |
| 66 callback->Run(); |
| 67 delete callback; |
| 68 } |
| 69 |
| 70 // static |
| 71 bool WebappRegistry::RegisterWebappRegistry(JNIEnv* env) { |
| 72 return RegisterNativesImpl(env); |
| 73 } |
OLD | NEW |