| 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> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // TODO(msramek): Consider implementing a wrapper class that will call and | 23 // TODO(msramek): Consider implementing a wrapper class that will call and |
| 24 // destroy this closure from Java, eliminating the need for | 24 // destroy this closure from Java, eliminating the need for |
| 25 // OnWebappsUnregistered() and OnClearedWebappHistory() callbacks. | 25 // OnWebappsUnregistered() and OnClearedWebappHistory() callbacks. |
| 26 uintptr_t callback_pointer = reinterpret_cast<uintptr_t>( | 26 uintptr_t callback_pointer = reinterpret_cast<uintptr_t>( |
| 27 new base::Closure(callback)); | 27 new base::Closure(callback)); |
| 28 | 28 |
| 29 // We will destroy |filter_bridge| from its Java counterpart before calling | 29 // We will destroy |filter_bridge| from its Java counterpart before calling |
| 30 // back OnWebappsUnregistered(). | 30 // back OnWebappsUnregistered(). |
| 31 UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter); | 31 UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter); |
| 32 | 32 |
| 33 Java_WebappRegistry_unregisterWebappsForUrls( | 33 Java_WebappRegistry_unregisterWebappsForUrls(env, filter_bridge->j_bridge(), |
| 34 env, base::android::GetApplicationContext(), filter_bridge->j_bridge(), | 34 callback_pointer); |
| 35 callback_pointer); | |
| 36 } | 35 } |
| 37 | 36 |
| 38 void WebappRegistry::ClearWebappHistoryForUrls( | 37 void WebappRegistry::ClearWebappHistoryForUrls( |
| 39 const base::Callback<bool(const GURL&)>& url_filter, | 38 const base::Callback<bool(const GURL&)>& url_filter, |
| 40 const base::Closure& callback) { | 39 const base::Closure& callback) { |
| 41 JNIEnv* env = base::android::AttachCurrentThread(); | 40 JNIEnv* env = base::android::AttachCurrentThread(); |
| 42 uintptr_t callback_pointer = reinterpret_cast<uintptr_t>( | 41 uintptr_t callback_pointer = reinterpret_cast<uintptr_t>( |
| 43 new base::Closure(callback)); | 42 new base::Closure(callback)); |
| 44 | 43 |
| 45 // We will destroy |filter_bridge| from its Java counterpart before calling | 44 // We will destroy |filter_bridge| from its Java counterpart before calling |
| 46 // back OnClearedWebappHistory(). | 45 // back OnClearedWebappHistory(). |
| 47 UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter); | 46 UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter); |
| 48 | 47 |
| 49 Java_WebappRegistry_clearWebappHistoryForUrls( | 48 Java_WebappRegistry_clearWebappHistoryForUrls(env, filter_bridge->j_bridge(), |
| 50 env, base::android::GetApplicationContext(), filter_bridge->j_bridge(), | 49 callback_pointer); |
| 51 callback_pointer); | |
| 52 } | 50 } |
| 53 | 51 |
| 54 // Callback used by Java when all web apps have been unregistered. | 52 // Callback used by Java when all web apps have been unregistered. |
| 55 void OnWebappsUnregistered(JNIEnv* env, | 53 void OnWebappsUnregistered(JNIEnv* env, |
| 56 const JavaParamRef<jclass>& clazz, | 54 const JavaParamRef<jclass>& clazz, |
| 57 jlong jcallback) { | 55 jlong jcallback) { |
| 58 base::Closure* callback = reinterpret_cast<base::Closure*>(jcallback); | 56 base::Closure* callback = reinterpret_cast<base::Closure*>(jcallback); |
| 59 callback->Run(); | 57 callback->Run(); |
| 60 delete callback; | 58 delete callback; |
| 61 } | 59 } |
| 62 | 60 |
| 63 // Callback used by Java when all web app last used times have been cleared. | 61 // Callback used by Java when all web app last used times have been cleared. |
| 64 void OnClearedWebappHistory(JNIEnv* env, | 62 void OnClearedWebappHistory(JNIEnv* env, |
| 65 const JavaParamRef<jclass>& clazz, | 63 const JavaParamRef<jclass>& clazz, |
| 66 jlong jcallback) { | 64 jlong jcallback) { |
| 67 base::Closure* callback = reinterpret_cast<base::Closure*>(jcallback); | 65 base::Closure* callback = reinterpret_cast<base::Closure*>(jcallback); |
| 68 callback->Run(); | 66 callback->Run(); |
| 69 delete callback; | 67 delete callback; |
| 70 } | 68 } |
| 71 | 69 |
| 72 // static | 70 // static |
| 73 bool WebappRegistry::RegisterWebappRegistry(JNIEnv* env) { | 71 bool WebappRegistry::RegisterWebappRegistry(JNIEnv* env) { |
| 74 return RegisterNativesImpl(env); | 72 return RegisterNativesImpl(env); |
| 75 } | 73 } |
| OLD | NEW |