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

Side by Side Diff: chrome/browser/ui/search_engines/edit_search_engine_controller.cc

Issue 10537154: A working implementation of AQS (Assisted Query Stats). (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Addressed comments. Created 8 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 | Annotate | Revision Log
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/ui/search_engines/edit_search_engine_controller.h" 5 #include "chrome/browser/ui/search_engines/edit_search_engine_controller.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/net/url_fixer_upper.h" 9 #include "chrome/browser/net/url_fixer_upper.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 // If this is going to be the default search engine, it must support 51 // If this is going to be the default search engine, it must support
52 // replacement. 52 // replacement.
53 if (!template_ref.SupportsReplacement() && 53 if (!template_ref.SupportsReplacement() &&
54 (template_url_ == TemplateURLServiceFactory::GetForProfile(profile_)-> 54 (template_url_ == TemplateURLServiceFactory::GetForProfile(profile_)->
55 GetDefaultSearchProvider())) 55 GetDefaultSearchProvider()))
56 return false; 56 return false;
57 57
58 // Replace any search term with a placeholder string and make sure the 58 // Replace any search term with a placeholder string and make sure the
59 // resulting URL is valid. 59 // resulting URL is valid.
60 return GURL(template_ref.ReplaceSearchTerms(ASCIIToUTF16("x"), 60 return GURL(template_ref.ReplaceSearchTerms(
61 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())).is_valid(); 61 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x")))).is_valid();
62 } 62 }
63 63
64 bool EditSearchEngineController::IsKeywordValid( 64 bool EditSearchEngineController::IsKeywordValid(
65 const string16& keyword_input) const { 65 const string16& keyword_input) const {
66 string16 keyword_input_trimmed(CollapseWhitespace(keyword_input, true)); 66 string16 keyword_input_trimmed(CollapseWhitespace(keyword_input, true));
67 if (keyword_input_trimmed.empty()) 67 if (keyword_input_trimmed.empty())
68 return false; // Do not allow empty keyword. 68 return false; // Do not allow empty keyword.
69 const TemplateURL* turl_with_keyword = 69 const TemplateURL* turl_with_keyword =
70 TemplateURLServiceFactory::GetForProfile(profile_)-> 70 TemplateURLServiceFactory::GetForProfile(profile_)->
71 GetTemplateURLForKeyword(keyword_input_trimmed); 71 GetTemplateURLForKeyword(keyword_input_trimmed);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 TRIM_ALL, &url); 126 TRIM_ALL, &url);
127 if (url.empty()) 127 if (url.empty())
128 return url; 128 return url;
129 129
130 // Parse the string as a URL to determine the scheme. If we need to, add the 130 // Parse the string as a URL to determine the scheme. If we need to, add the
131 // scheme. As the scheme may be expanded (as happens with {google:baseURL}) 131 // scheme. As the scheme may be expanded (as happens with {google:baseURL})
132 // we need to replace the search terms before testing for the scheme. 132 // we need to replace the search terms before testing for the scheme.
133 TemplateURLData data; 133 TemplateURLData data;
134 data.SetURL(url); 134 data.SetURL(url);
135 TemplateURL t_url(profile_, data); 135 TemplateURL t_url(profile_, data);
136 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("x"), 136 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms(
137 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 137 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x"))));
138 url_parse::Parsed parts; 138 url_parse::Parsed parts;
139 std::string scheme(URLFixerUpper::SegmentURL(expanded_url, &parts)); 139 std::string scheme(URLFixerUpper::SegmentURL(expanded_url, &parts));
140 if (!parts.scheme.is_valid()) 140 if (!parts.scheme.is_valid())
141 url.insert(0, scheme + "://"); 141 url.insert(0, scheme + "://");
142 142
143 return url; 143 return url;
144 } 144 }
145
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698