Chromium Code Reviews| Index: chrome/browser/manifest/manifest_icon_downloader.h |
| diff --git a/chrome/browser/manifest/manifest_icon_downloader.h b/chrome/browser/manifest/manifest_icon_downloader.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d071ce71798d3f999a704f2c0afceaf401c26de4 |
| --- /dev/null |
| +++ b/chrome/browser/manifest/manifest_icon_downloader.h |
| @@ -0,0 +1,68 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_MANIFEST_MANIFEST_ICON_DOWNLOADER_H_ |
| +#define CHROME_BROWSER_MANIFEST_MANIFEST_ICON_DOWNLOADER_H_ |
| + |
| +#include "base/basictypes.h" |
| +#include "base/bind.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "content/public/browser/web_contents_observer.h" |
| +#include "third_party/skia/include/core/SkBitmap.h" |
| + |
| +namespace content { |
| +class WebContents; |
| +} // namespace content |
| + |
| +namespace gfx { |
| +class Size; |
| +} // namespace gfx |
|
mlamouri (slow - plz ping)
2015/08/10 15:08:08
nit: two spaces between "}" and "//"
Lalit Maganti
2015/08/10 16:55:46
Done.
|
| + |
| +class GURL; |
| + |
| +class ManifestIconDownloader |
| + : public content::WebContentsObserver { |
|
mlamouri (slow - plz ping)
2015/08/10 15:08:08
Sorry to point that so late but it seems that usin
Lalit Maganti
2015/08/10 16:55:46
Done.
|
| + public: |
| + using IconFetchCallback = base::Callback<void(const SkBitmap&)>; |
| + |
| + explicit ManifestIconDownloader(content::WebContents* web_contents); |
| + ~ManifestIconDownloader() override = default; |
| + |
| + // Downloads the icon located at icon_url. If the file contains multiple icons |
| + // then it attempts to pick the one closest in size bigger than or |
| + // equal to ideal_icon_size_in_dp, taking into account the density of the |
| + // device. If a bigger icon is chosen then ,the icon is scaled down to be |
| + // equal to ideal_icon_size_in_dp. |
| + // Returns whether the download has started. It will return false if the |
| + // current context or information do not allow to download the image. |
| + bool Download(const GURL& icon_url, |
| + int ideal_icon_size_in_dp, |
| + const IconFetchCallback& callback); |
| + |
| + private: |
| + // Callback run after the manifest icon downloaded successfully or the |
| + // download failed. |
| + static void OnIconFetched(const int ideal_icon_size_in_px, |
| + const IconFetchCallback& callback, |
| + int id, |
| + int http_status_code, |
| + const GURL& url, |
| + const std::vector<SkBitmap>& bitmaps, |
| + const std::vector<gfx::Size>& sizes); |
| + static void ScaleIcon(const int ideal_icon_size_in_px, |
|
mlamouri (slow - plz ping)
2015/08/10 15:08:08
nit: to be consistent, leave an empty line before
Lalit Maganti
2015/08/10 16:55:46
Done.
|
| + const SkBitmap& bitmap, |
| + const IconFetchCallback& callback); |
| + static void RunCallbackOnUIThread( |
|
mlamouri (slow - plz ping)
2015/08/10 15:08:08
ditto
Lalit Maganti
2015/08/10 16:55:46
Removed altogether.
|
| + const ManifestIconDownloader::IconFetchCallback& callback, |
| + const SkBitmap& bitmap); |
| + |
| + static int FindClosestBitmapIndex(const int ideal_icon_size_in_px, |
| + const std::vector<SkBitmap>& bitmaps); |
| + |
| + friend class ManifestIconDownloaderTest; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ManifestIconDownloader); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_DOWNLOADER_H_ |