1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_RESULT_ICON_SOURCE_H_ 6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_RESULT_ICON_SOURCE_H_ 7 8 #include "base/basictypes.h" 9 #include "base/callback.h" 10 #include "base/memory/ref_counted.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "chrome/browser/image_decoder.h" 13 #include "net/url_request/url_fetcher_delegate.h" 14 #include "ui/gfx/image/image_skia.h" 15 #include "ui/gfx/image/image_skia_source.h" 16 #include "url/gurl.h" 17 18 namespace net { 19 class URLFetcher; 20 class URLRequestContextGetter; 21 } 22 23 namespace app_list { 24 25 // An ImageSkiaSource for the icon of web store result. It shows web store 26 // icon before the app icon is fetched. When the app icon is fetched 27 // successfully, it creates an representation using the app icon and web store 28 // icon as a badge. 29 class WebstoreResultIconSource : public gfx::ImageSkiaSource, 30 public net::URLFetcherDelegate, 31 public ImageDecoder::Delegate { 32 public: 33 typedef base::Closure IconLoadedCallback; 34 35 WebstoreResultIconSource(const IconLoadedCallback& icon_loaded_callback, 36 net::URLRequestContextGetter* context_getter, 37 const GURL& icon_url, 38 int icon_size); 39 virtual ~WebstoreResultIconSource(); 40 41 private: 42 // Invoked from GetImageForScale to download the app icon when the hosting 43 // ImageSkia gets painted on screen. 44 void StartIconFetch(); 45 46 // Creates the result icon by putting a small web store icon on the bottom 47 // right corner as a badge. 48 gfx::ImageSkiaRep CreateBadgedIcon(ui::ScaleFactor scale_factor); 49 50 // gfx::ImageSkiaSource overrides: 51 virtual gfx::ImageSkiaRep GetImageForScale( 52 ui::ScaleFactor scale_factor) OVERRIDE; 53 54 // net::URLFetcherDelegate overrides: 55 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 56 57 // ImageDecoder::Delegate overrides: 58 virtual void OnImageDecoded(const ImageDecoder* decoder, 59 const SkBitmap& decoded_image) OVERRIDE; 60 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; 61 62 IconLoadedCallback icon_loaded_callback_; 63 net::URLRequestContextGetter* context_getter_; 64 const GURL icon_url_; 65 const int icon_size_; 66 67 bool icon_fetch_attempted_; 68 scoped_ptr<net::URLFetcher> icon_fetcher_; 69 70 scoped_refptr<ImageDecoder> image_decoder_; 71 72 gfx::ImageSkia icon_; 73 74 DISALLOW_COPY_AND_ASSIGN(WebstoreResultIconSource); 75 }; 76 77 } // namespace app_list 78 79 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_RESULT_ICON_SOURCE_H_ 80