Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / search / thumbnail_source.cc
blobe2023c282ece51ddae10910e859608ba7c0f8920
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 #include "chrome/browser/search/thumbnail_source.h"
7 #include "base/callback.h"
8 #include "base/memory/ref_counted_memory.h"
9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/search/instant_io_context.h"
11 #include "chrome/browser/thumbnails/thumbnail_service.h"
12 #include "chrome/browser/thumbnails/thumbnail_service_factory.h"
13 #include "chrome/common/url_constants.h"
14 #include "net/url_request/url_request.h"
15 #include "url/gurl.h"
17 // Set ThumbnailService now as Profile isn't thread safe.
18 ThumbnailSource::ThumbnailSource(Profile* profile, bool capture_thumbnails)
19 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)),
20 capture_thumbnails_(capture_thumbnails) {
23 ThumbnailSource::~ThumbnailSource() {
26 std::string ThumbnailSource::GetSource() const {
27 return capture_thumbnails_ ?
28 chrome::kChromeUIThumbnailHost2 : chrome::kChromeUIThumbnailHost;
31 void ThumbnailSource::StartDataRequest(
32 const std::string& path,
33 int render_process_id,
34 int render_frame_id,
35 const content::URLDataSource::GotDataCallback& callback) {
36 scoped_refptr<base::RefCountedMemory> data;
37 if (thumbnail_service_->GetPageThumbnail(GURL(path), capture_thumbnails_,
38 &data)) {
39 // We have the thumbnail.
40 callback.Run(data.get());
41 } else {
42 callback.Run(default_thumbnail_.get());
44 if (capture_thumbnails_)
45 thumbnail_service_->AddForcedURL(GURL(path));
48 std::string ThumbnailSource::GetMimeType(const std::string&) const {
49 // We need to explicitly return a mime type, otherwise if the user tries to
50 // drag the image they get no extension.
51 return "image/png";
54 base::MessageLoop* ThumbnailSource::MessageLoopForRequestPath(
55 const std::string& path) const {
56 // TopSites can be accessed from the IO thread.
57 return thumbnail_service_.get() ?
58 NULL : content::URLDataSource::MessageLoopForRequestPath(path);
61 bool ThumbnailSource::ShouldServiceRequest(
62 const net::URLRequest* request) const {
63 if (request->url().SchemeIs(chrome::kChromeSearchScheme))
64 return InstantIOContext::ShouldServiceRequest(request);
65 return URLDataSource::ShouldServiceRequest(request);