1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_POPUP_PASSWORD_FAVICON_LOADER_H_
#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_POPUP_PASSWORD_FAVICON_LOADER_H_
#include "base/containers/lru_cache.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "components/autofill/core/browser/suggestions/suggestion.h"
namespace base {
class CancelableTaskTracker;
}
namespace favicon {
class LargeIconService;
}
namespace favicon_base {
struct LargeIconResult;
}
namespace gfx {
class Image;
}
namespace image_fetcher {
class ImageFetcher;
struct RequestMetadata;
} // namespace image_fetcher
class GURL;
namespace autofill {
// This class handles the process of loading favicons for websites associated
// with user credentials.
class PasswordFaviconLoader {
public:
using OnLoadSuccess = base::OnceCallback<void(const gfx::Image& image)>;
using OnLoadFail = base::OnceCallback<void()>;
virtual void Load(const Suggestion::FaviconDetails& favicon_details,
base::CancelableTaskTracker* task_tracker,
OnLoadSuccess on_success,
OnLoadFail on_fail) = 0;
};
class PasswordFaviconLoaderImpl : public PasswordFaviconLoader {
public:
PasswordFaviconLoaderImpl(favicon::LargeIconService* favicon_service,
image_fetcher::ImageFetcher* image_fetcher);
virtual ~PasswordFaviconLoaderImpl();
void Load(const Suggestion::FaviconDetails& favicon_details,
base::CancelableTaskTracker* task_tracker,
OnLoadSuccess on_success,
OnLoadFail on_fail) override;
private:
void OnFaviconResponse(const GURL& domain_url,
OnLoadSuccess on_success,
OnLoadFail on_fail,
const favicon_base::LargeIconResult& result);
void OnFaviconResponseFromImageFetcher(
const GURL& domain_url,
OnLoadSuccess on_success,
OnLoadFail on_fail,
const gfx::Image& image,
const image_fetcher::RequestMetadata& request_metadata);
const raw_ref<favicon::LargeIconService> favicon_service_;
const raw_ref<image_fetcher::ImageFetcher> image_fetcher_;
// The in-memory cache for icons downloaded through
// `favicon::LargeIconService`. It allows to synchronously respond to
// a favicon request and avoid image blinking on filter change (for those
// icons that were downloaded but not filtered out). This happens because
// the service API is asynchronous and we recreate the row view for every
// filter change.
base::LRUCache<GURL, gfx::Image> cache_;
base::WeakPtrFactory<PasswordFaviconLoaderImpl> weak_ptr_factory_{this};
};
} // namespace autofill
#endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_POPUP_PASSWORD_FAVICON_LOADER_H_
|