15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_THUMBNAILS_THUMBNAIL_SERVICE_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_THUMBNAILS_THUMBNAIL_SERVICE_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "components/history/core/common/thumbnail_score.h"
9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/content/refcounted_browser_context_keyed_service.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/image/image.h"
114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class GURL;
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RefCountedMemory;
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace thumbnails {
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ThumbnailingAlgorithm;
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct ThumbnailingContext;
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An interface abstracting access to thumbnails. Intended as a temporary
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// bridge facilitating switch from TopSites as the thumbnail source to a more
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// robust way of handling these artefacts.
2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class ThumbnailService : public RefcountedBrowserContextKeyedService {
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the given thumbnail for the given URL. Returns true if the thumbnail
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // was updated. False means either the URL wasn't known to us, or we felt
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that our current thumbnail was superior to the given one.
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool SetPageThumbnail(const ThumbnailingContext& context,
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                const gfx::Image& thumbnail) = 0;
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns the ThumbnailingAlgorithm used for processing thumbnails.
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // It is always a new instance, the caller owns it. It will encapsulate the
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // process of creating a thumbnail from tab contents. The lifetime of these
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // instances is limited to the act of processing a single tab image. They
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // are permitted to hold the state of such process.
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ThumbnailingAlgorithm* GetThumbnailingAlgorithm() const = 0;
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets a thumbnail for a given page. Returns true iff we have the thumbnail.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This may be invoked on any thread.
43d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // If an exact thumbnail URL match fails, |prefix_match| specifies whether or
444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // not to try harder by matching the query thumbnail URL as URL prefix (as
454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // defined by UrlIsPrefix()).
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // As this method may be invoked on any thread the ref count needs to be
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // incremented before this method returns, so this takes a scoped_refptr*.
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool GetPageThumbnail(
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& url,
50d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      bool prefix_match,
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      scoped_refptr<base::RefCountedMemory>* bytes) = 0;
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Add or updates a |url| for which we should force the capture of a thumbnail
54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // next time it's visited.
55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void AddForcedURL(const GURL& url) = 0;
56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the page thumbnail should be updated.
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool ShouldAcquirePageThumbnail(const GURL& url) = 0;
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~ThumbnailService() {}
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
64d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}  // namespace thumbnails
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_THUMBNAILS_THUMBNAIL_SERVICE_H_
67