OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/search/suggestions/suggestions_ui.h" | 5 #include "chrome/browser/search/suggestions/suggestions_ui.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/barrier_closure.h" | 10 #include "base/barrier_closure.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 public: | 116 public: |
117 explicit SuggestionsSource(Profile* profile); | 117 explicit SuggestionsSource(Profile* profile); |
118 | 118 |
119 // content::URLDataSource implementation. | 119 // content::URLDataSource implementation. |
120 std::string GetSource() const override; | 120 std::string GetSource() const override; |
121 void StartDataRequest( | 121 void StartDataRequest( |
122 const std::string& path, | 122 const std::string& path, |
123 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | 123 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
124 const content::URLDataSource::GotDataCallback& callback) override; | 124 const content::URLDataSource::GotDataCallback& callback) override; |
125 std::string GetMimeType(const std::string& path) const override; | 125 std::string GetMimeType(const std::string& path) const override; |
126 base::MessageLoop* MessageLoopForRequestPath( | 126 scoped_refptr<base::SingleThreadTaskRunner> TaskRunnerForRequestPath( |
127 const std::string& path) const override; | 127 const std::string& path) const override; |
128 | 128 |
129 private: | 129 private: |
130 ~SuggestionsSource() override; | 130 ~SuggestionsSource() override; |
131 | 131 |
132 // Container for the state of a request. | 132 // Container for the state of a request. |
133 struct RequestContext { | 133 struct RequestContext { |
134 RequestContext( | 134 RequestContext( |
135 bool is_refresh_in, | 135 bool is_refresh_in, |
136 const suggestions::SuggestionsProfile& suggestions_profile_in, | 136 const suggestions::SuggestionsProfile& suggestions_profile_in, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 base::Bind(&SuggestionsSource::OnThumbnailAvailable, | 225 base::Bind(&SuggestionsSource::OnThumbnailAvailable, |
226 weak_ptr_factory_.GetWeakPtr(), context, barrier)); | 226 weak_ptr_factory_.GetWeakPtr(), context, barrier)); |
227 } | 227 } |
228 } | 228 } |
229 } | 229 } |
230 | 230 |
231 std::string SuggestionsSource::GetMimeType(const std::string& path) const { | 231 std::string SuggestionsSource::GetMimeType(const std::string& path) const { |
232 return "text/html"; | 232 return "text/html"; |
233 } | 233 } |
234 | 234 |
235 base::MessageLoop* SuggestionsSource::MessageLoopForRequestPath( | 235 scoped_refptr<base::SingleThreadTaskRunner> |
236 const std::string& path) const { | 236 SuggestionsSource::TaskRunnerForRequestPath(const std::string& path) const { |
237 // This can be accessed from the IO thread. | 237 // This can be accessed from the IO thread. |
238 return content::URLDataSource::MessageLoopForRequestPath(path); | 238 return content::URLDataSource::TaskRunnerForRequestPath(path); |
239 } | 239 } |
240 | 240 |
241 void SuggestionsSource::OnThumbnailsFetched(RequestContext* context) { | 241 void SuggestionsSource::OnThumbnailsFetched(RequestContext* context) { |
242 std::unique_ptr<RequestContext> context_deleter(context); | 242 std::unique_ptr<RequestContext> context_deleter(context); |
243 | 243 |
244 std::string output = | 244 std::string output = |
245 RenderOutputHtml(context->is_refresh, context->suggestions_profile, | 245 RenderOutputHtml(context->is_refresh, context->suggestions_profile, |
246 context->base64_encoded_pngs); | 246 context->base64_encoded_pngs); |
247 context->callback.Run(base::RefCountedString::TakeString(&output)); | 247 context->callback.Run(base::RefCountedString::TakeString(&output)); |
248 } | 248 } |
(...skipping 21 matching lines...) Expand all Loading... |
270 | 270 |
271 SuggestionsUI::SuggestionsUI(content::WebUI* web_ui) | 271 SuggestionsUI::SuggestionsUI(content::WebUI* web_ui) |
272 : content::WebUIController(web_ui) { | 272 : content::WebUIController(web_ui) { |
273 Profile* profile = Profile::FromWebUI(web_ui); | 273 Profile* profile = Profile::FromWebUI(web_ui); |
274 content::URLDataSource::Add(profile, new SuggestionsSource(profile)); | 274 content::URLDataSource::Add(profile, new SuggestionsSource(profile)); |
275 } | 275 } |
276 | 276 |
277 SuggestionsUI::~SuggestionsUI() {} | 277 SuggestionsUI::~SuggestionsUI() {} |
278 | 278 |
279 } // namespace suggestions | 279 } // namespace suggestions |
OLD | NEW |