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 "chrome/browser/google/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" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 GoogleURLTracker::~GoogleURLTracker() { | 73 GoogleURLTracker::~GoogleURLTracker() { |
74 // We should only reach here after any tabs and their infobars have been torn | 74 // We should only reach here after any tabs and their infobars have been torn |
75 // down. | 75 // down. |
76 DCHECK(entry_map_.empty()); | 76 DCHECK(entry_map_.empty()); |
77 } | 77 } |
78 | 78 |
79 // static | 79 // static |
80 GURL GoogleURLTracker::GoogleURL(Profile* profile) { | 80 GURL GoogleURLTracker::DefaultGoogleHomepage() { |
81 const GoogleURLTracker* tracker = | 81 return GURL(kDefaultGoogleHomepage); |
82 GoogleURLTrackerFactory::GetForProfile(profile); | |
83 return tracker ? tracker->google_url_ : GURL(kDefaultGoogleHomepage); | |
84 } | 82 } |
85 | 83 |
86 // static | 84 void GoogleURLTracker::RequestServerCheck(bool force) { |
87 void GoogleURLTracker::RequestServerCheck(Profile* profile, bool force) { | 85 // If this instance already has a fetcher, SetNeedToFetch() is unnecessary, |
88 GoogleURLTracker* tracker = GoogleURLTrackerFactory::GetForProfile(profile); | 86 // and changing |already_fetched_| is wrong. |
89 // If the tracker already has a fetcher, SetNeedToFetch() is unnecessary, and | 87 if (!fetcher_) { |
90 // changing |already_fetched_| is wrong. | |
91 if (tracker && !tracker->fetcher_) { | |
92 if (force) | 88 if (force) |
93 tracker->already_fetched_ = false; | 89 already_fetched_ = false; |
94 tracker->SetNeedToFetch(); | 90 SetNeedToFetch(); |
95 } | 91 } |
96 } | 92 } |
97 | 93 |
98 // static | 94 void GoogleURLTracker::GoogleURLSearchCommitted() { |
99 void GoogleURLTracker::GoogleURLSearchCommitted(Profile* profile) { | 95 if (need_to_prompt_) { |
100 GoogleURLTracker* tracker = GoogleURLTrackerFactory::GetForProfile(profile); | 96 search_committed_ = true; |
101 if (tracker) | 97 // These notifications will fire a bit later in the same call chain we're |
102 tracker->SearchCommitted(); | 98 // currently in. |
| 99 if (!client_->IsListeningForNavigationStart()) |
| 100 client_->SetListeningForNavigationStart(true); |
| 101 } |
103 } | 102 } |
104 | 103 |
105 void GoogleURLTracker::AcceptGoogleURL(bool redo_searches) { | 104 void GoogleURLTracker::AcceptGoogleURL(bool redo_searches) { |
106 GURL old_google_url = google_url_; | 105 GURL old_google_url = google_url_; |
107 google_url_ = fetched_google_url_; | 106 google_url_ = fetched_google_url_; |
108 PrefService* prefs = profile_->GetPrefs(); | 107 PrefService* prefs = profile_->GetPrefs(); |
109 prefs->SetString(prefs::kLastKnownGoogleURL, google_url_.spec()); | 108 prefs->SetString(prefs::kLastKnownGoogleURL, google_url_.spec()); |
110 prefs->SetString(prefs::kLastPromptedGoogleURL, google_url_.spec()); | 109 prefs->SetString(prefs::kLastPromptedGoogleURL, google_url_.spec()); |
111 NotifyGoogleURLUpdated(old_google_url, google_url_); | 110 NotifyGoogleURLUpdated(old_google_url, google_url_); |
112 | 111 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 net::LOAD_DO_NOT_SAVE_COOKIES); | 257 net::LOAD_DO_NOT_SAVE_COOKIES); |
259 fetcher_->SetRequestContext(profile_->GetRequestContext()); | 258 fetcher_->SetRequestContext(profile_->GetRequestContext()); |
260 | 259 |
261 // Configure to max_retries at most kMaxRetries times for 5xx errors. | 260 // Configure to max_retries at most kMaxRetries times for 5xx errors. |
262 static const int kMaxRetries = 5; | 261 static const int kMaxRetries = 5; |
263 fetcher_->SetMaxRetriesOn5xx(kMaxRetries); | 262 fetcher_->SetMaxRetriesOn5xx(kMaxRetries); |
264 | 263 |
265 fetcher_->Start(); | 264 fetcher_->Start(); |
266 } | 265 } |
267 | 266 |
268 void GoogleURLTracker::SearchCommitted() { | |
269 if (need_to_prompt_) { | |
270 search_committed_ = true; | |
271 // These notifications will fire a bit later in the same call chain we're | |
272 // currently in. | |
273 if (!client_->IsListeningForNavigationStart()) | |
274 client_->SetListeningForNavigationStart(true); | |
275 } | |
276 } | |
277 | |
278 void GoogleURLTracker::OnNavigationPending( | 267 void GoogleURLTracker::OnNavigationPending( |
279 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, | 268 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, |
280 InfoBarService* infobar_service, | 269 InfoBarService* infobar_service, |
281 int pending_id) { | 270 int pending_id) { |
282 GoogleURLTrackerMapEntry* map_entry = NULL; | 271 GoogleURLTrackerMapEntry* map_entry = NULL; |
283 | 272 |
284 EntryMap::iterator i(entry_map_.find(infobar_service)); | 273 EntryMap::iterator i(entry_map_.find(infobar_service)); |
285 if (i != entry_map_.end()) | 274 if (i != entry_map_.end()) |
286 map_entry = i->second; | 275 map_entry = i->second; |
287 | 276 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 } | 408 } |
420 if (client_->IsListeningForNavigationStart()) { | 409 if (client_->IsListeningForNavigationStart()) { |
421 DCHECK(!search_committed_); | 410 DCHECK(!search_committed_); |
422 client_->SetListeningForNavigationStart(false); | 411 client_->SetListeningForNavigationStart(false); |
423 } | 412 } |
424 } | 413 } |
425 | 414 |
426 void GoogleURLTracker::NotifyGoogleURLUpdated(GURL old_url, GURL new_url) { | 415 void GoogleURLTracker::NotifyGoogleURLUpdated(GURL old_url, GURL new_url) { |
427 callback_list_.Notify(old_url, new_url); | 416 callback_list_.Notify(old_url, new_url); |
428 } | 417 } |
OLD | NEW |