| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/logo_bridge.h" | 5 #include "chrome/browser/android/logo_bridge.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "url/gurl.h" | 33 #include "url/gurl.h" |
| 34 | 34 |
| 35 using base::android::ConvertJavaStringToUTF8; | 35 using base::android::ConvertJavaStringToUTF8; |
| 36 using base::android::ConvertUTF8ToJavaString; | 36 using base::android::ConvertUTF8ToJavaString; |
| 37 using base::android::JavaParamRef; | 37 using base::android::JavaParamRef; |
| 38 using base::android::ScopedJavaLocalRef; | 38 using base::android::ScopedJavaLocalRef; |
| 39 using base::android::ToJavaByteArray; | 39 using base::android::ToJavaByteArray; |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 const int64_t kMaxImageDownloadBytes = 1024 * 1024; |
| 44 |
| 43 ScopedJavaLocalRef<jobject> MakeJavaLogo(JNIEnv* env, | 45 ScopedJavaLocalRef<jobject> MakeJavaLogo(JNIEnv* env, |
| 44 const SkBitmap* bitmap, | 46 const SkBitmap* bitmap, |
| 45 const GURL& on_click_url, | 47 const GURL& on_click_url, |
| 46 const std::string& alt_text, | 48 const std::string& alt_text, |
| 47 const GURL& animated_url) { | 49 const GURL& animated_url) { |
| 48 ScopedJavaLocalRef<jobject> j_bitmap = gfx::ConvertToJavaBitmap(bitmap); | 50 ScopedJavaLocalRef<jobject> j_bitmap = gfx::ConvertToJavaBitmap(bitmap); |
| 49 | 51 |
| 50 ScopedJavaLocalRef<jstring> j_on_click_url; | 52 ScopedJavaLocalRef<jstring> j_on_click_url; |
| 51 if (on_click_url.is_valid()) | 53 if (on_click_url.is_valid()) |
| 52 j_on_click_url = ConvertUTF8ToJavaString(env, on_click_url.spec()); | 54 j_on_click_url = ConvertUTF8ToJavaString(env, on_click_url.spec()); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 doodle_observer_(this), | 196 doodle_observer_(this), |
| 195 weak_ptr_factory_(this) { | 197 weak_ptr_factory_(this) { |
| 196 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); | 198 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); |
| 197 DCHECK(profile); | 199 DCHECK(profile); |
| 198 | 200 |
| 199 if (base::FeatureList::IsEnabled(chrome::android::kUseNewDoodleApi)) { | 201 if (base::FeatureList::IsEnabled(chrome::android::kUseNewDoodleApi)) { |
| 200 doodle_service_ = DoodleServiceFactory::GetForProfile(profile); | 202 doodle_service_ = DoodleServiceFactory::GetForProfile(profile); |
| 201 image_fetcher_ = base::MakeUnique<image_fetcher::ImageFetcherImpl>( | 203 image_fetcher_ = base::MakeUnique<image_fetcher::ImageFetcherImpl>( |
| 202 base::MakeUnique<suggestions::ImageDecoderImpl>(), | 204 base::MakeUnique<suggestions::ImageDecoderImpl>(), |
| 203 profile->GetRequestContext()); | 205 profile->GetRequestContext()); |
| 206 image_fetcher_->SetImageDownloadLimit(kMaxImageDownloadBytes); |
| 204 | 207 |
| 205 doodle_observer_.Add(doodle_service_); | 208 doodle_observer_.Add(doodle_service_); |
| 206 } else { | 209 } else { |
| 207 logo_service_ = LogoServiceFactory::GetForProfile(profile); | 210 logo_service_ = LogoServiceFactory::GetForProfile(profile); |
| 208 } | 211 } |
| 209 | 212 |
| 210 animated_logo_fetcher_ = base::MakeUnique<AnimatedLogoFetcher>( | 213 animated_logo_fetcher_ = base::MakeUnique<AnimatedLogoFetcher>( |
| 211 profile->GetRequestContext()); | 214 profile->GetRequestContext()); |
| 212 } | 215 } |
| 213 | 216 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 ScopedJavaLocalRef<jobject> j_logo = MakeJavaLogo( | 308 ScopedJavaLocalRef<jobject> j_logo = MakeJavaLogo( |
| 306 env, image.ToSkBitmap(), on_click_url, alt_text, animated_image_url); | 309 env, image.ToSkBitmap(), on_click_url, alt_text, animated_image_url); |
| 307 Java_LogoObserver_onLogoAvailable(env, j_logo_observer_, j_logo, | 310 Java_LogoObserver_onLogoAvailable(env, j_logo_observer_, j_logo, |
| 308 config_from_cache); | 311 config_from_cache); |
| 309 } | 312 } |
| 310 | 313 |
| 311 // static | 314 // static |
| 312 bool RegisterLogoBridge(JNIEnv* env) { | 315 bool RegisterLogoBridge(JNIEnv* env) { |
| 313 return RegisterNativesImpl(env); | 316 return RegisterNativesImpl(env); |
| 314 } | 317 } |
| OLD | NEW |