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

Side by Side Diff: chrome/browser/supervised_user/experimental/supervised_user_async_url_checker.cc

Issue 889463003: GURL::Replacements methods accept a StringPiece instead of std::string&. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase (fixed some merge conflicts). Created 5 years, 10 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
OLDNEW
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"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string_piece.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "components/google/core/browser/google_util.h" 18 #include "components/google/core/browser/google_util.h"
18 #include "google_apis/google_api_keys.h" 19 #include "google_apis/google_api_keys.h"
19 #include "net/base/escape.h" 20 #include "net/base/escape.h"
20 #include "net/base/load_flags.h" 21 #include "net/base/load_flags.h"
21 #include "net/url_request/url_fetcher.h" 22 #include "net/url_request/url_fetcher.h"
22 #include "net/url_request/url_request_context.h" 23 #include "net/url_request/url_request_context.h"
(...skipping 15 matching lines...) Expand all
38 const char kIdResults[] = "items"; 39 const char kIdResults[] = "items";
39 const char kIdResultURL[] = "link"; 40 const char kIdResultURL[] = "link";
40 41
41 const size_t kDefaultCacheSize = 1000; 42 const size_t kDefaultCacheSize = 1000;
42 43
43 // 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
44 // common default and strips a leading "www." from the host. 45 // common default and strips a leading "www." from the host.
45 GURL GetNormalizedURL(const GURL& url) { 46 GURL GetNormalizedURL(const GURL& url) {
46 GURL::Replacements replacements; 47 GURL::Replacements replacements;
47 // Set scheme to http. 48 // Set scheme to http.
48 const std::string scheme(url::kHttpScheme); 49 replacements.SetSchemeStr(url::kHttpScheme);
49 replacements.SetSchemeStr(scheme);
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 std::string new_host; 52 const std::string host(url.host());
53 if (StartsWithASCII(url.host(), www, true)) { 53 if (StartsWithASCII(host, www, true))
54 new_host = url.host().substr(www.size()); 54 replacements.SetHostStr(base::StringPiece(host).substr(www.size()));
55 replacements.SetHostStr(new_host);
56 }
57 // Strip trailing slash (if any). 55 // Strip trailing slash (if any).
58 std::string new_path; 56 const std::string path(url.path());
59 if (EndsWith(url.path(), "/", true)) { 57 if (EndsWith(path, "/", true))
60 new_path = url.path().substr(0, url.path().size() - 1); 58 replacements.SetPathStr(base::StringPiece(path).substr(0, path.size() - 1));
61 replacements.SetPathStr(new_path);
62 }
63 return url.ReplaceComponents(replacements); 59 return url.ReplaceComponents(replacements);
64 } 60 }
65 61
66 // 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
67 // and a Custom Search Engine identified by |cx|, using the specified 63 // and a Custom Search Engine identified by |cx|, using the specified
68 // |api_key|). If |safe| is specified, enables the SafeSearch query parameter. 64 // |api_key|). If |safe| is specified, enables the SafeSearch query parameter.
69 GURL BuildSearchURL(const std::string& cx, 65 GURL BuildSearchURL(const std::string& cx,
70 const std::string& api_key, 66 const std::string& api_key,
71 const GURL& url, 67 const GURL& url,
72 bool safe) { 68 bool safe) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 318
323 UMA_HISTOGRAM_TIMES("ManagedUsers.SafeSitesDelay", 319 UMA_HISTOGRAM_TIMES("ManagedUsers.SafeSitesDelay",
324 base::Time::Now() - check->start_time); 320 base::Time::Now() - check->start_time);
325 321
326 cache_.Put(check->url, CheckResult(behavior, uncertain)); 322 cache_.Put(check->url, CheckResult(behavior, uncertain));
327 323
328 for (size_t i = 0; i < check->callbacks.size(); i++) 324 for (size_t i = 0; i < check->callbacks.size(); i++)
329 check->callbacks[i].Run(check->url, behavior, uncertain); 325 check->callbacks[i].Run(check->url, behavior, uncertain);
330 checks_in_progress_.erase(it); 326 checks_in_progress_.erase(it);
331 } 327 }
OLDNEW
« no previous file with comments | « chrome/browser/ssl/ssl_browser_tests.cc ('k') | chrome/browser/task_manager/task_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698