| 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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 namespace image_fetcher { | 29 namespace image_fetcher { |
| 30 class ImageFetcher; | 30 class ImageFetcher; |
| 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 // Stores its creation time and writes it to a UMA histogram. Each instance |
| 39 // writes the metric once or never. |
| 40 class LoadTimeMetricRecorder { |
| 41 public: |
| 42 // Writes the diff between |Now| and the recorders creation time to a UMA |
| 43 // metric. If the recorder was aborted/finished before, nothing happens. |
| 44 virtual void Finish() = 0; |
| 45 |
| 46 // The recorder instance immediately stops to record. |
| 47 virtual void Cancel() = 0; |
| 48 }; |
| 49 |
| 38 explicit LogoBridge(jobject j_profile); | 50 explicit LogoBridge(jobject j_profile); |
| 39 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 51 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 40 | 52 |
| 41 // Gets the current non-animated logo (downloading it if necessary) and passes | 53 // Gets the current non-animated logo (downloading it if necessary) and passes |
| 42 // it to the observer. | 54 // it to the observer. |
| 43 void GetCurrentLogo( | 55 void GetCurrentLogo( |
| 44 JNIEnv* env, | 56 JNIEnv* env, |
| 45 const base::android::JavaParamRef<jobject>& obj, | 57 const base::android::JavaParamRef<jobject>& obj, |
| 46 const base::android::JavaParamRef<jobject>& j_logo_observer); | 58 const base::android::JavaParamRef<jobject>& j_logo_observer); |
| 47 | 59 |
| 48 // Downloads the animated logo from the given URL and returns it to the | 60 // Downloads the animated logo from the given URL and returns it to the |
| 49 // callback. Does not support multiple concurrent requests: A second request | 61 // 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 | 62 // 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. | 63 // any ongoing request. If downloading fails, the callback is not called. |
| 52 void GetAnimatedLogo(JNIEnv* env, | 64 void GetAnimatedLogo(JNIEnv* env, |
| 53 const base::android::JavaParamRef<jobject>& obj, | 65 const base::android::JavaParamRef<jobject>& obj, |
| 54 const base::android::JavaParamRef<jobject>& j_callback, | 66 const base::android::JavaParamRef<jobject>& j_callback, |
| 55 const base::android::JavaParamRef<jstring>& j_url); | 67 const base::android::JavaParamRef<jstring>& j_url); |
| 56 | 68 |
| 57 private: | 69 private: |
| 58 class AnimatedLogoFetcher; | 70 class AnimatedLogoFetcher; |
| 59 | 71 |
| 60 virtual ~LogoBridge(); | 72 virtual ~LogoBridge(); |
| 61 | 73 |
| 62 // doodle::DoodleService::Observer implementation. | 74 // doodle::DoodleService::Observer implementation. |
| 63 void OnDoodleConfigUpdated( | 75 void OnDoodleConfigUpdated( |
| 64 const base::Optional<doodle::DoodleConfig>& maybe_doodle_config) override; | 76 const base::Optional<doodle::DoodleConfig>& maybe_doodle_config) override; |
| 65 | 77 |
| 66 void DoodleConfigReceived( | 78 // Takes a config and loads the image for it. Returns true if the image is |
| 79 // loading. |
| 80 bool DoodleConfigReceived( |
| 67 const base::Optional<doodle::DoodleConfig>& maybe_doodle_config, | 81 const base::Optional<doodle::DoodleConfig>& maybe_doodle_config, |
| 68 bool from_cache); | 82 bool from_cache); |
| 69 | 83 |
| 70 void DoodleImageFetched(bool config_from_cache, | 84 void DoodleImageFetched(bool config_from_cache, |
| 71 const GURL& on_click_url, | 85 const GURL& on_click_url, |
| 72 const std::string& alt_text, | 86 const std::string& alt_text, |
| 73 const GURL& animated_image_url, | 87 const GURL& animated_image_url, |
| 74 const std::string& image_fetch_id, | 88 const std::string& image_fetch_id, |
| 75 const gfx::Image& image, | 89 const gfx::Image& image, |
| 76 const image_fetcher::RequestMetadata& metadata); | 90 const image_fetcher::RequestMetadata& metadata); |
| 77 | 91 |
| 92 // Returns the currently running LoadTimeRecorder. If there is none, a null |
| 93 // object is returned. |
| 94 LoadTimeMetricRecorder* load_time_recorder(); |
| 95 |
| 78 // Only valid if UseNewDoodleApi is disabled. | 96 // Only valid if UseNewDoodleApi is disabled. |
| 79 LogoService* logo_service_; | 97 LogoService* logo_service_; |
| 80 | 98 |
| 81 // Only valid if UseNewDoodleApi is enabled. | 99 // Only valid if UseNewDoodleApi is enabled. |
| 82 doodle::DoodleService* doodle_service_; | 100 doodle::DoodleService* doodle_service_; |
| 83 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; | 101 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; |
| 84 base::android::ScopedJavaGlobalRef<jobject> j_logo_observer_; | 102 base::android::ScopedJavaGlobalRef<jobject> j_logo_observer_; |
| 85 ScopedObserver<doodle::DoodleService, doodle::DoodleService::Observer> | 103 ScopedObserver<doodle::DoodleService, doodle::DoodleService::Observer> |
| 86 doodle_observer_; | 104 doodle_observer_; |
| 87 | 105 |
| 88 std::unique_ptr<AnimatedLogoFetcher> animated_logo_fetcher_; | 106 std::unique_ptr<AnimatedLogoFetcher> animated_logo_fetcher_; |
| 89 | 107 |
| 108 std::unique_ptr<LoadTimeMetricRecorder> load_time_recorder_; |
| 109 |
| 90 base::WeakPtrFactory<LogoBridge> weak_ptr_factory_; | 110 base::WeakPtrFactory<LogoBridge> weak_ptr_factory_; |
| 91 | 111 |
| 92 DISALLOW_COPY_AND_ASSIGN(LogoBridge); | 112 DISALLOW_COPY_AND_ASSIGN(LogoBridge); |
| 93 }; | 113 }; |
| 94 | 114 |
| 95 bool RegisterLogoBridge(JNIEnv* env); | 115 bool RegisterLogoBridge(JNIEnv* env); |
| 96 | 116 |
| 97 #endif // CHROME_BROWSER_ANDROID_LOGO_BRIDGE_H_ | 117 #endif // CHROME_BROWSER_ANDROID_LOGO_BRIDGE_H_ |
| OLD | NEW |