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

Side by Side Diff: chrome/browser/android/ntp/ntp_snippets_bridge.h

Issue 2158883002: Change NTPSnippetsBridge to read from ContentSuggestionsService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@offlinepagesprovider
Patch Set: Marc's comments Created 4 years, 5 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 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/content_suggestions_category.h"
16 #include "components/ntp_snippets/content_suggestions_category_status.h"
17 #include "components/ntp_snippets/content_suggestions_service.h"
15 #include "components/ntp_snippets/ntp_snippets_service.h" 18 #include "components/ntp_snippets/ntp_snippets_service.h"
Marc Treib 2016/07/20 09:17:38 Not needed anymore
Philipp Keck 2016/07/20 13:20:02 Moved to .cc file, it's needed there.
16 19
17 namespace gfx { 20 namespace gfx {
18 class Image; 21 class Image;
19 } 22 }
20 23
21 // The C++ counterpart to SnippetsBridge.java. Enables Java code to access 24 // The C++ counterpart to SnippetsBridge.java. Enables Java code to access
22 // the list of snippets to show on the NTP 25 // the list of snippets to show on the NTP
23 class NTPSnippetsBridge : public ntp_snippets::NTPSnippetsServiceObserver { 26 class NTPSnippetsBridge
27 : public ntp_snippets::ContentSuggestionsService::Observer {
24 public: 28 public:
25 NTPSnippetsBridge(JNIEnv* env, 29 NTPSnippetsBridge(JNIEnv* env,
26 const base::android::JavaParamRef<jobject>& j_profile); 30 const base::android::JavaParamRef<jobject>& j_profile);
27 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); 31 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
28 32
29 void SetObserver(JNIEnv* env, 33 void SetObserver(JNIEnv* env,
30 const base::android::JavaParamRef<jobject>& obj, 34 const base::android::JavaParamRef<jobject>& obj,
31 const base::android::JavaParamRef<jobject>& j_observer); 35 const base::android::JavaParamRef<jobject>& j_observer);
32 36
33 void FetchImage(JNIEnv* env, 37 void FetchImage(JNIEnv* env,
34 const base::android::JavaParamRef<jobject>& obj, 38 const base::android::JavaParamRef<jobject>& obj,
35 const base::android::JavaParamRef<jstring>& snippet_id, 39 const base::android::JavaParamRef<jstring>& snippet_id,
36 const base::android::JavaParamRef<jobject>& j_callback); 40 const base::android::JavaParamRef<jobject>& j_callback);
37 41
38 // Discards the snippet with the given ID. 42 // Discards the snippet with the given ID.
39 void DiscardSnippet(JNIEnv* env, 43 void DiscardSnippet(JNIEnv* env,
40 const base::android::JavaParamRef<jobject>& obj, 44 const base::android::JavaParamRef<jobject>& obj,
41 const base::android::JavaParamRef<jstring>& snippet_id); 45 const base::android::JavaParamRef<jstring>& snippet_id);
42 46
43 // Checks if the URL has been visited. 47 // Checks if the URL has been visited.
44 void SnippetVisited(JNIEnv* env, 48 void SnippetVisited(JNIEnv* env,
45 const base::android::JavaParamRef<jobject>& obj, 49 const base::android::JavaParamRef<jobject>& obj,
46 const base::android::JavaParamRef<jobject>& callback, 50 const base::android::JavaParamRef<jobject>& callback,
47 const base::android::JavaParamRef<jstring>& jurl); 51 const base::android::JavaParamRef<jstring>& jurl);
48 52
49 // Returns a reason why the snippet service is disabled, or 0 if it isn't. 53 // Returns the status of the ARTICLES category.
50 // See NTPSnippetsService::DisabledReason for more info. 54 // See ContentSuggestionsCategoryStatus for more info.
51 int GetDisabledReason(JNIEnv* env, 55 int GetCategoryStatus(JNIEnv* env,
52 const base::android::JavaParamRef<jobject>& obj); 56 const base::android::JavaParamRef<jobject>& obj);
53 57
54 static bool Register(JNIEnv* env); 58 static bool Register(JNIEnv* env);
55 59
56 private: 60 private:
57 ~NTPSnippetsBridge() override; 61 ~NTPSnippetsBridge() override;
58 62
59 // NTPSnippetsServiceObserver overrides 63 // ContentSuggestionsService::Observer overrides
60 void NTPSnippetsServiceLoaded() override; 64 void OnNewSuggestions() override;
61 void NTPSnippetsServiceShutdown() override; 65 void OnCategoryStatusChanged(
62 void NTPSnippetsServiceDisabledReasonChanged( 66 ntp_snippets::ContentSuggestionsCategory category,
63 ntp_snippets::DisabledReason disabled_reason) override; 67 ntp_snippets::ContentSuggestionsCategoryStatus new_status) override;
68 void ContentSuggestionsServiceShutdown() override;
64 69
65 void OnImageFetched(base::android::ScopedJavaGlobalRef<jobject> callback, 70 void OnImageFetched(base::android::ScopedJavaGlobalRef<jobject> callback,
66 const std::string& snippet_id, 71 const std::string& snippet_id,
67 const gfx::Image& image); 72 const gfx::Image& image);
68 73
69 ntp_snippets::NTPSnippetsService* ntp_snippets_service_; 74 ntp_snippets::ContentSuggestionsService* content_suggestions_service_;
70 history::HistoryService* history_service_; 75 history::HistoryService* history_service_;
71 base::CancelableTaskTracker tracker_; 76 base::CancelableTaskTracker tracker_;
72 77
73 // Used to notify the Java side when new snippets have been fetched. 78 // Used to notify the Java side when new snippets have been fetched.
74 base::android::ScopedJavaGlobalRef<jobject> observer_; 79 base::android::ScopedJavaGlobalRef<jobject> observer_;
75 ScopedObserver<ntp_snippets::NTPSnippetsService, 80 ScopedObserver<ntp_snippets::ContentSuggestionsService,
Marc Treib 2016/07/20 09:17:38 nit: I'd move this somewhere else, or at least put
Philipp Keck 2016/07/20 13:20:02 Done.
76 ntp_snippets::NTPSnippetsServiceObserver> 81 ntp_snippets::ContentSuggestionsService::Observer>
77 snippet_service_observer_; 82 content_suggestions_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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698