• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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_THUMBNAILS_THUMBNAIL_SERVICE_H_
6 #define CHROME_BROWSER_THUMBNAILS_THUMBNAIL_SERVICE_H_
7 
8 #include "components/history/core/common/thumbnail_score.h"
9 #include "components/keyed_service/content/refcounted_browser_context_keyed_service.h"
10 #include "ui/gfx/image/image.h"
11 
12 class GURL;
13 
14 namespace base {
15 class RefCountedMemory;
16 }
17 
18 namespace thumbnails {
19 
20 class ThumbnailingAlgorithm;
21 struct ThumbnailingContext;
22 
23 // An interface abstracting access to thumbnails. Intended as a temporary
24 // bridge facilitating switch from TopSites as the thumbnail source to a more
25 // robust way of handling these artefacts.
26 class ThumbnailService : public RefcountedBrowserContextKeyedService {
27  public:
28   // Sets the given thumbnail for the given URL. Returns true if the thumbnail
29   // was updated. False means either the URL wasn't known to us, or we felt
30   // that our current thumbnail was superior to the given one.
31   virtual bool SetPageThumbnail(const ThumbnailingContext& context,
32                                 const gfx::Image& thumbnail) = 0;
33 
34   // Returns the ThumbnailingAlgorithm used for processing thumbnails.
35   // It is always a new instance, the caller owns it. It will encapsulate the
36   // process of creating a thumbnail from tab contents. The lifetime of these
37   // instances is limited to the act of processing a single tab image. They
38   // are permitted to hold the state of such process.
39   virtual ThumbnailingAlgorithm* GetThumbnailingAlgorithm() const = 0;
40 
41   // Gets a thumbnail for a given page. Returns true iff we have the thumbnail.
42   // This may be invoked on any thread.
43   // If an exact thumbnail URL match fails, |prefix_match| specifies whether or
44   // not to try harder by matching the query thumbnail URL as URL prefix (as
45   // defined by UrlIsPrefix()).
46   // As this method may be invoked on any thread the ref count needs to be
47   // incremented before this method returns, so this takes a scoped_refptr*.
48   virtual bool GetPageThumbnail(
49       const GURL& url,
50       bool prefix_match,
51       scoped_refptr<base::RefCountedMemory>* bytes) = 0;
52 
53   // Add or updates a |url| for which we should force the capture of a thumbnail
54   // next time it's visited.
55   virtual void AddForcedURL(const GURL& url) = 0;
56 
57   // Returns true if the page thumbnail should be updated.
58   virtual bool ShouldAcquirePageThumbnail(const GURL& url) = 0;
59 
60  protected:
~ThumbnailService()61   virtual ~ThumbnailService() {}
62 };
63 
64 }  // namespace thumbnails
65 
66 #endif  // CHROME_BROWSER_THUMBNAILS_THUMBNAIL_SERVICE_H_
67