| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/barrier_closure.h" | 12 #include "base/barrier_closure.h" |
| 13 #include "base/base64.h" | 13 #include "base/base64.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/memory/ref_counted_memory.h" | 15 #include "base/memory/ref_counted_memory.h" |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" | 24 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" |
| 25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 26 #include "components/suggestions/suggestions_service.h" | 26 #include "components/suggestions/suggestions_service.h" |
| 27 #include "components/suggestions/suggestions_utils.h" | |
| 28 #include "net/base/escape.h" | 27 #include "net/base/escape.h" |
| 29 #include "ui/base/l10n/time_format.h" | 28 #include "ui/base/l10n/time_format.h" |
| 30 #include "ui/gfx/codec/png_codec.h" | 29 #include "ui/gfx/codec/png_codec.h" |
| 31 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" |
| 32 #include "url/gurl.h" | 31 #include "url/gurl.h" |
| 33 | 32 |
| 34 namespace suggestions { | 33 namespace suggestions { |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 113 |
| 115 std::string SuggestionsSource::GetSource() const { | 114 std::string SuggestionsSource::GetSource() const { |
| 116 return chrome::kChromeUISuggestionsHost; | 115 return chrome::kChromeUISuggestionsHost; |
| 117 } | 116 } |
| 118 | 117 |
| 119 void SuggestionsSource::StartDataRequest( | 118 void SuggestionsSource::StartDataRequest( |
| 120 const std::string& path, int render_process_id, int render_frame_id, | 119 const std::string& path, int render_process_id, int render_frame_id, |
| 121 const content::URLDataSource::GotDataCallback& callback) { | 120 const content::URLDataSource::GotDataCallback& callback) { |
| 122 SuggestionsService* suggestions_service = | 121 SuggestionsService* suggestions_service = |
| 123 SuggestionsServiceFactory::GetForProfile(profile_); | 122 SuggestionsServiceFactory::GetForProfile(profile_); |
| 124 | 123 OnSuggestionsAvailable(callback, |
| 125 if (!suggestions_service) { | 124 suggestions_service->GetSuggestionsDataFromCache()); |
| 126 callback.Run(NULL); | 125 suggestions_service->FetchSuggestionsData(); |
| 127 return; | |
| 128 } | |
| 129 | |
| 130 // Since it's a debugging page, it's fine to specify that sync state is | |
| 131 // initialized. | |
| 132 suggestions_service->FetchSuggestionsData( | |
| 133 INITIALIZED_ENABLED_HISTORY, | |
| 134 base::Bind(&SuggestionsSource::OnSuggestionsAvailable, | |
| 135 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 136 } | 126 } |
| 137 | 127 |
| 138 std::string SuggestionsSource::GetMimeType(const std::string& path) const { | 128 std::string SuggestionsSource::GetMimeType(const std::string& path) const { |
| 139 return "text/html"; | 129 return "text/html"; |
| 140 } | 130 } |
| 141 | 131 |
| 142 base::MessageLoop* SuggestionsSource::MessageLoopForRequestPath( | 132 base::MessageLoop* SuggestionsSource::MessageLoopForRequestPath( |
| 143 const std::string& path) const { | 133 const std::string& path) const { |
| 144 // This can be accessed from the IO thread. | 134 // This can be accessed from the IO thread. |
| 145 return content::URLDataSource::MessageLoopForRequestPath(path); | 135 return content::URLDataSource::MessageLoopForRequestPath(path); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 std::string encoded_output; | 183 std::string encoded_output; |
| 194 base::Base64Encode(std::string(output.begin(), output.end()), | 184 base::Base64Encode(std::string(output.begin(), output.end()), |
| 195 &encoded_output); | 185 &encoded_output); |
| 196 context->base64_encoded_pngs[url] = "data:image/png;base64,"; | 186 context->base64_encoded_pngs[url] = "data:image/png;base64,"; |
| 197 context->base64_encoded_pngs[url] += encoded_output; | 187 context->base64_encoded_pngs[url] += encoded_output; |
| 198 } | 188 } |
| 199 barrier.Run(); | 189 barrier.Run(); |
| 200 } | 190 } |
| 201 | 191 |
| 202 } // namespace suggestions | 192 } // namespace suggestions |
| OLD | NEW |