Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: chrome/browser/search_engines/template_url_parser.cc

Issue 343823002: Move GenerateSearchURL() and GenerateKeyword() from TemplateURLService to TemplateURL (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_engines/template_url_parser.h" 5 #include "chrome/browser/search_engines/template_url_parser.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/search_engines/template_url.h" 16 #include "chrome/browser/search_engines/template_url.h"
17 #include "chrome/browser/search_engines/template_url_service.h"
18 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 17 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
19 #include "libxml/parser.h" 18 #include "libxml/parser.h"
20 #include "libxml/xmlwriter.h" 19 #include "libxml/xmlwriter.h"
21 #include "ui/gfx/favicon_size.h" 20 #include "ui/gfx/favicon_size.h"
22 #include "url/gurl.h" 21 #include "url/gurl.h"
23 #include "url/url_constants.h" 22 #include "url/url_constants.h"
24 23
25 namespace { 24 namespace {
26 25
27 // NOTE: libxml uses the UTF-8 encoding. As 0-127 of UTF-8 corresponds 26 // NOTE: libxml uses the UTF-8 encoding. As 0-127 of UTF-8 corresponds
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return NULL; 291 return NULL;
293 if (suggestion_method_ == TemplateURLParsingContext::POST) 292 if (suggestion_method_ == TemplateURLParsingContext::POST)
294 data_.suggestions_url.clear(); 293 data_.suggestions_url.clear();
295 294
296 // If the image was a data URL, use the favicon from the search URL instead. 295 // If the image was a data URL, use the favicon from the search URL instead.
297 // (see the TODO in EndElementImpl()). 296 // (see the TODO in EndElementImpl()).
298 GURL search_url(data_.url()); 297 GURL search_url(data_.url());
299 if (derive_image_from_url_ && data_.favicon_url.is_empty()) 298 if (derive_image_from_url_ && data_.favicon_url.is_empty())
300 data_.favicon_url = TemplateURL::GenerateFaviconURL(search_url); 299 data_.favicon_url = TemplateURL::GenerateFaviconURL(search_url);
301 300
302 data_.SetKeyword(TemplateURLService::GenerateKeyword(search_url)); 301 data_.SetKeyword(TemplateURL::GenerateKeyword(search_url));
303 data_.show_in_default_list = show_in_default_list; 302 data_.show_in_default_list = show_in_default_list;
304 303
305 // Bail if the search URL is empty or if either TemplateURLRef is invalid. 304 // Bail if the search URL is empty or if either TemplateURLRef is invalid.
306 scoped_ptr<TemplateURL> template_url(new TemplateURL(data_)); 305 scoped_ptr<TemplateURL> template_url(new TemplateURL(data_));
307 scoped_ptr<SearchTermsData> search_terms_data(profile ? 306 scoped_ptr<SearchTermsData> search_terms_data(profile ?
308 new UIThreadSearchTermsData(profile) : new SearchTermsData()); 307 new UIThreadSearchTermsData(profile) : new SearchTermsData());
309 if (template_url->url().empty() || 308 if (template_url->url().empty() ||
310 !template_url->url_ref().IsValid(*search_terms_data) || 309 !template_url->url_ref().IsValid(*search_terms_data) ||
311 (!template_url->suggestions_url().empty() && 310 (!template_url->suggestions_url().empty() &&
312 !template_url->suggestions_url_ref().IsValid(*search_terms_data))) { 311 !template_url->suggestions_url_ref().IsValid(*search_terms_data))) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 memset(&sax_handler, 0, sizeof(sax_handler)); 485 memset(&sax_handler, 0, sizeof(sax_handler));
487 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; 486 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl;
488 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; 487 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl;
489 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; 488 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl;
490 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, 489 int error = xmlSAXUserParseMemory(&sax_handler, &context, data,
491 static_cast<int>(length)); 490 static_cast<int>(length));
492 xmlSubstituteEntitiesDefault(last_sub_entities_value); 491 xmlSubstituteEntitiesDefault(last_sub_entities_value);
493 492
494 return error ? NULL : context.GetTemplateURL(profile, show_in_default_list); 493 return error ? NULL : context.GetTemplateURL(profile, show_in_default_list);
495 } 494 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url.cc ('k') | chrome/browser/search_engines/template_url_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698