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

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

Issue 2061803002: 📰 The Status card reports disabled sync states (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplifyBridge
Patch Set: yolo: another big bag of changes 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 #include "chrome/browser/android/ntp/ntp_snippets_bridge.h" 5 #include "chrome/browser/android/ntp/ntp_snippets_bridge.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 8
9 #include "base/android/callback_android.h" 9 #include "base/android/callback_android.h"
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 const JavaParamRef<jstring>& jurl) { 111 const JavaParamRef<jstring>& jurl) {
112 base::android::ScopedJavaGlobalRef<jobject> callback(jcallback); 112 base::android::ScopedJavaGlobalRef<jobject> callback(jcallback);
113 113
114 history_service_->QueryURL( 114 history_service_->QueryURL(
115 GURL(ConvertJavaStringToUTF8(env, jurl)), 115 GURL(ConvertJavaStringToUTF8(env, jurl)),
116 false, 116 false,
117 base::Bind(&SnippetVisitedHistoryRequestCallback, callback), 117 base::Bind(&SnippetVisitedHistoryRequestCallback, callback),
118 &tracker_); 118 &tracker_);
119 } 119 }
120 120
121 int NTPSnippetsBridge::GetDisabledReason(JNIEnv* env,
122 const JavaParamRef<jobject>& obj) {
123 return static_cast<int>(ntp_snippets_service_->disabled_reason());
124 }
125
121 NTPSnippetsBridge::~NTPSnippetsBridge() {} 126 NTPSnippetsBridge::~NTPSnippetsBridge() {}
122 127
123 void NTPSnippetsBridge::NTPSnippetsServiceLoaded() { 128 void NTPSnippetsBridge::NTPSnippetsServiceLoaded() {
124 if (observer_.is_null()) 129 if (observer_.is_null())
125 return; 130 return;
126 131
127 std::vector<std::string> ids; 132 std::vector<std::string> ids;
128 std::vector<std::string> titles; 133 std::vector<std::string> titles;
129 // URL for the article. This will also be used to find the favicon for the 134 // URL for the article. This will also be used to find the favicon for the
130 // article. 135 // article.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 ToJavaLongArray(env, timestamps).obj(), 168 ToJavaLongArray(env, timestamps).obj(),
164 ToJavaArrayOfStrings(env, publishers).obj(), 169 ToJavaArrayOfStrings(env, publishers).obj(),
165 ToJavaFloatArray(env, scores).obj()); 170 ToJavaFloatArray(env, scores).obj());
166 } 171 }
167 172
168 void NTPSnippetsBridge::NTPSnippetsServiceShutdown() { 173 void NTPSnippetsBridge::NTPSnippetsServiceShutdown() {
169 observer_.Reset(); 174 observer_.Reset();
170 snippet_service_observer_.Remove(ntp_snippets_service_); 175 snippet_service_observer_.Remove(ntp_snippets_service_);
171 } 176 }
172 177
173 void NTPSnippetsBridge::NTPSnippetsServiceDisabled() { 178 void NTPSnippetsBridge::NTPSnippetsServiceDisabledReasonChanged(
179 ntp_snippets::DisabledReason disabled_reason) {
174 // The user signed out or disabled sync. Since snippets rely on those, we 180 // The user signed out or disabled sync. Since snippets rely on those, we
175 // clear them to be consistent with the initially signed out state. 181 // clear them to be consistent with the initially signed out state.
176 JNIEnv* env = base::android::AttachCurrentThread(); 182 JNIEnv* env = base::android::AttachCurrentThread();
177 Java_SnippetsBridge_onSnippetsDisabled(env, observer_.obj()); 183 Java_SnippetsBridge_onDisabledReasonChanged(
184 env, observer_.obj(), static_cast<int>(disabled_reason));
178 } 185 }
179 186
180 void NTPSnippetsBridge::OnImageFetched(ScopedJavaGlobalRef<jobject> callback, 187 void NTPSnippetsBridge::OnImageFetched(ScopedJavaGlobalRef<jobject> callback,
181 const std::string& snippet_id, 188 const std::string& snippet_id,
182 const gfx::Image& image) { 189 const gfx::Image& image) {
183 ScopedJavaLocalRef<jobject> j_bitmap; 190 ScopedJavaLocalRef<jobject> j_bitmap;
184 if (!image.IsEmpty()) 191 if (!image.IsEmpty())
185 j_bitmap = gfx::ConvertToJavaBitmap(image.ToSkBitmap()); 192 j_bitmap = gfx::ConvertToJavaBitmap(image.ToSkBitmap());
186 193
187 base::android::RunCallbackAndroid(callback, j_bitmap); 194 base::android::RunCallbackAndroid(callback, j_bitmap);
188 } 195 }
189 196
190 // static 197 // static
191 bool NTPSnippetsBridge::Register(JNIEnv* env) { 198 bool NTPSnippetsBridge::Register(JNIEnv* env) {
192 return RegisterNativesImpl(env); 199 return RegisterNativesImpl(env);
193 } 200 }
OLDNEW
« no previous file with comments | « chrome/browser/android/ntp/ntp_snippets_bridge.h ('k') | chrome/browser/ntp_snippets/ntp_snippets_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698