OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/google/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 "chrome/browser/chrome_notification_types.h" | |
12 #include "chrome/browser/google/google_url_tracker_factory.h" | |
13 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" | |
14 #include "chrome/browser/google/google_url_tracker_navigation_helper.h" | |
15 #include "chrome/browser/google/google_util.h" | |
16 #include "chrome/common/pref_names.h" | |
17 #include "components/google/core/browser/google_pref_names.h" | 11 #include "components/google/core/browser/google_pref_names.h" |
18 #include "components/google/core/browser/google_switches.h" | 12 #include "components/google/core/browser/google_switches.h" |
19 #include "components/google/core/browser/google_url_tracker_client.h" | 13 #include "components/google/core/browser/google_url_tracker_infobar_delegate.h" |
| 14 #include "components/google/core/browser/google_url_tracker_navigation_helper.h" |
20 #include "components/infobars/core/infobar.h" | 15 #include "components/infobars/core/infobar.h" |
21 #include "components/infobars/core/infobar_manager.h" | 16 #include "components/infobars/core/infobar_manager.h" |
22 #include "content/public/browser/notification_service.h" | |
23 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
24 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
25 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
26 #include "net/url_request/url_request_status.h" | 20 #include "net/url_request/url_request_status.h" |
27 | 21 |
28 | 22 |
29 const char GoogleURLTracker::kDefaultGoogleHomepage[] = | 23 const char GoogleURLTracker::kDefaultGoogleHomepage[] = |
30 "http://www.google.com/"; | 24 "http://www.google.com/"; |
31 const char GoogleURLTracker::kSearchDomainCheckURL[] = | 25 const char GoogleURLTracker::kSearchDomainCheckURL[] = |
32 "https://www.google.com/searchdomaincheck?format=url&type=chrome"; | 26 "https://www.google.com/searchdomaincheck?format=url&type=chrome"; |
(...skipping 14 matching lines...) Expand all Loading... |
47 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 41 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
48 client_->set_google_url_tracker(this); | 42 client_->set_google_url_tracker(this); |
49 | 43 |
50 // Because this function can be called during startup, when kicking off a URL | 44 // Because this function can be called during startup, when kicking off a URL |
51 // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully | 45 // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully |
52 // long enough to be after startup, but still get results back quickly. | 46 // long enough to be after startup, but still get results back quickly. |
53 // Ideally, instead of this timer, we'd do something like "check if the | 47 // Ideally, instead of this timer, we'd do something like "check if the |
54 // browser is starting up, and if so, come back later", but there is currently | 48 // browser is starting up, and if so, come back later", but there is currently |
55 // no function to do this. | 49 // no function to do this. |
56 // | 50 // |
57 // In UNIT_TEST mode, where we want to explicitly control when the tracker | 51 // In UNIT_TEST_MODE, where we want to explicitly control when the tracker |
58 // "wakes up", we do nothing at all. | 52 // "wakes up", we do nothing at all. |
59 if (mode == NORMAL_MODE) { | 53 if (mode == NORMAL_MODE) { |
60 static const int kStartFetchDelayMS = 5000; | 54 static const int kStartFetchDelayMS = 5000; |
61 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 55 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
62 base::Bind(&GoogleURLTracker::FinishSleep, | 56 base::Bind(&GoogleURLTracker::FinishSleep, |
63 weak_ptr_factory_.GetWeakPtr()), | 57 weak_ptr_factory_.GetWeakPtr()), |
64 base::TimeDelta::FromMilliseconds(kStartFetchDelayMS)); | 58 base::TimeDelta::FromMilliseconds(kStartFetchDelayMS)); |
65 } | 59 } |
66 } | 60 } |
67 | 61 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 115 } |
122 | 116 |
123 // See if the response data was valid. It should be | 117 // See if the response data was valid. It should be |
124 // "<scheme>://[www.]google.<TLD>/". | 118 // "<scheme>://[www.]google.<TLD>/". |
125 std::string url_str; | 119 std::string url_str; |
126 source->GetResponseAsString(&url_str); | 120 source->GetResponseAsString(&url_str); |
127 base::TrimWhitespace(url_str, base::TRIM_ALL, &url_str); | 121 base::TrimWhitespace(url_str, base::TRIM_ALL, &url_str); |
128 GURL url(url_str); | 122 GURL url(url_str); |
129 if (!url.is_valid() || (url.path().length() > 1) || url.has_query() || | 123 if (!url.is_valid() || (url.path().length() > 1) || url.has_query() || |
130 url.has_ref() || | 124 url.has_ref() || |
131 !google_util::IsGoogleDomainUrl(url, google_util::DISALLOW_SUBDOMAIN, | 125 !client_->IsGoogleDomainURL(url)) |
132 google_util::DISALLOW_NON_STANDARD_PORTS)) | |
133 return; | 126 return; |
134 | 127 |
135 std::swap(url, fetched_google_url_); | 128 std::swap(url, fetched_google_url_); |
136 GURL last_prompted_url( | 129 GURL last_prompted_url( |
137 client_->GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); | 130 client_->GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); |
138 | 131 |
139 if (last_prompted_url.is_empty()) { | 132 if (last_prompted_url.is_empty()) { |
140 // On the very first run of Chrome, when we've never looked up the URL at | 133 // On the very first run of Chrome, when we've never looked up the URL at |
141 // all, we should just silently switch over to whatever we get immediately. | 134 // all, we should just silently switch over to whatever we get immediately. |
142 AcceptGoogleURL(true); // Arg is irrelevant. | 135 AcceptGoogleURL(true); // Arg is irrelevant. |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 } | 391 } |
399 if (client_->IsListeningForNavigationStart()) { | 392 if (client_->IsListeningForNavigationStart()) { |
400 DCHECK(!search_committed_); | 393 DCHECK(!search_committed_); |
401 client_->SetListeningForNavigationStart(false); | 394 client_->SetListeningForNavigationStart(false); |
402 } | 395 } |
403 } | 396 } |
404 | 397 |
405 void GoogleURLTracker::NotifyGoogleURLUpdated(GURL old_url, GURL new_url) { | 398 void GoogleURLTracker::NotifyGoogleURLUpdated(GURL old_url, GURL new_url) { |
406 callback_list_.Notify(old_url, new_url); | 399 callback_list_.Notify(old_url, new_url); |
407 } | 400 } |
OLD | NEW |