| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/supervised_user/experimental/supervised_user_async_url_
checker.h" | 5 #include "chrome/browser/supervised_user/experimental/supervised_user_async_url_
checker.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 // Build a normalized version of |url| for comparisons. Sets the scheme to a | 44 // Build a normalized version of |url| for comparisons. Sets the scheme to a |
| 45 // common default and strips a leading "www." from the host. | 45 // common default and strips a leading "www." from the host. |
| 46 GURL GetNormalizedURL(const GURL& url) { | 46 GURL GetNormalizedURL(const GURL& url) { |
| 47 GURL::Replacements replacements; | 47 GURL::Replacements replacements; |
| 48 // Set scheme to http. | 48 // Set scheme to http. |
| 49 replacements.SetSchemeStr(url::kHttpScheme); | 49 replacements.SetSchemeStr(url::kHttpScheme); |
| 50 // Strip leading "www." (if any). | 50 // Strip leading "www." (if any). |
| 51 const std::string www("www."); | 51 const std::string www("www."); |
| 52 const std::string host(url.host()); | 52 const std::string host(url.host()); |
| 53 if (base::StartsWithASCII(host, www, true)) | 53 if (base::StartsWith(host, www, base::CompareCase::SENSITIVE)) |
| 54 replacements.SetHostStr(base::StringPiece(host).substr(www.size())); | 54 replacements.SetHostStr(base::StringPiece(host).substr(www.size())); |
| 55 // Strip trailing slash (if any). | 55 // Strip trailing slash (if any). |
| 56 const std::string path(url.path()); | 56 const std::string path(url.path()); |
| 57 if (base::EndsWith(path, "/", true)) | 57 if (base::EndsWith(path, "/", true)) |
| 58 replacements.SetPathStr(base::StringPiece(path).substr(0, path.size() - 1)); | 58 replacements.SetPathStr(base::StringPiece(path).substr(0, path.size() - 1)); |
| 59 return url.ReplaceComponents(replacements); | 59 return url.ReplaceComponents(replacements); |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Builds a URL for a web search for |url| (using the "inurl:" query parameter | 62 // Builds a URL for a web search for |url| (using the "inurl:" query parameter |
| 63 // and a Custom Search Engine, using the specified |api_key|). If |safe| is | 63 // and a Custom Search Engine, using the specified |api_key|). If |safe| is |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 313 |
| 314 UMA_HISTOGRAM_TIMES("ManagedUsers.SafeSitesDelay", | 314 UMA_HISTOGRAM_TIMES("ManagedUsers.SafeSitesDelay", |
| 315 base::Time::Now() - check->start_time); | 315 base::Time::Now() - check->start_time); |
| 316 | 316 |
| 317 cache_.Put(check->url, CheckResult(behavior, uncertain)); | 317 cache_.Put(check->url, CheckResult(behavior, uncertain)); |
| 318 | 318 |
| 319 for (size_t i = 0; i < check->callbacks.size(); i++) | 319 for (size_t i = 0; i < check->callbacks.size(); i++) |
| 320 check->callbacks[i].Run(check->url, behavior, uncertain); | 320 check->callbacks[i].Run(check->url, behavior, uncertain); |
| 321 checks_in_progress_.erase(it); | 321 checks_in_progress_.erase(it); |
| 322 } | 322 } |
| OLD | NEW |