Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 5 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 } | 28 } |
| 29 | 29 |
| 30 ThumbnailSource::~ThumbnailSource() { | 30 ThumbnailSource::~ThumbnailSource() { |
| 31 } | 31 } |
| 32 | 32 |
| 33 std::string ThumbnailSource::GetSource() const { | 33 std::string ThumbnailSource::GetSource() const { |
| 34 return chrome::kChromeUIThumbnailHost; | 34 return chrome::kChromeUIThumbnailHost; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void ThumbnailSource::StartDataRequest( | 37 void ThumbnailSource::StartDataRequest( |
| 38 const std::string& raw_path, | 38 const std::string& raw_path, |
|
Jered
2013/05/31 17:34:33
raw_path -> path
kmadhusu
2013/06/04 02:36:01
Done.
| |
| 39 int render_process_id, | 39 int render_process_id, |
| 40 int render_view_id, | 40 int render_view_id, |
| 41 const content::URLDataSource::GotDataCallback& callback) { | 41 const content::URLDataSource::GotDataCallback& callback) { |
| 42 // Translate to regular path if |raw_path| is of the form | |
| 43 // chrome-search://favicon/<id> or chrome-search://thumb/<id>, where <id> is | |
| 44 // an integer. | |
| 45 std::string path = raw_path; | |
| 46 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
| 47 std::map<std::string, std::string>::iterator it = | |
| 48 id_to_url_map_.find(raw_path); | |
| 49 if (it != id_to_url_map_.end()) { | |
| 50 path = id_to_url_map_[raw_path]; | |
| 51 id_to_url_map_.erase(it); | |
| 52 } | |
| 53 } else if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 54 path = InstantService::MaybeTranslateInstantPathOnUI(profile_, raw_path); | |
| 55 } | |
| 56 | |
| 57 scoped_refptr<base::RefCountedMemory> data; | 42 scoped_refptr<base::RefCountedMemory> data; |
| 58 if (thumbnail_service_->GetPageThumbnail(GURL(path), &data)) { | 43 if (thumbnail_service_->GetPageThumbnail(GURL(raw_path), &data)) { |
| 59 // We have the thumbnail. | 44 // We have the thumbnail. |
| 60 callback.Run(data.get()); | 45 callback.Run(data.get()); |
| 61 } else { | 46 } else { |
| 62 callback.Run(default_thumbnail_); | 47 callback.Run(default_thumbnail_); |
| 63 } | 48 } |
| 64 } | 49 } |
| 65 | 50 |
| 66 std::string ThumbnailSource::GetMimeType(const std::string&) const { | 51 std::string ThumbnailSource::GetMimeType(const std::string&) const { |
| 67 // We need to explicitly return a mime type, otherwise if the user tries to | 52 // We need to explicitly return a mime type, otherwise if the user tries to |
| 68 // drag the image they get no extension. | 53 // drag the image they get no extension. |
| 69 return "image/png"; | 54 return "image/png"; |
| 70 } | 55 } |
| 71 | 56 |
| 72 base::MessageLoop* ThumbnailSource::MessageLoopForRequestPath( | 57 base::MessageLoop* ThumbnailSource::MessageLoopForRequestPath( |
| 73 const std::string& path) const { | 58 const std::string& path) const { |
| 74 // TopSites can be accessed from the IO thread. | 59 // TopSites can be accessed from the IO thread. |
| 75 return thumbnail_service_.get() ? | 60 return thumbnail_service_.get() ? |
| 76 NULL : content::URLDataSource::MessageLoopForRequestPath(path); | 61 NULL : content::URLDataSource::MessageLoopForRequestPath(path); |
| 77 } | 62 } |
| 78 | 63 |
| 79 bool ThumbnailSource::ShouldServiceRequest( | 64 bool ThumbnailSource::ShouldServiceRequest( |
| 80 const net::URLRequest* request) const { | 65 const net::URLRequest* request) const { |
| 81 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { | 66 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { |
| 82 if (InstantService::IsInstantPath(request->url()) && | 67 // Strip leading slash from path. |
| 83 InstantIOContext::ShouldServiceRequest(request)) { | 68 std::string raw_path = request->url().path().substr(1); |
|
Jered
2013/05/31 17:34:33
Same comment here about the check for an empty pat
kmadhusu
2013/06/04 02:36:01
Fixed.
| |
| 84 // If this request will be serviced on the IO thread, then do the | 69 return !raw_path.empty() && InstantIOContext::ShouldServiceRequest(request); |
| 85 // translation from raw_path to path here, where we have the |request| | |
| 86 // object in-hand, saving the result for later use. | |
| 87 | |
| 88 // Strip leading slash from path. | |
| 89 std::string raw_path = request->url().path().substr(1); | |
| 90 if (!MessageLoopForRequestPath(raw_path)) { | |
| 91 id_to_url_map_[raw_path] = | |
| 92 InstantService::MaybeTranslateInstantPathOnIO(request, raw_path); | |
| 93 } | |
| 94 return true; | |
| 95 } | |
| 96 return false; | |
| 97 } | 70 } |
| 98 return URLDataSource::ShouldServiceRequest(request); | 71 return URLDataSource::ShouldServiceRequest(request); |
| 99 } | 72 } |
| OLD | NEW |