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.
5 #ifndef CHROME_BROWSER_SEARCH_THUMBNAIL_SOURCE_H_
6 #define CHROME_BROWSER_SEARCH_THUMBNAIL_SOURCE_H_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/public/browser/url_data_source.h"
20 class RefCountedMemory
;
23 namespace thumbnails
{
24 class ThumbnailService
;
27 namespace suggestions
{
31 // ThumbnailSource is the gateway between network-level chrome: requests for
32 // thumbnails and the history/top-sites backend that serves these.
33 class ThumbnailSource
: public content::URLDataSource
{
35 ThumbnailSource(Profile
* profile
, bool capture_thumbnails
);
36 ~ThumbnailSource() override
;
38 // content::URLDataSource implementation.
39 std::string
GetSource() const override
;
40 void StartDataRequest(
41 const std::string
& path
,
42 int render_process_id
,
44 const content::URLDataSource::GotDataCallback
& callback
) override
;
45 std::string
GetMimeType(const std::string
& path
) const override
;
46 base::MessageLoop
* MessageLoopForRequestPath(
47 const std::string
& path
) const override
;
48 bool ShouldServiceRequest(const net::URLRequest
* request
) const override
;
50 // Extracts the |page_url| (e.g. cnn.com) and the |fallback_thumbnail_url|
51 // fetchable from the server, if present, from the |path|. Visible for
53 void ExtractPageAndThumbnailUrls(const std::string
& path
,
55 GURL
* fallback_thumbnail_url
);
58 // Returns a JPEG-encoded |bitmap| to the |callback| if valid, or the default
60 void SendFetchedUrlImage(
61 const content::URLDataSource::GotDataCallback
& callback
,
63 const SkBitmap
* bitmap
);
65 // Raw PNG representation of the thumbnail to show when the thumbnail
66 // database doesn't have a thumbnail for a webpage.
67 scoped_refptr
<base::RefCountedMemory
> default_thumbnail_
;
70 scoped_refptr
<thumbnails::ThumbnailService
> thumbnail_service_
;
73 scoped_ptr
<suggestions::ImageFetcher
> image_fetcher_
;
75 // Indicate that, when a URL for which we don't have a thumbnail is requested
76 // from this source, then Chrome should capture a thumbnail next time it
77 // navigates to this URL. This is useful when the thumbnail URLs are generated
78 // by an external service rather than TopSites, so Chrome can learn about the
79 // URLs for which it should get thumbnails. Sources that capture thumbnails
80 // are also be more lenient when matching thumbnail URLs by checking for
81 // existing thumbnails in the database that contain a URL matching the prefix
82 // of the requested URL.
83 const bool capture_thumbnails_
;
85 base::WeakPtrFactory
<ThumbnailSource
> weak_ptr_factory_
;
87 DISALLOW_COPY_AND_ASSIGN(ThumbnailSource
);
90 #endif // CHROME_BROWSER_SEARCH_THUMBNAIL_SOURCE_H_