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/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/scoped_observer.h" | 12 #include "base/scoped_observer.h" |
13 #include "base/task/cancelable_task_tracker.h" | 13 #include "base/task/cancelable_task_tracker.h" |
14 #include "components/history/core/browser/history_service.h" | 14 #include "components/history/core/browser/history_service.h" |
15 #include "components/ntp_snippets/ntp_snippets_service.h" | 15 #include "components/ntp_snippets/content_suggestions_category.h" |
| 16 #include "components/ntp_snippets/content_suggestions_category_status.h" |
| 17 #include "components/ntp_snippets/content_suggestions_service.h" |
16 | 18 |
17 namespace gfx { | 19 namespace gfx { |
18 class Image; | 20 class Image; |
19 } | 21 } |
20 | 22 |
21 // The C++ counterpart to SnippetsBridge.java. Enables Java code to access | 23 // The C++ counterpart to SnippetsBridge.java. Enables Java code to access |
22 // the list of snippets to show on the NTP | 24 // the list of snippets to show on the NTP |
23 class NTPSnippetsBridge : public ntp_snippets::NTPSnippetsServiceObserver { | 25 class NTPSnippetsBridge |
| 26 : public ntp_snippets::ContentSuggestionsService::Observer { |
24 public: | 27 public: |
25 NTPSnippetsBridge(JNIEnv* env, | 28 NTPSnippetsBridge(JNIEnv* env, |
26 const base::android::JavaParamRef<jobject>& j_profile); | 29 const base::android::JavaParamRef<jobject>& j_profile); |
27 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 30 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
28 | 31 |
29 void SetObserver(JNIEnv* env, | 32 void SetObserver(JNIEnv* env, |
30 const base::android::JavaParamRef<jobject>& obj, | 33 const base::android::JavaParamRef<jobject>& obj, |
31 const base::android::JavaParamRef<jobject>& j_observer); | 34 const base::android::JavaParamRef<jobject>& j_observer); |
32 | 35 |
33 void FetchImage(JNIEnv* env, | 36 void FetchImage(JNIEnv* env, |
34 const base::android::JavaParamRef<jobject>& obj, | 37 const base::android::JavaParamRef<jobject>& obj, |
35 const base::android::JavaParamRef<jstring>& snippet_id, | 38 const base::android::JavaParamRef<jstring>& snippet_id, |
36 const base::android::JavaParamRef<jobject>& j_callback); | 39 const base::android::JavaParamRef<jobject>& j_callback); |
37 | 40 |
38 // Discards the snippet with the given ID. | 41 // Discards the snippet with the given ID. |
39 void DiscardSnippet(JNIEnv* env, | 42 void DiscardSnippet(JNIEnv* env, |
40 const base::android::JavaParamRef<jobject>& obj, | 43 const base::android::JavaParamRef<jobject>& obj, |
41 const base::android::JavaParamRef<jstring>& snippet_id); | 44 const base::android::JavaParamRef<jstring>& snippet_id); |
42 | 45 |
43 // Checks if the URL has been visited. | 46 // Checks if the URL has been visited. |
44 void SnippetVisited(JNIEnv* env, | 47 void SnippetVisited(JNIEnv* env, |
45 const base::android::JavaParamRef<jobject>& obj, | 48 const base::android::JavaParamRef<jobject>& obj, |
46 const base::android::JavaParamRef<jobject>& callback, | 49 const base::android::JavaParamRef<jobject>& callback, |
47 const base::android::JavaParamRef<jstring>& jurl); | 50 const base::android::JavaParamRef<jstring>& jurl); |
48 | 51 |
49 // Returns a reason why the snippet service is disabled, or 0 if it isn't. | 52 // Returns the status of the ARTICLES category. |
50 // See NTPSnippetsService::DisabledReason for more info. | 53 // See ContentSuggestionsCategoryStatus for more info. |
51 int GetDisabledReason(JNIEnv* env, | 54 int GetCategoryStatus(JNIEnv* env, |
52 const base::android::JavaParamRef<jobject>& obj); | 55 const base::android::JavaParamRef<jobject>& obj); |
53 | 56 |
54 static bool Register(JNIEnv* env); | 57 static bool Register(JNIEnv* env); |
55 | 58 |
56 private: | 59 private: |
57 ~NTPSnippetsBridge() override; | 60 ~NTPSnippetsBridge() override; |
58 | 61 |
59 // NTPSnippetsServiceObserver overrides | 62 // ContentSuggestionsService::Observer overrides |
60 void NTPSnippetsServiceLoaded() override; | 63 void OnNewSuggestions() override; |
61 void NTPSnippetsServiceShutdown() override; | 64 void OnCategoryStatusChanged( |
62 void NTPSnippetsServiceDisabledReasonChanged( | 65 ntp_snippets::ContentSuggestionsCategory category, |
63 ntp_snippets::DisabledReason disabled_reason) override; | 66 ntp_snippets::ContentSuggestionsCategoryStatus new_status) override; |
| 67 void ContentSuggestionsServiceShutdown() override; |
64 | 68 |
65 void OnImageFetched(base::android::ScopedJavaGlobalRef<jobject> callback, | 69 void OnImageFetched(base::android::ScopedJavaGlobalRef<jobject> callback, |
66 const std::string& snippet_id, | 70 const std::string& snippet_id, |
67 const gfx::Image& image); | 71 const gfx::Image& image); |
68 | 72 |
69 ntp_snippets::NTPSnippetsService* ntp_snippets_service_; | 73 ntp_snippets::ContentSuggestionsService* content_suggestions_service_; |
70 history::HistoryService* history_service_; | 74 history::HistoryService* history_service_; |
71 base::CancelableTaskTracker tracker_; | 75 base::CancelableTaskTracker tracker_; |
72 | 76 |
| 77 ScopedObserver<ntp_snippets::ContentSuggestionsService, |
| 78 ntp_snippets::ContentSuggestionsService::Observer> |
| 79 content_suggestions_service_observer_; |
| 80 |
73 // Used to notify the Java side when new snippets have been fetched. | 81 // Used to notify the Java side when new snippets have been fetched. |
74 base::android::ScopedJavaGlobalRef<jobject> observer_; | 82 base::android::ScopedJavaGlobalRef<jobject> observer_; |
75 ScopedObserver<ntp_snippets::NTPSnippetsService, | |
76 ntp_snippets::NTPSnippetsServiceObserver> | |
77 snippet_service_observer_; | |
78 | 83 |
79 base::WeakPtrFactory<NTPSnippetsBridge> weak_ptr_factory_; | 84 base::WeakPtrFactory<NTPSnippetsBridge> weak_ptr_factory_; |
80 | 85 |
81 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsBridge); | 86 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsBridge); |
82 }; | 87 }; |
83 | 88 |
84 #endif // CHROME_BROWSER_ANDROID_NTP_NTP_SNIPPETS_BRIDGE_H_ | 89 #endif // CHROME_BROWSER_ANDROID_NTP_NTP_SNIPPETS_BRIDGE_H_ |
OLD | NEW |