| 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 #ifndef CHROME_BROWSER_ANDROID_LOGO_BRIDGE_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_LOGO_BRIDGE_H_ |
| 6 #define CHROME_BROWSER_ANDROID_LOGO_BRIDGE_H_ | 6 #define CHROME_BROWSER_ANDROID_LOGO_BRIDGE_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 | 9 |
| 10 #include <memory> |
| 11 |
| 10 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/optional.h" |
| 16 #include "base/scoped_observer.h" |
| 17 #include "components/doodle/doodle_service.h" |
| 13 | 18 |
| 14 class LogoService; | 19 class LogoService; |
| 15 | 20 |
| 21 namespace doodle { |
| 22 class DoodleService; |
| 23 } // namespace doodle |
| 24 |
| 25 namespace gfx { |
| 26 class Image; |
| 27 } // namespace gfx |
| 28 |
| 29 namespace image_fetcher { |
| 30 class ImageFetcher; |
| 31 } // namespace image_fetcher |
| 32 |
| 16 // The C++ counterpart to LogoBridge.java. Enables Java code to access the | 33 // The C++ counterpart to LogoBridge.java. Enables Java code to access the |
| 17 // default search provider's logo. | 34 // default search provider's logo. |
| 18 class LogoBridge { | 35 class LogoBridge : public doodle::DoodleService::Observer { |
| 19 public: | 36 public: |
| 20 explicit LogoBridge(jobject j_profile); | 37 explicit LogoBridge(jobject j_profile); |
| 21 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 38 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 22 | 39 |
| 23 // Gets the current non-animated logo (downloading it if necessary) and passes | 40 // Gets the current non-animated logo (downloading it if necessary) and passes |
| 24 // it to the observer. | 41 // it to the observer. |
| 25 void GetCurrentLogo( | 42 void GetCurrentLogo( |
| 26 JNIEnv* env, | 43 JNIEnv* env, |
| 27 const base::android::JavaParamRef<jobject>& obj, | 44 const base::android::JavaParamRef<jobject>& obj, |
| 28 const base::android::JavaParamRef<jobject>& j_logo_observer); | 45 const base::android::JavaParamRef<jobject>& j_logo_observer); |
| 29 | 46 |
| 30 // Downloads the animated logo from the given URL and returns it to the | 47 // Downloads the animated logo from the given URL and returns it to the |
| 31 // callback. Does not support multiple concurrent requests: A second request | 48 // callback. Does not support multiple concurrent requests: A second request |
| 32 // for the same URL will be ignored; a request for a different URL will cancel | 49 // for the same URL will be ignored; a request for a different URL will cancel |
| 33 // any ongoing request. If downloading fails, the callback is not called. | 50 // any ongoing request. If downloading fails, the callback is not called. |
| 34 void GetAnimatedLogo(JNIEnv* env, | 51 void GetAnimatedLogo(JNIEnv* env, |
| 35 const base::android::JavaParamRef<jobject>& obj, | 52 const base::android::JavaParamRef<jobject>& obj, |
| 36 const base::android::JavaParamRef<jobject>& j_callback, | 53 const base::android::JavaParamRef<jobject>& j_callback, |
| 37 const base::android::JavaParamRef<jstring>& j_url); | 54 const base::android::JavaParamRef<jstring>& j_url); |
| 38 | 55 |
| 39 private: | 56 private: |
| 40 class AnimatedLogoFetcher; | 57 class AnimatedLogoFetcher; |
| 41 | 58 |
| 42 ~LogoBridge(); | 59 virtual ~LogoBridge(); |
| 43 | 60 |
| 61 // doodle::DoodleService::Observer implementation. |
| 62 void OnDoodleConfigUpdated( |
| 63 const base::Optional<doodle::DoodleConfig>& maybe_doodle_config) override; |
| 64 |
| 65 void DoodleConfigReceived( |
| 66 const base::Optional<doodle::DoodleConfig>& maybe_doodle_config, |
| 67 bool from_cache); |
| 68 |
| 69 void DoodleImageFetched(bool config_from_cache, |
| 70 const GURL& on_click_url, |
| 71 const std::string& alt_text, |
| 72 const GURL& animated_image_url, |
| 73 const std::string& image_fetch_id, |
| 74 const gfx::Image& image); |
| 75 |
| 76 // Only valid if UseNewDoodleApi is disabled. |
| 44 LogoService* logo_service_; | 77 LogoService* logo_service_; |
| 45 | 78 |
| 79 // Only valid if UseNewDoodleApi is enabled. |
| 80 doodle::DoodleService* doodle_service_; |
| 81 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; |
| 82 base::android::ScopedJavaGlobalRef<jobject> j_logo_observer_; |
| 83 ScopedObserver<doodle::DoodleService, doodle::DoodleService::Observer> |
| 84 doodle_observer_; |
| 85 |
| 46 std::unique_ptr<AnimatedLogoFetcher> animated_logo_fetcher_; | 86 std::unique_ptr<AnimatedLogoFetcher> animated_logo_fetcher_; |
| 47 | 87 |
| 48 base::WeakPtrFactory<LogoBridge> weak_ptr_factory_; | 88 base::WeakPtrFactory<LogoBridge> weak_ptr_factory_; |
| 49 | 89 |
| 50 DISALLOW_COPY_AND_ASSIGN(LogoBridge); | 90 DISALLOW_COPY_AND_ASSIGN(LogoBridge); |
| 51 }; | 91 }; |
| 52 | 92 |
| 53 bool RegisterLogoBridge(JNIEnv* env); | 93 bool RegisterLogoBridge(JNIEnv* env); |
| 54 | 94 |
| 55 #endif // CHROME_BROWSER_ANDROID_LOGO_BRIDGE_H_ | 95 #endif // CHROME_BROWSER_ANDROID_LOGO_BRIDGE_H_ |
| OLD | NEW |