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

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

Issue 9811022: Misc. small cleanups to minimize TemplateURL refactoring diffs: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 if (!template_ref.IsValid()) 42 if (!template_ref.IsValid())
43 return false; 43 return false;
44 44
45 // If this is going to be the default search engine, it must support 45 // If this is going to be the default search engine, it must support
46 // replacement. 46 // replacement.
47 if (!template_ref.SupportsReplacement() && 47 if (!template_ref.SupportsReplacement() &&
48 (template_url_ == TemplateURLServiceFactory::GetForProfile(profile_)-> 48 (template_url_ == TemplateURLServiceFactory::GetForProfile(profile_)->
49 GetDefaultSearchProvider())) 49 GetDefaultSearchProvider()))
50 return false; 50 return false;
51 51
52 // If the url has a search term, replace it with a random string and make 52 // Replace any search term with a placeholder string and make sure the
53 // sure the resulting URL is valid. We don't check the validity of the url 53 // resulting URL is valid.
54 // with the search term as that is not necessarily valid.
55 return GURL(template_ref.ReplaceSearchTerms(TemplateURL(), ASCIIToUTF16("x"), 54 return GURL(template_ref.ReplaceSearchTerms(TemplateURL(), ASCIIToUTF16("x"),
56 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())).is_valid(); 55 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())).is_valid();
57 } 56 }
58 57
59 bool EditSearchEngineController::IsKeywordValid( 58 bool EditSearchEngineController::IsKeywordValid(
60 const string16& keyword_input) const { 59 const string16& keyword_input) const {
61 string16 keyword_input_trimmed(CollapseWhitespace(keyword_input, true)); 60 string16 keyword_input_trimmed(CollapseWhitespace(keyword_input, true));
62 if (keyword_input_trimmed.empty()) 61 if (keyword_input_trimmed.empty())
63 return false; // Do not allow empty keyword. 62 return false; // Do not allow empty keyword.
64 const TemplateURL* turl_with_keyword = 63 const TemplateURL* turl_with_keyword =
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 std::string expanded_url(t_url.url()->ReplaceSearchTerms(t_url, 134 std::string expanded_url(t_url.url()->ReplaceSearchTerms(t_url,
136 ASCIIToUTF16("x"), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); 135 ASCIIToUTF16("x"), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
137 url_parse::Parsed parts; 136 url_parse::Parsed parts;
138 std::string scheme(URLFixerUpper::SegmentURL(expanded_url, &parts)); 137 std::string scheme(URLFixerUpper::SegmentURL(expanded_url, &parts));
139 if (!parts.scheme.is_valid()) 138 if (!parts.scheme.is_valid())
140 url.insert(0, scheme + "://"); 139 url.insert(0, scheme + "://");
141 140
142 return url; 141 return url;
143 } 142 }
144 143
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698