| 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 scoped_refptr<base::SingleThreadTaskRunner> TaskRunnerForRequestPath( | |
| 127 const std::string& path) const override; | |
| 128 | 126 |
| 129 private: | 127 private: |
| 130 ~SuggestionsSource() override; | 128 ~SuggestionsSource() override; |
| 131 | 129 |
| 132 // Container for the state of a request. | 130 // Container for the state of a request. |
| 133 struct RequestContext { | 131 struct RequestContext { |
| 134 RequestContext( | 132 RequestContext( |
| 135 bool is_refresh_in, | 133 bool is_refresh_in, |
| 136 const suggestions::SuggestionsProfile& suggestions_profile_in, | 134 const suggestions::SuggestionsProfile& suggestions_profile_in, |
| 137 const content::URLDataSource::GotDataCallback& callback_in); | 135 const content::URLDataSource::GotDataCallback& callback_in); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 base::Bind(&SuggestionsSource::OnThumbnailAvailable, | 223 base::Bind(&SuggestionsSource::OnThumbnailAvailable, |
| 226 weak_ptr_factory_.GetWeakPtr(), context, barrier)); | 224 weak_ptr_factory_.GetWeakPtr(), context, barrier)); |
| 227 } | 225 } |
| 228 } | 226 } |
| 229 } | 227 } |
| 230 | 228 |
| 231 std::string SuggestionsSource::GetMimeType(const std::string& path) const { | 229 std::string SuggestionsSource::GetMimeType(const std::string& path) const { |
| 232 return "text/html"; | 230 return "text/html"; |
| 233 } | 231 } |
| 234 | 232 |
| 235 scoped_refptr<base::SingleThreadTaskRunner> | |
| 236 SuggestionsSource::TaskRunnerForRequestPath(const std::string& path) const { | |
| 237 // This can be accessed from the IO thread. | |
| 238 return content::URLDataSource::TaskRunnerForRequestPath(path); | |
| 239 } | |
| 240 | |
| 241 void SuggestionsSource::OnThumbnailsFetched(RequestContext* context) { | 233 void SuggestionsSource::OnThumbnailsFetched(RequestContext* context) { |
| 242 std::unique_ptr<RequestContext> context_deleter(context); | 234 std::unique_ptr<RequestContext> context_deleter(context); |
| 243 | 235 |
| 244 std::string output = | 236 std::string output = |
| 245 RenderOutputHtml(context->is_refresh, context->suggestions_profile, | 237 RenderOutputHtml(context->is_refresh, context->suggestions_profile, |
| 246 context->base64_encoded_pngs); | 238 context->base64_encoded_pngs); |
| 247 context->callback.Run(base::RefCountedString::TakeString(&output)); | 239 context->callback.Run(base::RefCountedString::TakeString(&output)); |
| 248 } | 240 } |
| 249 | 241 |
| 250 void SuggestionsSource::OnThumbnailAvailable(RequestContext* context, | 242 void SuggestionsSource::OnThumbnailAvailable(RequestContext* context, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 270 | 262 |
| 271 SuggestionsUI::SuggestionsUI(content::WebUI* web_ui) | 263 SuggestionsUI::SuggestionsUI(content::WebUI* web_ui) |
| 272 : content::WebUIController(web_ui) { | 264 : content::WebUIController(web_ui) { |
| 273 Profile* profile = Profile::FromWebUI(web_ui); | 265 Profile* profile = Profile::FromWebUI(web_ui); |
| 274 content::URLDataSource::Add(profile, new SuggestionsSource(profile)); | 266 content::URLDataSource::Add(profile, new SuggestionsSource(profile)); |
| 275 } | 267 } |
| 276 | 268 |
| 277 SuggestionsUI::~SuggestionsUI() {} | 269 SuggestionsUI::~SuggestionsUI() {} |
| 278 | 270 |
| 279 } // namespace suggestions | 271 } // namespace suggestions |
| OLD | NEW |