summaryrefslogtreecommitdiffstats
path: root/ios/chrome/browser/favicon/large_icon_cache.h
blob: 5d7d447225037e6a2a0b0f1ddea14ee29d975f06 (plain)
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
// 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 IOS_CHROME_BROWSER_FAVICON_LARGE_ICON_CACHE_H_
#define IOS_CHROME_BROWSER_FAVICON_LARGE_ICON_CACHE_H_

#include "base/containers/mru_cache.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "components/keyed_service/core/keyed_service.h"

class GURL;
struct LargeIconCacheEntry;

namespace favicon_base {
struct LargeIconResult;
}

namespace ios {
class ChromeBrowserState;
}

// Provides a cache of most recently used LargeIconResult.
//
// Example usage:
//   LargeIconCache* large_icon_cache =
//       IOSChromeLargeIconServiceFactory::GetForBrowserState(browser_state);
//   scoped_ptr<favicon_base::LargeIconResult> icon =
//       large_icon_cache->GetCachedResult(...);
//
class LargeIconCache : public KeyedService {
 public:
  LargeIconCache();
  ~LargeIconCache() override;

  // |LargeIconService| does everything on callbacks, and iOS needs to load the
  // icons immediately on page load. This caches the LargeIconResult so we can
  // immediately load.
  void SetCachedResult(const GURL& url, const favicon_base::LargeIconResult&);

  // Returns a cached LargeIconResult.
  scoped_ptr<favicon_base::LargeIconResult> GetCachedResult(const GURL& url);

 private:
  // Clones a LargeIconResult.
  scoped_ptr<favicon_base::LargeIconResult> CloneLargeIconResult(
      const favicon_base::LargeIconResult& large_icon_result);

  base::MRUCache<GURL, scoped_ptr<LargeIconCacheEntry>> cache_;

  DISALLOW_COPY_AND_ASSIGN(LargeIconCache);
};

#endif  // IOS_CHROME_BROWSER_FAVICON_LARGE_ICON_CACHE_H_