Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: chrome/browser/ui/webui/ntp/thumbnail_source.cc

Issue 15907006: Rip out browser-side RID caching for most visited items. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/ntp/thumbnail_source.h ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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& path,
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(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_.get()); 47 callback.Run(default_thumbnail_.get());
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 return InstantIOContext::ShouldServiceRequest(request);
83 InstantIOContext::ShouldServiceRequest(request)) {
84 // If this request will be serviced on the IO thread, then do the
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 }
98 return URLDataSource::ShouldServiceRequest(request); 68 return URLDataSource::ShouldServiceRequest(request);
99 } 69 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/thumbnail_source.h ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698