Chromium Code Reviews| 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> | 10 #include <memory> |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 struct RequestMetadata; | 31 struct RequestMetadata; |
| 32 } // namespace image_fetcher | 32 } // namespace image_fetcher |
| 33 | 33 |
| 34 // The C++ counterpart to LogoBridge.java. Enables Java code to access the | 34 // The C++ counterpart to LogoBridge.java. Enables Java code to access the |
| 35 // default search provider's logo. | 35 // default search provider's logo. |
| 36 class LogoBridge : public doodle::DoodleService::Observer { | 36 class LogoBridge : public doodle::DoodleService::Observer { |
| 37 public: | 37 public: |
| 38 explicit LogoBridge(jobject j_profile); | 38 explicit LogoBridge(jobject j_profile); |
| 39 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 39 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 40 | 40 |
| 41 // TODO(treib): Double-check the observer contract (esp. for LogoTracker). | |
| 41 // Gets the current non-animated logo (downloading it if necessary) and passes | 42 // Gets the current non-animated logo (downloading it if necessary) and passes |
| 42 // it to the observer. | 43 // it to the observer. |
| 44 // The observer's |onLogoAvailable| is guaranteed to be called at least once: | |
| 45 // a) A cached doodle is available. | |
| 46 // b) A new doodle is available. | |
| 47 // c) The current doodle was revalidated.. | |
|
Marc Treib
2017/04/27 15:22:55
The comment above is now slightly misleading: This
fhorschig
2017/04/28 08:20:07
Gone. Correct, it's not relevant in this context.
| |
| 48 // d) Not having a doodle was revalidated. | |
| 43 void GetCurrentLogo( | 49 void GetCurrentLogo( |
| 44 JNIEnv* env, | 50 JNIEnv* env, |
| 45 const base::android::JavaParamRef<jobject>& obj, | 51 const base::android::JavaParamRef<jobject>& obj, |
| 46 const base::android::JavaParamRef<jobject>& j_logo_observer); | 52 const base::android::JavaParamRef<jobject>& j_logo_observer); |
| 47 | 53 |
| 48 // Downloads the animated logo from the given URL and returns it to the | 54 // Downloads the animated logo from the given URL and returns it to the |
| 49 // callback. Does not support multiple concurrent requests: A second request | 55 // callback. Does not support multiple concurrent requests: A second request |
| 50 // for the same URL will be ignored; a request for a different URL will cancel | 56 // for the same URL will be ignored; a request for a different URL will cancel |
| 51 // any ongoing request. If downloading fails, the callback is not called. | 57 // any ongoing request. If downloading fails, the callback is not called. |
| 52 void GetAnimatedLogo(JNIEnv* env, | 58 void GetAnimatedLogo(JNIEnv* env, |
| 53 const base::android::JavaParamRef<jobject>& obj, | 59 const base::android::JavaParamRef<jobject>& obj, |
| 54 const base::android::JavaParamRef<jobject>& j_callback, | 60 const base::android::JavaParamRef<jobject>& j_callback, |
| 55 const base::android::JavaParamRef<jstring>& j_url); | 61 const base::android::JavaParamRef<jstring>& j_url); |
| 56 | 62 |
| 57 private: | 63 private: |
| 58 class AnimatedLogoFetcher; | 64 class AnimatedLogoFetcher; |
| 59 | 65 |
| 60 virtual ~LogoBridge(); | 66 virtual ~LogoBridge(); |
| 61 | 67 |
| 62 // doodle::DoodleService::Observer implementation. | 68 // doodle::DoodleService::Observer implementation. |
| 69 void OnDoodleConfigRevalidated() override; | |
| 63 void OnDoodleConfigUpdated( | 70 void OnDoodleConfigUpdated( |
| 64 const base::Optional<doodle::DoodleConfig>& maybe_doodle_config) override; | 71 const base::Optional<doodle::DoodleConfig>& maybe_doodle_config) override; |
| 65 | 72 |
| 66 void DoodleConfigReceived( | 73 void NotifyNoLogoAvailable(bool from_cache); |
| 67 const base::Optional<doodle::DoodleConfig>& maybe_doodle_config, | 74 void FetchDoodleImage(const doodle::DoodleConfig& doodle_config, |
| 68 bool from_cache); | 75 bool from_cache); |
| 69 | |
| 70 void DoodleImageFetched(bool config_from_cache, | 76 void DoodleImageFetched(bool config_from_cache, |
| 71 const GURL& on_click_url, | 77 const GURL& on_click_url, |
| 72 const std::string& alt_text, | 78 const std::string& alt_text, |
| 73 const GURL& animated_image_url, | 79 const GURL& animated_image_url, |
| 74 const std::string& image_fetch_id, | 80 const std::string& image_fetch_id, |
| 75 const gfx::Image& image, | 81 const gfx::Image& image, |
| 76 const image_fetcher::RequestMetadata& metadata); | 82 const image_fetcher::RequestMetadata& metadata); |
| 77 | 83 |
| 78 // Only valid if UseNewDoodleApi is disabled. | 84 // Only valid if UseNewDoodleApi is disabled. |
| 79 LogoService* logo_service_; | 85 LogoService* logo_service_; |
| 80 | 86 |
| 81 // Only valid if UseNewDoodleApi is enabled. | 87 // Only valid if UseNewDoodleApi is enabled. |
| 82 doodle::DoodleService* doodle_service_; | 88 doodle::DoodleService* doodle_service_; |
| 83 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; | 89 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; |
| 84 base::android::ScopedJavaGlobalRef<jobject> j_logo_observer_; | 90 base::android::ScopedJavaGlobalRef<jobject> j_logo_observer_; |
| 85 ScopedObserver<doodle::DoodleService, doodle::DoodleService::Observer> | 91 ScopedObserver<doodle::DoodleService, doodle::DoodleService::Observer> |
| 86 doodle_observer_; | 92 doodle_observer_; |
| 87 | 93 |
| 88 std::unique_ptr<AnimatedLogoFetcher> animated_logo_fetcher_; | 94 std::unique_ptr<AnimatedLogoFetcher> animated_logo_fetcher_; |
| 89 | 95 |
| 90 base::WeakPtrFactory<LogoBridge> weak_ptr_factory_; | 96 base::WeakPtrFactory<LogoBridge> weak_ptr_factory_; |
| 91 | 97 |
| 92 DISALLOW_COPY_AND_ASSIGN(LogoBridge); | 98 DISALLOW_COPY_AND_ASSIGN(LogoBridge); |
| 93 }; | 99 }; |
| 94 | 100 |
| 95 bool RegisterLogoBridge(JNIEnv* env); | 101 bool RegisterLogoBridge(JNIEnv* env); |
| 96 | 102 |
| 97 #endif // CHROME_BROWSER_ANDROID_LOGO_BRIDGE_H_ | 103 #endif // CHROME_BROWSER_ANDROID_LOGO_BRIDGE_H_ |
| OLD | NEW |