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/search/suggestions/suggestions_source.h" | 5 #include "chrome/browser/search/suggestions/suggestions_source.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/barrier_closure.h" | 9 #include "base/barrier_closure.h" |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/search/instant_io_context.h" | |
18 #include "chrome/browser/search/suggestions/suggestions_service.h" | 17 #include "chrome/browser/search/suggestions/suggestions_service.h" |
19 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" | 18 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" |
20 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
21 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
22 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
huangs
2014/07/07 21:38:47
Remove
#include "net/url_request/url_request.h"
?
Mathieu
2014/07/08 00:15:12
Done.
| |
23 #include "ui/gfx/codec/png_codec.h" | 22 #include "ui/gfx/codec/png_codec.h" |
24 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
25 #include "url/gurl.h" | 24 #include "url/gurl.h" |
26 | 25 |
27 namespace suggestions { | 26 namespace suggestions { |
28 | 27 |
29 namespace { | 28 namespace { |
30 | 29 |
31 const char kHtmlHeader[] = | 30 const char kHtmlHeader[] = |
32 "<!DOCTYPE html>\n<html>\n<head>\n<title>Suggestions</title>\n" | 31 "<!DOCTYPE html>\n<html>\n<head>\n<title>Suggestions</title>\n" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 std::string SuggestionsSource::GetMimeType(const std::string& path) const { | 120 std::string SuggestionsSource::GetMimeType(const std::string& path) const { |
122 return "text/html"; | 121 return "text/html"; |
123 } | 122 } |
124 | 123 |
125 base::MessageLoop* SuggestionsSource::MessageLoopForRequestPath( | 124 base::MessageLoop* SuggestionsSource::MessageLoopForRequestPath( |
126 const std::string& path) const { | 125 const std::string& path) const { |
127 // This can be accessed from the IO thread. | 126 // This can be accessed from the IO thread. |
128 return content::URLDataSource::MessageLoopForRequestPath(path); | 127 return content::URLDataSource::MessageLoopForRequestPath(path); |
129 } | 128 } |
130 | 129 |
131 bool SuggestionsSource::ShouldServiceRequest( | |
132 const net::URLRequest* request) const { | |
133 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) | |
134 return InstantIOContext::ShouldServiceRequest(request); | |
135 return URLDataSource::ShouldServiceRequest(request); | |
136 } | |
137 | |
138 void SuggestionsSource::OnSuggestionsAvailable( | 130 void SuggestionsSource::OnSuggestionsAvailable( |
139 const content::URLDataSource::GotDataCallback& callback, | 131 const content::URLDataSource::GotDataCallback& callback, |
140 const SuggestionsProfile& suggestions_profile) { | 132 const SuggestionsProfile& suggestions_profile) { |
141 size_t size = suggestions_profile.suggestions_size(); | 133 size_t size = suggestions_profile.suggestions_size(); |
142 if (!size) { | 134 if (!size) { |
143 std::string output; | 135 std::string output; |
144 RenderOutputHtmlNoSuggestions(&output); | 136 RenderOutputHtmlNoSuggestions(&output); |
145 callback.Run(base::RefCountedString::TakeString(&output)); | 137 callback.Run(base::RefCountedString::TakeString(&output)); |
146 } else { | 138 } else { |
147 RequestContext* context = new RequestContext(suggestions_profile, callback); | 139 RequestContext* context = new RequestContext(suggestions_profile, callback); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 std::string encoded_output; | 175 std::string encoded_output; |
184 base::Base64Encode(std::string(output.begin(), output.end()), | 176 base::Base64Encode(std::string(output.begin(), output.end()), |
185 &encoded_output); | 177 &encoded_output); |
186 context->base64_encoded_pngs[url] = "data:image/png;base64,"; | 178 context->base64_encoded_pngs[url] = "data:image/png;base64,"; |
187 context->base64_encoded_pngs[url] += encoded_output; | 179 context->base64_encoded_pngs[url] += encoded_output; |
188 } | 180 } |
189 barrier.Run(); | 181 barrier.Run(); |
190 } | 182 } |
191 | 183 |
192 } // namespace suggestions | 184 } // namespace suggestions |
OLD | NEW |