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

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

Issue 338363004: Remove Profile* from TemplateURL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments 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 | 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/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search_engines/template_url.h" 10 #include "chrome/browser/search_engines/template_url.h"
(...skipping 25 matching lines...) Expand all
36 std::string url = GetFixedUpURL(url_input); 36 std::string url = GetFixedUpURL(url_input);
37 if (url.empty()) 37 if (url.empty())
38 return false; 38 return false;
39 39
40 // Convert |url| to a TemplateURLRef so we can check its validity even if it 40 // Convert |url| to a TemplateURLRef so we can check its validity even if it
41 // contains replacement strings. We do this by constructing a dummy 41 // contains replacement strings. We do this by constructing a dummy
42 // TemplateURL owner because |template_url_| might be NULL and we can't call 42 // TemplateURL owner because |template_url_| might be NULL and we can't call
43 // TemplateURLRef::IsValid() when its owner is NULL. 43 // TemplateURLRef::IsValid() when its owner is NULL.
44 TemplateURLData data; 44 TemplateURLData data;
45 data.SetURL(url); 45 data.SetURL(url);
46 TemplateURL t_url(profile_, data); 46 TemplateURL t_url(data);
47 const TemplateURLRef& template_ref = t_url.url_ref(); 47 const TemplateURLRef& template_ref = t_url.url_ref();
48 TemplateURLService* service = 48 TemplateURLService* service =
49 TemplateURLServiceFactory::GetForProfile(profile_); 49 TemplateURLServiceFactory::GetForProfile(profile_);
50 if (!template_ref.IsValid(service->search_terms_data())) 50 if (!template_ref.IsValid(service->search_terms_data()))
51 return false; 51 return false;
52 52
53 // If this is going to be the default search engine, it must support 53 // If this is going to be the default search engine, it must support
54 // replacement. 54 // replacement.
55 if (!template_ref.SupportsReplacement(service->search_terms_data()) && 55 if (!template_ref.SupportsReplacement(service->search_terms_data()) &&
56 template_url_ && 56 template_url_ &&
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 base::UTF8ToUTF16(url_input)), 130 base::UTF8ToUTF16(url_input)),
131 base::TRIM_ALL, &url); 131 base::TRIM_ALL, &url);
132 if (url.empty()) 132 if (url.empty())
133 return url; 133 return url;
134 134
135 // Parse the string as a URL to determine the scheme. If we need to, add the 135 // Parse the string as a URL to determine the scheme. If we need to, add the
136 // scheme. As the scheme may be expanded (as happens with {google:baseURL}) 136 // scheme. As the scheme may be expanded (as happens with {google:baseURL})
137 // we need to replace the search terms before testing for the scheme. 137 // we need to replace the search terms before testing for the scheme.
138 TemplateURLData data; 138 TemplateURLData data;
139 data.SetURL(url); 139 data.SetURL(url);
140 TemplateURL t_url(profile_, data); 140 TemplateURL t_url(data);
141 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms( 141 std::string expanded_url(t_url.url_ref().ReplaceSearchTerms(
142 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")), 142 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("x")),
143 TemplateURLServiceFactory::GetForProfile(profile_)->search_terms_data())); 143 TemplateURLServiceFactory::GetForProfile(profile_)->search_terms_data()));
144 url::Parsed parts; 144 url::Parsed parts;
145 std::string scheme(url_fixer::SegmentURL(expanded_url, &parts)); 145 std::string scheme(url_fixer::SegmentURL(expanded_url, &parts));
146 if (!parts.scheme.is_valid()) 146 if (!parts.scheme.is_valid())
147 url.insert(0, scheme + "://"); 147 url.insert(0, scheme + "://");
148 148
149 return url; 149 return url;
150 } 150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698