Chromium Code Reviews| Index: chrome/browser/ui/webui/ntp/thumbnail_source.cc |
| diff --git a/chrome/browser/ui/webui/ntp/thumbnail_source.cc b/chrome/browser/ui/webui/ntp/thumbnail_source.cc |
| index 706b760592df07346b0058a3aa2c0cbb9eee0d0b..96686c72f2df335cee3a75dad57c63f0fc03967d 100644 |
| --- a/chrome/browser/ui/webui/ntp/thumbnail_source.cc |
| +++ b/chrome/browser/ui/webui/ntp/thumbnail_source.cc |
| @@ -7,7 +7,10 @@ |
| #include "base/callback.h" |
| #include "base/message_loop.h" |
| #include "base/memory/ref_counted_memory.h" |
| +#include "base/strings/string_number_conversions.h" |
| #include "chrome/browser/instant/instant_io_context.h" |
| +#include "chrome/browser/instant/instant_service.h" |
| +#include "chrome/browser/instant/instant_service_factory.h" |
| #include "chrome/browser/thumbnails/thumbnail_service.h" |
| #include "chrome/browser/thumbnails/thumbnail_service_factory.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -17,9 +20,29 @@ |
| #include "net/url_request/url_request.h" |
| #include "ui/base/resource/resource_bundle.h" |
| +using content::BrowserThread; |
| + |
| +namespace { |
| + |
| +const std::string MaybeTranslateInstantPath( |
|
palmer
2013/03/11 20:42:31
This is (or is nearly) duplicate code. Unify it by
dhollowa
2013/03/11 23:27:59
I considered that, but the two code paths are on d
|
| + const net::URLRequest* request, const std::string& path) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + uint64 restricted_id = 0; |
| + if (base::StringToUint64(path, &restricted_id)) { |
| + GURL url; |
| + if (InstantIOContext::GetURLForRestrictedId(request, restricted_id, &url)) |
| + return url.spec(); |
| + } |
| + return path; |
| +} |
| + |
| +} |
| + |
| // Set ThumbnailService now as Profile isn't thread safe. |
| ThumbnailSource::ThumbnailSource(Profile* profile) |
| - : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)) { |
| + : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)), |
| + current_request_(NULL), |
| + profile_(profile) { |
| } |
| ThumbnailSource::~ThumbnailSource() { |
| @@ -30,9 +53,17 @@ std::string ThumbnailSource::GetSource() { |
| } |
| void ThumbnailSource::StartDataRequest( |
| - const std::string& path, |
| + const std::string& raw_path, |
| bool is_incognito, |
| const content::URLDataSource::GotDataCallback& callback) { |
| + // Translate to regular path if |raw_path| is of the form |
| + // chrome-search://favicon/<rid>, where rid is a uint64. |
| + std::string path = raw_path; |
| + if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
| + path = MaybeTranslateInstantPath(current_request_, raw_path); |
| + else if (BrowserThread::CurrentlyOn(BrowserThread::UI)) |
| + path = InstantService::MaybeTranslateInstantPath(profile_, raw_path); |
| + |
| scoped_refptr<base::RefCountedMemory> data; |
| if (thumbnail_service_->GetPageThumbnail(GURL(path), &data)) { |
| // We have the thumbnail. |
| @@ -40,6 +71,7 @@ void ThumbnailSource::StartDataRequest( |
| } else { |
| callback.Run(default_thumbnail_); |
| } |
| + current_request_ = NULL; |
| } |
| std::string ThumbnailSource::GetMimeType(const std::string&) const { |
| @@ -57,7 +89,10 @@ MessageLoop* ThumbnailSource::MessageLoopForRequestPath( |
| bool ThumbnailSource::ShouldServiceRequest( |
| const net::URLRequest* request) const { |
| - if (request->url().SchemeIs(chrome::kChromeSearchScheme)) |
| - return InstantIOContext::ShouldServiceRequest(request); |
| + current_request_ = request; |
| + if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { |
| + return InstantService::IsInstantPath(request->url()) && |
| + InstantIOContext::ShouldServiceRequest(request); |
| + } |
| return URLDataSource::ShouldServiceRequest(request); |
| } |