summaryrefslogtreecommitdiffstats
path: root/chrome/browser/thumbnails/thumbnail_service.h
blob: 41444366f0820bf23e0d250817488e5ad2fe69ff (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
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2012 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_THUMBNAILS_THUMBNAIL_SERVICE_H_
#define CHROME_BROWSER_THUMBNAILS_THUMBNAIL_SERVICE_H_

#include "components/history/core/common/thumbnail_score.h"
#include "components/keyed_service/content/refcounted_browser_context_keyed_service.h"
#include "ui/gfx/image/image.h"

class GURL;

namespace base {
class RefCountedMemory;
}

namespace thumbnails {

class ThumbnailingAlgorithm;
struct ThumbnailingContext;

// An interface abstracting access to thumbnails. Intended as a temporary
// bridge facilitating switch from TopSites as the thumbnail source to a more
// robust way of handling these artefacts.
class ThumbnailService : public RefcountedBrowserContextKeyedService {
 public:
  // Sets the given thumbnail for the given URL. Returns true if the thumbnail
  // was updated. False means either the URL wasn't known to us, or we felt
  // that our current thumbnail was superior to the given one.
  virtual bool SetPageThumbnail(const ThumbnailingContext& context,
                                const gfx::Image& thumbnail) = 0;

  // Returns the ThumbnailingAlgorithm used for processing thumbnails.
  // It is always a new instance, the caller owns it. It will encapsulate the
  // process of creating a thumbnail from tab contents. The lifetime of these
  // instances is limited to the act of processing a single tab image. They
  // are permitted to hold the state of such process.
  virtual ThumbnailingAlgorithm* GetThumbnailingAlgorithm() const = 0;

  // Gets a thumbnail for a given page. Returns true iff we have the thumbnail.
  // This may be invoked on any thread.
  // If an exact thumbnail URL match fails, |prefix_match| specifies whether or
  // not to try harder by matching the query thumbnail URL as URL prefix (as
  // defined by UrlIsPrefix()).
  // As this method may be invoked on any thread the ref count needs to be
  // incremented before this method returns, so this takes a scoped_refptr*.
  virtual bool GetPageThumbnail(
      const GURL& url,
      bool prefix_match,
      scoped_refptr<base::RefCountedMemory>* bytes) = 0;

  // Add or updates a |url| for which we should force the capture of a thumbnail
  // next time it's visited.
  virtual void AddForcedURL(const GURL& url) = 0;

  // Returns true if the page thumbnail should be updated.
  virtual bool ShouldAcquirePageThumbnail(const GURL& url) = 0;

 protected:
  virtual ~ThumbnailService() {}
};

}  // namespace thumbnails

#endif  // CHROME_BROWSER_THUMBNAILS_THUMBNAIL_SERVICE_H_