OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/thumbnails/thumbnail_list_source.h" | 5 #include "chrome/browser/thumbnails/thumbnail_list_source.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "chrome/browser/history/top_sites.h" | 14 #include "chrome/browser/history/top_sites.h" |
| 15 #include "chrome/browser/history/top_sites_factory.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/search/instant_io_context.h" | 17 #include "chrome/browser/search/instant_io_context.h" |
17 #include "chrome/browser/thumbnails/thumbnail_service.h" | 18 #include "chrome/browser/thumbnails/thumbnail_service.h" |
18 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" | 19 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" |
19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
20 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 88 |
88 std::string ThumbnailListSource::GetSource() const { | 89 std::string ThumbnailListSource::GetSource() const { |
89 return chrome::kChromeUIThumbnailListHost; | 90 return chrome::kChromeUIThumbnailListHost; |
90 } | 91 } |
91 | 92 |
92 void ThumbnailListSource::StartDataRequest( | 93 void ThumbnailListSource::StartDataRequest( |
93 const std::string& path, | 94 const std::string& path, |
94 int render_process_id, | 95 int render_process_id, |
95 int render_frame_id, | 96 int render_frame_id, |
96 const content::URLDataSource::GotDataCallback& callback) { | 97 const content::URLDataSource::GotDataCallback& callback) { |
97 if (!profile_->GetTopSites()) { | 98 scoped_refptr<history::TopSites> top_sites = |
| 99 TopSitesFactory::GetForProfile(profile_); |
| 100 if (!top_sites) { |
98 callback.Run(NULL); | 101 callback.Run(NULL); |
99 return; | 102 return; |
100 } | 103 } |
101 | 104 |
102 profile_->GetTopSites()->GetMostVisitedURLs( | 105 top_sites->GetMostVisitedURLs( |
103 base::Bind(&ThumbnailListSource::OnMostVisitedURLsAvailable, | 106 base::Bind(&ThumbnailListSource::OnMostVisitedURLsAvailable, |
104 weak_ptr_factory_.GetWeakPtr(), | 107 weak_ptr_factory_.GetWeakPtr(), callback), |
105 callback), true); | 108 true); |
106 } | 109 } |
107 | 110 |
108 std::string ThumbnailListSource::GetMimeType(const std::string& path) const { | 111 std::string ThumbnailListSource::GetMimeType(const std::string& path) const { |
109 return "text/html"; | 112 return "text/html"; |
110 } | 113 } |
111 | 114 |
112 base::MessageLoop* ThumbnailListSource::MessageLoopForRequestPath( | 115 base::MessageLoop* ThumbnailListSource::MessageLoopForRequestPath( |
113 const std::string& path) const { | 116 const std::string& path) const { |
114 // TopSites can be accessed from the IO thread. | 117 // TopSites can be accessed from the IO thread. |
115 return thumbnail_service_.get() ? | 118 return thumbnail_service_.get() ? |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 157 } |
155 if (num_mv_with_thumb < num_mv) { | 158 if (num_mv_with_thumb < num_mv) { |
156 out.push_back("<h2>TopSites URLs without Thumbnails</h2>\n"); | 159 out.push_back("<h2>TopSites URLs without Thumbnails</h2>\n"); |
157 RenderMostVisitedURLList(mvurl_list, base64_encoded_pngs, false, &out); | 160 RenderMostVisitedURLList(mvurl_list, base64_encoded_pngs, false, &out); |
158 } | 161 } |
159 out.push_back(kHtmlFooter); | 162 out.push_back(kHtmlFooter); |
160 | 163 |
161 std::string out_html = JoinString(out, ""); | 164 std::string out_html = JoinString(out, ""); |
162 callback.Run(base::RefCountedString::TakeString(&out_html)); | 165 callback.Run(base::RefCountedString::TakeString(&out_html)); |
163 } | 166 } |
OLD | NEW |