| 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 "components/google/core/browser/google_url_tracker.h" | 5 #include "components/google/core/browser/google_url_tracker.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "components/google/core/browser/google_pref_names.h" | 11 #include "components/google/core/browser/google_pref_names.h" |
| 12 #include "components/google/core/browser/google_switches.h" | 12 #include "components/google/core/browser/google_switches.h" |
| 13 #include "components/google/core/browser/google_util.h" | 13 #include "components/google/core/browser/google_util.h" |
| 14 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 15 #include "net/url_request/url_fetcher.h" | 15 #include "net/url_request/url_fetcher.h" |
| 16 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
| 17 | 17 |
| 18 | 18 |
| 19 const char GoogleURLTracker::kDefaultGoogleHomepage[] = | 19 const char GoogleURLTracker::kDefaultGoogleHomepage[] = |
| 20 "http://www.google.com/"; | 20 "https://www.google.com/"; |
| 21 const char GoogleURLTracker::kSearchDomainCheckURL[] = | 21 const char GoogleURLTracker::kSearchDomainCheckURL[] = |
| 22 "https://www.google.com/searchdomaincheck?format=url&type=chrome"; | 22 "https://www.google.com/searchdomaincheck?format=domain&type=chrome"; |
| 23 | 23 |
| 24 GoogleURLTracker::GoogleURLTracker(scoped_ptr<GoogleURLTrackerClient> client, | 24 GoogleURLTracker::GoogleURLTracker(scoped_ptr<GoogleURLTrackerClient> client, |
| 25 Mode mode) | 25 Mode mode) |
| 26 : client_(client.Pass()), | 26 : client_(client.Pass()), |
| 27 google_url_(mode == UNIT_TEST_MODE ? | 27 google_url_(mode == UNIT_TEST_MODE ? |
| 28 kDefaultGoogleHomepage : | 28 kDefaultGoogleHomepage : |
| 29 client_->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)), | 29 client_->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)), |
| 30 fetcher_id_(0), | 30 fetcher_id_(0), |
| 31 in_startup_sleep_(true), | 31 in_startup_sleep_(true), |
| 32 already_fetched_(false), | 32 already_fetched_(false), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 void GoogleURLTracker::OnURLFetchComplete(const net::URLFetcher* source) { | 74 void GoogleURLTracker::OnURLFetchComplete(const net::URLFetcher* source) { |
| 75 // Delete the fetcher on this function's exit. | 75 // Delete the fetcher on this function's exit. |
| 76 scoped_ptr<net::URLFetcher> clean_up_fetcher(fetcher_.release()); | 76 scoped_ptr<net::URLFetcher> clean_up_fetcher(fetcher_.release()); |
| 77 | 77 |
| 78 // Don't update the URL if the request didn't succeed. | 78 // Don't update the URL if the request didn't succeed. |
| 79 if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200)) { | 79 if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200)) { |
| 80 already_fetched_ = false; | 80 already_fetched_ = false; |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 | 83 |
| 84 // See if the response data was valid. It should be | 84 // See if the response data was valid. It should be ".google.<TLD>". |
| 85 // "<scheme>://[www.]google.<TLD>/". | |
| 86 std::string url_str; | 85 std::string url_str; |
| 87 source->GetResponseAsString(&url_str); | 86 source->GetResponseAsString(&url_str); |
| 88 base::TrimWhitespace(url_str, base::TRIM_ALL, &url_str); | 87 base::TrimWhitespace(url_str, base::TRIM_ALL, &url_str); |
| 89 GURL url(url_str); | 88 if (!StartsWithASCII(url_str, ".google.", false)) |
| 89 return; |
| 90 GURL url("https://www" + url_str); |
| 90 if (!url.is_valid() || (url.path().length() > 1) || url.has_query() || | 91 if (!url.is_valid() || (url.path().length() > 1) || url.has_query() || |
| 91 url.has_ref() || | 92 url.has_ref() || |
| 92 !google_util::IsGoogleDomainUrl(url, | 93 !google_util::IsGoogleDomainUrl(url, google_util::DISALLOW_SUBDOMAIN, |
| 93 google_util::DISALLOW_SUBDOMAIN, | |
| 94 google_util::DISALLOW_NON_STANDARD_PORTS)) | 94 google_util::DISALLOW_NON_STANDARD_PORTS)) |
| 95 return; | 95 return; |
| 96 | 96 |
| 97 if (url != google_url_) { | 97 if (url != google_url_) { |
| 98 google_url_ = url; | 98 google_url_ = url; |
| 99 client_->GetPrefs()->SetString(prefs::kLastKnownGoogleURL, | 99 client_->GetPrefs()->SetString(prefs::kLastKnownGoogleURL, |
| 100 google_url_.spec()); | 100 google_url_.spec()); |
| 101 callback_list_.Notify(); | 101 callback_list_.Notify(); |
| 102 } | 102 } |
| 103 } | 103 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // Also retry kMaxRetries times on network change errors. A network change can | 164 // Also retry kMaxRetries times on network change errors. A network change can |
| 165 // propagate through Chrome in various stages, so it's possible for this code | 165 // propagate through Chrome in various stages, so it's possible for this code |
| 166 // to be reached via OnNetworkChanged(), and then have the fetch we kick off | 166 // to be reached via OnNetworkChanged(), and then have the fetch we kick off |
| 167 // be canceled due to e.g. the DNS server changing at a later time. In general | 167 // be canceled due to e.g. the DNS server changing at a later time. In general |
| 168 // it's not possible to ensure that by the time we reach here any requests we | 168 // it's not possible to ensure that by the time we reach here any requests we |
| 169 // start won't be canceled in this fashion, so retrying is the best we can do. | 169 // start won't be canceled in this fashion, so retrying is the best we can do. |
| 170 fetcher_->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries); | 170 fetcher_->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries); |
| 171 | 171 |
| 172 fetcher_->Start(); | 172 fetcher_->Start(); |
| 173 } | 173 } |
| OLD | NEW |