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

Unified Diff: chrome/browser/android/ntp/ntp_snippets_bridge.cc

Issue 2608333004: Clarify that NTPSnippetsBridge holds a Java SnippetsBridge. (Closed)
Patch Set: Add null checks for the Java observer. Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/ntp/ntp_snippets_bridge.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/ntp/ntp_snippets_bridge.cc
diff --git a/chrome/browser/android/ntp/ntp_snippets_bridge.cc b/chrome/browser/android/ntp/ntp_snippets_bridge.cc
index 939435eba8b2a60d840dfae30e1cad96a0af49e6..cb9cdca533f64145b26c5158a890a1de543535b5 100644
--- a/chrome/browser/android/ntp/ntp_snippets_bridge.cc
+++ b/chrome/browser/android/ntp/ntp_snippets_bridge.cc
@@ -110,9 +110,10 @@ ntp_snippets::RemoteSuggestionsScheduler* GetRemoteSuggestionsScheduler() {
} // namespace
static jlong Init(JNIEnv* env,
- const JavaParamRef<jobject>& obj,
+ const JavaParamRef<jobject>& j_bridge,
const JavaParamRef<jobject>& j_profile) {
- NTPSnippetsBridge* snippets_bridge = new NTPSnippetsBridge(env, j_profile);
+ NTPSnippetsBridge* snippets_bridge =
+ new NTPSnippetsBridge(env, j_bridge, j_profile);
return reinterpret_cast<intptr_t>(snippets_bridge);
}
@@ -155,8 +156,11 @@ static void OnSuggestionTargetVisited(JNIEnv* env,
}
NTPSnippetsBridge::NTPSnippetsBridge(JNIEnv* env,
+ const JavaParamRef<jobject>& j_bridge,
const JavaParamRef<jobject>& j_profile)
- : content_suggestions_service_observer_(this), weak_ptr_factory_(this) {
+ : content_suggestions_service_observer_(this),
+ bridge_(env, j_bridge),
+ weak_ptr_factory_(this) {
Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile);
content_suggestions_service_ =
ContentSuggestionsServiceFactory::GetForProfile(profile);
@@ -170,12 +174,6 @@ void NTPSnippetsBridge::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
delete this;
}
-void NTPSnippetsBridge::SetObserver(JNIEnv* env,
- const JavaParamRef<jobject>& obj,
- const JavaParamRef<jobject>& j_observer) {
- observer_.Reset(env, j_observer);
-}
-
ScopedJavaLocalRef<jintArray> NTPSnippetsBridge::GetCategories(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) {
@@ -405,50 +403,34 @@ void NTPSnippetsBridge::OnNTPInitialized(
NTPSnippetsBridge::~NTPSnippetsBridge() {}
void NTPSnippetsBridge::OnNewSuggestions(Category category) {
- if (observer_.is_null()) {
- return;
- }
-
JNIEnv* env = base::android::AttachCurrentThread();
- Java_SnippetsBridge_onNewSuggestions(env, observer_,
+ Java_SnippetsBridge_onNewSuggestions(env, bridge_,
static_cast<int>(category.id()));
}
void NTPSnippetsBridge::OnCategoryStatusChanged(Category category,
CategoryStatus new_status) {
- if (observer_.is_null()) {
- return;
- }
-
JNIEnv* env = base::android::AttachCurrentThread();
- Java_SnippetsBridge_onCategoryStatusChanged(env, observer_,
+ Java_SnippetsBridge_onCategoryStatusChanged(env, bridge_,
static_cast<int>(category.id()),
static_cast<int>(new_status));
}
void NTPSnippetsBridge::OnSuggestionInvalidated(
const ContentSuggestion::ID& suggestion_id) {
- if (observer_.is_null()) {
- return;
- }
-
JNIEnv* env = base::android::AttachCurrentThread();
Java_SnippetsBridge_onSuggestionInvalidated(
- env, observer_.obj(), static_cast<int>(suggestion_id.category().id()),
+ env, bridge_.obj(), static_cast<int>(suggestion_id.category().id()),
ConvertUTF8ToJavaString(env, suggestion_id.id_within_category()).obj());
}
void NTPSnippetsBridge::OnFullRefreshRequired() {
- if (observer_.is_null()) {
- return;
- }
-
JNIEnv* env = base::android::AttachCurrentThread();
- Java_SnippetsBridge_onFullRefreshRequired(env, observer_.obj());
+ Java_SnippetsBridge_onFullRefreshRequired(env, bridge_.obj());
}
void NTPSnippetsBridge::ContentSuggestionsServiceShutdown() {
- observer_.Reset();
+ bridge_.Reset();
content_suggestions_service_observer_.Remove(content_suggestions_service_);
}
@@ -468,7 +450,7 @@ void NTPSnippetsBridge::OnSuggestionsFetched(
// TODO(fhorschig, dgn): Allow refetch or show notification acc. to status.
JNIEnv* env = AttachCurrentThread();
Java_SnippetsBridge_onMoreSuggestions(
- env, observer_, category.id(),
+ env, bridge_, category.id(),
ToJavaSuggestionList(env, category, suggestions));
}
« no previous file with comments | « chrome/browser/android/ntp/ntp_snippets_bridge.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698