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) Not having a doodle was revalidated. |
43 void GetCurrentLogo( | 48 void GetCurrentLogo( |
44 JNIEnv* env, | 49 JNIEnv* env, |
45 const base::android::JavaParamRef<jobject>& obj, | 50 const base::android::JavaParamRef<jobject>& obj, |
46 const base::android::JavaParamRef<jobject>& j_logo_observer); | 51 const base::android::JavaParamRef<jobject>& j_logo_observer); |
47 | 52 |
48 // Downloads the animated logo from the given URL and returns it to the | 53 // Downloads the animated logo from the given URL and returns it to the |
49 // callback. Does not support multiple concurrent requests: A second request | 54 // 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 | 55 // 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. | 56 // any ongoing request. If downloading fails, the callback is not called. |
52 void GetAnimatedLogo(JNIEnv* env, | 57 void GetAnimatedLogo(JNIEnv* env, |
53 const base::android::JavaParamRef<jobject>& obj, | 58 const base::android::JavaParamRef<jobject>& obj, |
54 const base::android::JavaParamRef<jobject>& j_callback, | 59 const base::android::JavaParamRef<jobject>& j_callback, |
55 const base::android::JavaParamRef<jstring>& j_url); | 60 const base::android::JavaParamRef<jstring>& j_url); |
56 | 61 |
57 private: | 62 private: |
58 class AnimatedLogoFetcher; | 63 class AnimatedLogoFetcher; |
59 | 64 |
60 virtual ~LogoBridge(); | 65 virtual ~LogoBridge(); |
61 | 66 |
62 // doodle::DoodleService::Observer implementation. | 67 // doodle::DoodleService::Observer implementation. |
| 68 void OnDoodleConfigRevalidated() override; |
63 void OnDoodleConfigUpdated( | 69 void OnDoodleConfigUpdated( |
64 const base::Optional<doodle::DoodleConfig>& maybe_doodle_config) override; | 70 const base::Optional<doodle::DoodleConfig>& maybe_doodle_config) override; |
65 | 71 |
66 void DoodleConfigReceived( | 72 void NotifyNoLogoAvailable(bool from_cache); |
67 const base::Optional<doodle::DoodleConfig>& maybe_doodle_config, | 73 void FetchDoodleImage(const doodle::DoodleConfig& doodle_config, |
68 bool from_cache); | 74 bool from_cache); |
69 | |
70 void DoodleImageFetched(bool config_from_cache, | 75 void DoodleImageFetched(bool config_from_cache, |
71 const GURL& on_click_url, | 76 const GURL& on_click_url, |
72 const std::string& alt_text, | 77 const std::string& alt_text, |
73 const GURL& animated_image_url, | 78 const GURL& animated_image_url, |
74 const std::string& image_fetch_id, | 79 const std::string& image_fetch_id, |
75 const gfx::Image& image, | 80 const gfx::Image& image, |
76 const image_fetcher::RequestMetadata& metadata); | 81 const image_fetcher::RequestMetadata& metadata); |
77 | 82 |
78 // Only valid if UseNewDoodleApi is disabled. | 83 // Only valid if UseNewDoodleApi is disabled. |
79 LogoService* logo_service_; | 84 LogoService* logo_service_; |
80 | 85 |
81 // Only valid if UseNewDoodleApi is enabled. | 86 // Only valid if UseNewDoodleApi is enabled. |
82 doodle::DoodleService* doodle_service_; | 87 doodle::DoodleService* doodle_service_; |
83 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; | 88 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; |
84 base::android::ScopedJavaGlobalRef<jobject> j_logo_observer_; | 89 base::android::ScopedJavaGlobalRef<jobject> j_logo_observer_; |
85 ScopedObserver<doodle::DoodleService, doodle::DoodleService::Observer> | 90 ScopedObserver<doodle::DoodleService, doodle::DoodleService::Observer> |
86 doodle_observer_; | 91 doodle_observer_; |
87 | 92 |
88 std::unique_ptr<AnimatedLogoFetcher> animated_logo_fetcher_; | 93 std::unique_ptr<AnimatedLogoFetcher> animated_logo_fetcher_; |
89 | 94 |
90 base::WeakPtrFactory<LogoBridge> weak_ptr_factory_; | 95 base::WeakPtrFactory<LogoBridge> weak_ptr_factory_; |
91 | 96 |
92 DISALLOW_COPY_AND_ASSIGN(LogoBridge); | 97 DISALLOW_COPY_AND_ASSIGN(LogoBridge); |
93 }; | 98 }; |
94 | 99 |
95 bool RegisterLogoBridge(JNIEnv* env); | 100 bool RegisterLogoBridge(JNIEnv* env); |
96 | 101 |
97 #endif // CHROME_BROWSER_ANDROID_LOGO_BRIDGE_H_ | 102 #endif // CHROME_BROWSER_ANDROID_LOGO_BRIDGE_H_ |
OLD | NEW |