| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_ANDROID_NTP_NTP_SNIPPETS_BRIDGE_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_NTP_NTP_SNIPPETS_BRIDGE_H_ |
| 6 #define CHROME_BROWSER_ANDROID_NTP_NTP_SNIPPETS_BRIDGE_H_ | 6 #define CHROME_BROWSER_ANDROID_NTP_NTP_SNIPPETS_BRIDGE_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 | 9 |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/scoped_observer.h" | 11 #include "base/scoped_observer.h" |
| 12 #include "base/task/cancelable_task_tracker.h" |
| 13 #include "components/history/core/browser/history_service.h" |
| 12 #include "components/ntp_snippets/ntp_snippets_service.h" | 14 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 13 | 15 |
| 14 // The C++ counterpart to SnippetsBridge.java. Enables Java code to access | 16 // The C++ counterpart to SnippetsBridge.java. Enables Java code to access |
| 15 // the list of snippets to show on the NTP | 17 // the list of snippets to show on the NTP |
| 16 class NTPSnippetsBridge : public ntp_snippets::NTPSnippetsServiceObserver { | 18 class NTPSnippetsBridge : public ntp_snippets::NTPSnippetsServiceObserver { |
| 17 public: | 19 public: |
| 18 NTPSnippetsBridge(JNIEnv* env, | 20 NTPSnippetsBridge(JNIEnv* env, |
| 19 const base::android::JavaParamRef<jobject>& j_profile); | 21 const base::android::JavaParamRef<jobject>& j_profile); |
| 20 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 22 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 21 | 23 |
| 22 void SetObserver(JNIEnv* env, | 24 void SetObserver(JNIEnv* env, |
| 23 const base::android::JavaParamRef<jobject>& obj, | 25 const base::android::JavaParamRef<jobject>& obj, |
| 24 const base::android::JavaParamRef<jobject>& j_observer); | 26 const base::android::JavaParamRef<jobject>& j_observer); |
| 25 | 27 |
| 26 // Discards the snippet with the given URL. | 28 // Discards the snippet with the given URL. |
| 27 void DiscardSnippet(JNIEnv* env, | 29 void DiscardSnippet(JNIEnv* env, |
| 28 const base::android::JavaParamRef<jobject>& obj, | 30 const base::android::JavaParamRef<jobject>& obj, |
| 29 const base::android::JavaParamRef<jstring>& url); | 31 const base::android::JavaParamRef<jstring>& url); |
| 30 | 32 |
| 33 // Checks if the URL has been visited. |
| 34 void SnippetVisited(JNIEnv* env, |
| 35 const base::android::JavaParamRef<jobject>& obj, |
| 36 const base::android::JavaParamRef<jobject>& callback, |
| 37 const base::android::JavaParamRef<jstring>& jurl); |
| 38 |
| 31 static bool Register(JNIEnv* env); | 39 static bool Register(JNIEnv* env); |
| 32 | 40 |
| 33 private: | 41 private: |
| 34 ~NTPSnippetsBridge() override; | 42 ~NTPSnippetsBridge() override; |
| 35 | 43 |
| 36 // NTPSnippetsServiceObserver overrides | 44 // NTPSnippetsServiceObserver overrides |
| 37 void NTPSnippetsServiceLoaded() override; | 45 void NTPSnippetsServiceLoaded() override; |
| 38 void NTPSnippetsServiceShutdown() override; | 46 void NTPSnippetsServiceShutdown() override; |
| 39 | 47 |
| 40 ntp_snippets::NTPSnippetsService* ntp_snippets_service_; | 48 ntp_snippets::NTPSnippetsService* ntp_snippets_service_; |
| 49 history::HistoryService* history_service_; |
| 50 base::CancelableTaskTracker tracker_; |
| 41 | 51 |
| 42 // Used to notify the Java side when new snippets have been fetched. | 52 // Used to notify the Java side when new snippets have been fetched. |
| 43 base::android::ScopedJavaGlobalRef<jobject> observer_; | 53 base::android::ScopedJavaGlobalRef<jobject> observer_; |
| 44 ScopedObserver<ntp_snippets::NTPSnippetsService, | 54 ScopedObserver<ntp_snippets::NTPSnippetsService, |
| 45 ntp_snippets::NTPSnippetsServiceObserver> | 55 ntp_snippets::NTPSnippetsServiceObserver> |
| 46 snippet_service_observer_; | 56 snippet_service_observer_; |
| 47 | 57 |
| 48 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsBridge); | 58 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsBridge); |
| 49 }; | 59 }; |
| 50 | 60 |
| 51 #endif // CHROME_BROWSER_ANDROID_NTP_NTP_SNIPPETS_BRIDGE_H_ | 61 #endif // CHROME_BROWSER_ANDROID_NTP_NTP_SNIPPETS_BRIDGE_H_ |
| OLD | NEW |