| 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" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "chrome/browser/io_thread.h" | 12 #include "chrome/browser/io_thread.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "jni/WebappRegistry_jni.h" | 14 #include "jni/WebappRegistry_jni.h" |
| 15 | 15 |
| 16 void WebappRegistry::UnregisterWebapps(const base::Closure& callback) { | 16 void WebappRegistry::UnregisterWebapps(const base::Closure& callback) { |
| 17 JNIEnv* env = base::android::AttachCurrentThread(); | 17 JNIEnv* env = base::android::AttachCurrentThread(); |
| 18 uintptr_t callback_pointer = reinterpret_cast<uintptr_t>( | 18 uintptr_t callback_pointer = reinterpret_cast<uintptr_t>( |
| 19 new base::Closure(callback)); | 19 new base::Closure(callback)); |
| 20 | 20 |
| 21 Java_WebappRegistry_unregisterAllWebapps( | 21 Java_WebappRegistry_unregisterAllWebapps( |
| 22 env, | 22 env, |
| 23 base::android::GetApplicationContext(), | 23 base::android::GetApplicationContext(), |
| 24 callback_pointer); | 24 callback_pointer); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void WebappRegistry::ClearWebappHistory(const base::Closure& callback) { |
| 28 JNIEnv* env = base::android::AttachCurrentThread(); |
| 29 uintptr_t callback_pointer = reinterpret_cast<uintptr_t>( |
| 30 new base::Closure(callback)); |
| 31 |
| 32 Java_WebappRegistry_clearWebappHistory( |
| 33 env, |
| 34 base::android::GetApplicationContext(), |
| 35 callback_pointer); |
| 36 } |
| 37 |
| 27 // Callback used by Java when all web apps have been unregistered. | 38 // Callback used by Java when all web apps have been unregistered. |
| 28 void OnWebappsUnregistered(JNIEnv* env, | 39 void OnWebappsUnregistered(JNIEnv* env, |
| 29 const JavaParamRef<jclass>& clazz, | 40 const JavaParamRef<jclass>& clazz, |
| 30 jlong jcallback) { | 41 jlong jcallback) { |
| 31 base::Closure* callback = reinterpret_cast<base::Closure*>(jcallback); | 42 base::Closure* callback = reinterpret_cast<base::Closure*>(jcallback); |
| 32 callback->Run(); | 43 callback->Run(); |
| 33 delete callback; | 44 delete callback; |
| 34 } | 45 } |
| 35 | 46 |
| 47 // Callback used by Java when all web app last used times have been cleared. |
| 48 void OnClearedWebappHistory(JNIEnv* env, |
| 49 const JavaParamRef<jclass>& clazz, |
| 50 jlong jcallback) { |
| 51 base::Closure* callback = reinterpret_cast<base::Closure*>(jcallback); |
| 52 callback->Run(); |
| 53 delete callback; |
| 54 } |
| 55 |
| 36 // static | 56 // static |
| 37 bool WebappRegistry::RegisterWebappRegistry(JNIEnv* env) { | 57 bool WebappRegistry::RegisterWebappRegistry(JNIEnv* env) { |
| 38 return RegisterNativesImpl(env); | 58 return RegisterNativesImpl(env); |
| 39 } | 59 } |
| OLD | NEW |