| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 callback.Run(default_thumbnail_); | 61 callback.Run(default_thumbnail_); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 std::string ThumbnailSource::GetMimeType(const std::string&) const { | 65 std::string ThumbnailSource::GetMimeType(const std::string&) const { |
| 66 // We need to explicitly return a mime type, otherwise if the user tries to | 66 // We need to explicitly return a mime type, otherwise if the user tries to |
| 67 // drag the image they get no extension. | 67 // drag the image they get no extension. |
| 68 return "image/png"; | 68 return "image/png"; |
| 69 } | 69 } |
| 70 | 70 |
| 71 MessageLoop* ThumbnailSource::MessageLoopForRequestPath( | 71 base::MessageLoop* ThumbnailSource::MessageLoopForRequestPath( |
| 72 const std::string& path) const { | 72 const std::string& path) const { |
| 73 // TopSites can be accessed from the IO thread. | 73 // TopSites can be accessed from the IO thread. |
| 74 return thumbnail_service_.get() ? | 74 return thumbnail_service_.get() ? |
| 75 NULL : content::URLDataSource::MessageLoopForRequestPath(path); | 75 NULL : content::URLDataSource::MessageLoopForRequestPath(path); |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool ThumbnailSource::ShouldServiceRequest( | 78 bool ThumbnailSource::ShouldServiceRequest( |
| 79 const net::URLRequest* request) const { | 79 const net::URLRequest* request) const { |
| 80 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { | 80 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { |
| 81 if (InstantService::IsInstantPath(request->url()) && | 81 if (InstantService::IsInstantPath(request->url()) && |
| 82 InstantIOContext::ShouldServiceRequest(request)) { | 82 InstantIOContext::ShouldServiceRequest(request)) { |
| 83 // If this request will be serviced on the IO thread, then do the | 83 // If this request will be serviced on the IO thread, then do the |
| 84 // translation from raw_path to path here, where we have the |request| | 84 // translation from raw_path to path here, where we have the |request| |
| 85 // object in-hand, saving the result for later use. | 85 // object in-hand, saving the result for later use. |
| 86 | 86 |
| 87 // Strip leading slash from path. | 87 // Strip leading slash from path. |
| 88 std::string raw_path = request->url().path().substr(1); | 88 std::string raw_path = request->url().path().substr(1); |
| 89 if (!MessageLoopForRequestPath(raw_path)) { | 89 if (!MessageLoopForRequestPath(raw_path)) { |
| 90 id_to_url_map_[raw_path] = | 90 id_to_url_map_[raw_path] = |
| 91 InstantService::MaybeTranslateInstantPathOnIO(request, raw_path); | 91 InstantService::MaybeTranslateInstantPathOnIO(request, raw_path); |
| 92 } | 92 } |
| 93 return true; | 93 return true; |
| 94 } | 94 } |
| 95 return false; | 95 return false; |
| 96 } | 96 } |
| 97 return URLDataSource::ShouldServiceRequest(request); | 97 return URLDataSource::ShouldServiceRequest(request); |
| 98 } | 98 } |
| OLD | NEW |