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

Side by Side Diff: chrome/browser/android/webapps/webapp_registry.cc

Issue 2351113005: [Reland] Refactor WebappRegistry into a singleton instance. (Closed)
Patch Set: Checkstyle import order has changed overnight argh 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 unified diff | Download patch
OLDNEW
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"
10 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
11 #include "base/callback.h"
12 #include "chrome/browser/android/browsing_data/url_filter_bridge.h" 8 #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"
15 #include "jni/WebappRegistry_jni.h" 9 #include "jni/WebappRegistry_jni.h"
16 10
17 using base::android::JavaParamRef; 11 using base::android::JavaParamRef;
18 12
19 void WebappRegistry::UnregisterWebappsForUrls( 13 void WebappRegistry::UnregisterWebappsForUrls(
20 const base::Callback<bool(const GURL&)>& url_filter, 14 const base::Callback<bool(const GURL&)>& url_filter) {
21 const base::Closure& callback) { 15 // |filter_bridge| is destroyed from its Java counterpart.
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().
31 UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter); 16 UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter);
32 17
33 Java_WebappRegistry_unregisterWebappsForUrls(env, filter_bridge->j_bridge(), 18 Java_WebappRegistry_unregisterWebappsForUrls(
34 callback_pointer); 19 base::android::AttachCurrentThread(), filter_bridge->j_bridge());
35 } 20 }
36 21
37 void WebappRegistry::ClearWebappHistoryForUrls( 22 void WebappRegistry::ClearWebappHistoryForUrls(
38 const base::Callback<bool(const GURL&)>& url_filter, 23 const base::Callback<bool(const GURL&)>& url_filter) {
39 const base::Closure& callback) { 24 // |filter_bridge| is destroyed from its Java counterpart.
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().
46 UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter); 25 UrlFilterBridge* filter_bridge = new UrlFilterBridge(url_filter);
47 26
48 Java_WebappRegistry_clearWebappHistoryForUrls(env, filter_bridge->j_bridge(), 27 Java_WebappRegistry_clearWebappHistoryForUrls(
49 callback_pointer); 28 base::android::AttachCurrentThread(), filter_bridge->j_bridge());
50 } 29 }
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 }
OLDNEW
« 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