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

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

Issue 1869023002: [NTP Snippets] SnippetsBridge: register as SnippetsObserver only when we get a Java observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snippets_service_cleanup
Patch Set: rebase Created 4 years, 8 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') | components/ntp_snippets/ntp_snippets_service.h » ('j') | 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 3059eb30238bf9a9115f165e5a5fb274bd18a774..471053d0f00ebb5e2433ac3e0bb2b158a523f2f8 100644
--- a/chrome/browser/android/ntp/ntp_snippets_bridge.cc
+++ b/chrome/browser/android/ntp/ntp_snippets_bridge.cc
@@ -21,8 +21,6 @@ using base::android::ConvertJavaStringToUTF8;
using base::android::JavaParamRef;
using base::android::ToJavaArrayOfStrings;
using base::android::ToJavaLongArray;
-using ntp_snippets::NTPSnippetsService;
-using ntp_snippets::NTPSnippetsServiceObserver;
static jlong Init(JNIEnv* env,
const JavaParamRef<jobject>& obj,
@@ -36,14 +34,14 @@ NTPSnippetsBridge::NTPSnippetsBridge(JNIEnv* env,
: snippet_service_observer_(this) {
Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile);
ntp_snippets_service_ = NTPSnippetsServiceFactory::GetForProfile(profile);
- snippet_service_observer_.Add(ntp_snippets_service_);
}
void NTPSnippetsBridge::SetObserver(JNIEnv* env,
const JavaParamRef<jobject>& obj,
const JavaParamRef<jobject>& j_observer) {
observer_.Reset(env, j_observer);
- NTPSnippetsServiceLoaded(ntp_snippets_service_);
+ // This will call NTPSnippetsServiceLoaded.
+ snippet_service_observer_.Add(ntp_snippets_service_);
}
NTPSnippetsBridge::~NTPSnippetsBridge() {}
@@ -59,16 +57,15 @@ void NTPSnippetsBridge::DiscardSnippet(JNIEnv* env,
GURL(ConvertJavaStringToUTF8(env, url)));
}
-void NTPSnippetsBridge::NTPSnippetsServiceLoaded(NTPSnippetsService* service) {
- if (observer_.is_null())
- return;
+void NTPSnippetsBridge::NTPSnippetsServiceLoaded() {
+ DCHECK(!observer_.is_null());
std::vector<std::string> titles;
std::vector<std::string> urls;
std::vector<std::string> thumbnail_urls;
std::vector<std::string> snippets;
std::vector<int64_t> timestamps;
- for (const ntp_snippets::NTPSnippet& snippet : *service) {
+ for (const ntp_snippets::NTPSnippet& snippet : *ntp_snippets_service_) {
titles.push_back(snippet.title());
urls.push_back(snippet.url().spec());
thumbnail_urls.push_back(snippet.salient_image_url().spec());
@@ -85,8 +82,7 @@ void NTPSnippetsBridge::NTPSnippetsServiceLoaded(NTPSnippetsService* service) {
ToJavaLongArray(env, timestamps).obj());
}
-void NTPSnippetsBridge::NTPSnippetsServiceShutdown(
- NTPSnippetsService* service) {
+void NTPSnippetsBridge::NTPSnippetsServiceShutdown() {
observer_.Reset();
snippet_service_observer_.Remove(ntp_snippets_service_);
}
« no previous file with comments | « chrome/browser/android/ntp/ntp_snippets_bridge.h ('k') | components/ntp_snippets/ntp_snippets_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698