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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
23 #include "net/url_request/url_fetcher.h" | 23 #include "net/url_request/url_fetcher.h" |
24 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
25 | 25 |
26 | 26 |
27 const char GoogleURLTracker::kDefaultGoogleHomepage[] = | 27 const char GoogleURLTracker::kDefaultGoogleHomepage[] = |
28 "https://www.google.com/"; | 28 "https://www.google.com/"; |
29 const char GoogleURLTracker::kSearchDomainCheckURL[] = | 29 const char GoogleURLTracker::kSearchDomainCheckURL[] = |
30 "https://www.google.com/searchdomaincheck?format=domain&type=chrome"; | 30 "https://www.google.com/searchdomaincheck?format=domain&type=chrome"; |
31 | 31 |
32 GoogleURLTracker::GoogleURLTracker(scoped_ptr<GoogleURLTrackerClient> client, | 32 GoogleURLTracker::GoogleURLTracker( |
33 Mode mode) | 33 std::unique_ptr<GoogleURLTrackerClient> client, |
| 34 Mode mode) |
34 : client_(std::move(client)), | 35 : client_(std::move(client)), |
35 google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage | 36 google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage |
36 : client_->GetPrefs()->GetString( | 37 : client_->GetPrefs()->GetString( |
37 prefs::kLastKnownGoogleURL)), | 38 prefs::kLastKnownGoogleURL)), |
38 fetcher_id_(0), | 39 fetcher_id_(0), |
39 in_startup_sleep_(true), | 40 in_startup_sleep_(true), |
40 already_fetched_(false), | 41 already_fetched_(false), |
41 need_to_fetch_(false), | 42 need_to_fetch_(false), |
42 weak_ptr_factory_(this) { | 43 weak_ptr_factory_(this) { |
43 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); | 44 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 void GoogleURLTracker::RequestServerCheck(bool force) { | 76 void GoogleURLTracker::RequestServerCheck(bool force) { |
76 // If this instance already has a fetcher, SetNeedToFetch() is unnecessary, | 77 // If this instance already has a fetcher, SetNeedToFetch() is unnecessary, |
77 // and changing |already_fetched_| is wrong. | 78 // and changing |already_fetched_| is wrong. |
78 if (!fetcher_) { | 79 if (!fetcher_) { |
79 if (force) | 80 if (force) |
80 already_fetched_ = false; | 81 already_fetched_ = false; |
81 SetNeedToFetch(); | 82 SetNeedToFetch(); |
82 } | 83 } |
83 } | 84 } |
84 | 85 |
85 scoped_ptr<GoogleURLTracker::Subscription> GoogleURLTracker::RegisterCallback( | 86 std::unique_ptr<GoogleURLTracker::Subscription> |
86 const OnGoogleURLUpdatedCallback& cb) { | 87 GoogleURLTracker::RegisterCallback(const OnGoogleURLUpdatedCallback& cb) { |
87 return callback_list_.Add(cb); | 88 return callback_list_.Add(cb); |
88 } | 89 } |
89 | 90 |
90 void GoogleURLTracker::OnURLFetchComplete(const net::URLFetcher* source) { | 91 void GoogleURLTracker::OnURLFetchComplete(const net::URLFetcher* source) { |
91 // Delete the fetcher on this function's exit. | 92 // Delete the fetcher on this function's exit. |
92 scoped_ptr<net::URLFetcher> clean_up_fetcher(fetcher_.release()); | 93 std::unique_ptr<net::URLFetcher> clean_up_fetcher(std::move(fetcher_)); |
93 | 94 |
94 // Don't update the URL if the request didn't succeed. | 95 // Don't update the URL if the request didn't succeed. |
95 if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200)) { | 96 if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200)) { |
96 already_fetched_ = false; | 97 already_fetched_ = false; |
97 return; | 98 return; |
98 } | 99 } |
99 | 100 |
100 // See if the response data was valid. It should be ".google.<TLD>". | 101 // See if the response data was valid. It should be ".google.<TLD>". |
101 std::string url_str; | 102 std::string url_str; |
102 source->GetResponseAsString(&url_str); | 103 source->GetResponseAsString(&url_str); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // Also retry kMaxRetries times on network change errors. A network change can | 185 // Also retry kMaxRetries times on network change errors. A network change can |
185 // propagate through Chrome in various stages, so it's possible for this code | 186 // propagate through Chrome in various stages, so it's possible for this code |
186 // to be reached via OnNetworkChanged(), and then have the fetch we kick off | 187 // to be reached via OnNetworkChanged(), and then have the fetch we kick off |
187 // be canceled due to e.g. the DNS server changing at a later time. In general | 188 // be canceled due to e.g. the DNS server changing at a later time. In general |
188 // it's not possible to ensure that by the time we reach here any requests we | 189 // it's not possible to ensure that by the time we reach here any requests we |
189 // start won't be canceled in this fashion, so retrying is the best we can do. | 190 // start won't be canceled in this fashion, so retrying is the best we can do. |
190 fetcher_->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries); | 191 fetcher_->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries); |
191 | 192 |
192 fetcher_->Start(); | 193 fetcher_->Start(); |
193 } | 194 } |
OLD | NEW |