| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/search.h" | 5 #include "chrome/browser/search/search.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 search_url = TemplateURLRefToGURL(ref, search_terms_data, | 191 search_url = TemplateURLRefToGURL(ref, search_terms_data, |
| 192 kDisableStartMargin, false, false); | 192 kDisableStartMargin, false, false); |
| 193 if (search_url.is_valid() && | 193 if (search_url.is_valid() && |
| 194 search::MatchesOriginAndPath(url, search_url)) | 194 search::MatchesOriginAndPath(url, search_url)) |
| 195 return true; | 195 return true; |
| 196 } | 196 } |
| 197 | 197 |
| 198 return false; | 198 return false; |
| 199 } | 199 } |
| 200 | 200 |
| 201 // Returns true if |contents| is rendered inside the Instant process for | |
| 202 // |profile|. | |
| 203 bool IsRenderedInInstantProcess(const content::WebContents* contents, | |
| 204 Profile* profile) { | |
| 205 const content::RenderProcessHost* process_host = | |
| 206 contents->GetRenderProcessHost(); | |
| 207 if (!process_host) | |
| 208 return false; | |
| 209 | 201 |
| 210 const InstantService* instant_service = | |
| 211 InstantServiceFactory::GetForProfile(profile); | |
| 212 if (!instant_service) | |
| 213 return false; | |
| 214 | |
| 215 return instant_service->IsInstantProcess(process_host->GetID()); | |
| 216 } | |
| 217 | 202 |
| 218 // |url| should either have a secure scheme or have a non-HTTPS base URL that | 203 // |url| should either have a secure scheme or have a non-HTTPS base URL that |
| 219 // the user specified using --google-base-url. (This allows testers to use | 204 // the user specified using --google-base-url. (This allows testers to use |
| 220 // --google-base-url to point at non-HTTPS servers, which eases testing.) | 205 // --google-base-url to point at non-HTTPS servers, which eases testing.) |
| 221 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) { | 206 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) { |
| 222 return template_url->HasSearchTermsReplacementKey(url) && | 207 return template_url->HasSearchTermsReplacementKey(url) && |
| 223 (url.SchemeIsSecure() || | 208 (url.SchemeIsSecure() || |
| 224 google_util::StartsWithCommandLineGoogleBaseURL(url)); | 209 google_util::StartsWithCommandLineGoogleBaseURL(url)); |
| 225 } | 210 } |
| 226 | 211 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 } | 450 } |
| 466 | 451 |
| 467 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { | 452 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { |
| 468 return url.is_valid() && | 453 return url.is_valid() && |
| 469 profile && | 454 profile && |
| 470 IsInstantExtendedAPIEnabled() && | 455 IsInstantExtendedAPIEnabled() && |
| 471 (url.SchemeIs(chrome::kChromeSearchScheme) || | 456 (url.SchemeIs(chrome::kChromeSearchScheme) || |
| 472 IsInstantURL(url, profile)); | 457 IsInstantURL(url, profile)); |
| 473 } | 458 } |
| 474 | 459 |
| 460 bool IsRenderedInInstantProcess(const content::WebContents* contents, |
| 461 Profile* profile) { |
| 462 const content::RenderProcessHost* process_host = |
| 463 contents->GetRenderProcessHost(); |
| 464 if (!process_host) |
| 465 return false; |
| 466 |
| 467 const InstantService* instant_service = |
| 468 InstantServiceFactory::GetForProfile(profile); |
| 469 if (!instant_service) |
| 470 return false; |
| 471 |
| 472 return instant_service->IsInstantProcess(process_host->GetID()); |
| 473 } |
| 474 |
| 475 bool ShouldUseProcessPerSiteForInstantURL(const GURL& url, Profile* profile) { | 475 bool ShouldUseProcessPerSiteForInstantURL(const GURL& url, Profile* profile) { |
| 476 return ShouldAssignURLToInstantRenderer(url, profile) && | 476 return ShouldAssignURLToInstantRenderer(url, profile) && |
| 477 (url.host() == chrome::kChromeSearchLocalNtpHost || | 477 (url.host() == chrome::kChromeSearchLocalNtpHost || |
| 478 url.host() == chrome::kChromeSearchRemoteNtpHost); | 478 url.host() == chrome::kChromeSearchRemoteNtpHost); |
| 479 } | 479 } |
| 480 | 480 |
| 481 bool IsNTPURL(const GURL& url, Profile* profile) { | 481 bool IsNTPURL(const GURL& url, Profile* profile) { |
| 482 if (!url.is_valid()) | 482 if (!url.is_valid()) |
| 483 return false; | 483 return false; |
| 484 | 484 |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 | 838 |
| 839 // Given a FieldTrialFlags object, returns the boolean value of the provided | 839 // Given a FieldTrialFlags object, returns the boolean value of the provided |
| 840 // flag. | 840 // flag. |
| 841 bool GetBoolValueForFlagWithDefault(const std::string& flag, | 841 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
| 842 bool default_value, | 842 bool default_value, |
| 843 const FieldTrialFlags& flags) { | 843 const FieldTrialFlags& flags) { |
| 844 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 844 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
| 845 } | 845 } |
| 846 | 846 |
| 847 } // namespace chrome | 847 } // namespace chrome |
| OLD | NEW |