thumbnail_service.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/thumbnail_score.h" 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "components/browser_context_keyed_service/refcounted_browser_context_keyed_service.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "googleurl/src/gurl.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/image/image.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RefCountedMemory; 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace thumbnails { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ThumbnailingAlgorithm; 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct ThumbnailingContext; 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An interface abstracting access to thumbnails. Intended as a temporary 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// bridge facilitating switch from TopSites as the thumbnail source to a more 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// robust way of handling these artefacts. 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class ThumbnailService : public RefcountedBrowserContextKeyedService { 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the given thumbnail for the given URL. Returns true if the thumbnail 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // was updated. False means either the URL wasn't known to us, or we felt 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that our current thumbnail was superior to the given one. 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool SetPageThumbnail(const ThumbnailingContext& context, 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Image& thumbnail) = 0; 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the ThumbnailingAlgorithm used for processing thumbnails. 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // It is always a new instance, the caller owns it. It will encapsulate the 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // process of creating a thumbnail from tab contents. The lifetime of these 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // instances is limited to the act of processing a single tab image. They 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // are permitted to hold the state of such process. 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ThumbnailingAlgorithm* GetThumbnailingAlgorithm() const = 0; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets a thumbnail for a given page. Returns true iff we have the thumbnail. 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This may be invoked on any thread. 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // As this method may be invoked on any thread the ref count needs to be 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // incremented before this method returns, so this takes a scoped_refptr*. 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool GetPageThumbnail( 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url, 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<base::RefCountedMemory>* bytes) = 0; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the page thumbnail should be updated. 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool ShouldAcquirePageThumbnail(const GURL& url) = 0; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~ThumbnailService() {} 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_THUMBNAILS_THUMBNAIL_SERVICE_H_ 58