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

Side by Side Diff: chrome/browser/google/google_url_tracker.cc

Issue 303233006: Abstract GoogleURLTracker & google_util Profile dependencies (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Build fix and rebase Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/google/google_url_tracker.h ('k') | chrome/browser/google/google_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 base::TimeDelta::FromMilliseconds(kStartFetchDelayMS)); 66 base::TimeDelta::FromMilliseconds(kStartFetchDelayMS));
67 } 67 }
68 } 68 }
69 69
70 GoogleURLTracker::~GoogleURLTracker() { 70 GoogleURLTracker::~GoogleURLTracker() {
71 // We should only reach here after any tabs and their infobars have been torn 71 // We should only reach here after any tabs and their infobars have been torn
72 // down. 72 // down.
73 DCHECK(entry_map_.empty()); 73 DCHECK(entry_map_.empty());
74 } 74 }
75 75
76 // static 76 void GoogleURLTracker::RequestServerCheck(bool force) {
77 GURL GoogleURLTracker::GoogleURL(Profile* profile) { 77 // If this instance already has a fetcher, SetNeedToFetch() is unnecessary,
78 const GoogleURLTracker* tracker = 78 // and changing |already_fetched_| is wrong.
79 GoogleURLTrackerFactory::GetForProfile(profile); 79 if (!fetcher_) {
80 return tracker ? tracker->google_url_ : GURL(kDefaultGoogleHomepage);
81 }
82
83 // static
84 void GoogleURLTracker::RequestServerCheck(Profile* profile, bool force) {
85 GoogleURLTracker* tracker = GoogleURLTrackerFactory::GetForProfile(profile);
86 // If the tracker already has a fetcher, SetNeedToFetch() is unnecessary, and
87 // changing |already_fetched_| is wrong.
88 if (tracker && !tracker->fetcher_) {
89 if (force) 80 if (force)
90 tracker->already_fetched_ = false; 81 already_fetched_ = false;
91 tracker->SetNeedToFetch(); 82 SetNeedToFetch();
92 } 83 }
93 } 84 }
94 85
95 // static 86 void GoogleURLTracker::SearchCommitted() {
96 void GoogleURLTracker::GoogleURLSearchCommitted(Profile* profile) { 87 if (need_to_prompt_) {
97 GoogleURLTracker* tracker = GoogleURLTrackerFactory::GetForProfile(profile); 88 search_committed_ = true;
98 if (tracker) 89 // These notifications will fire a bit later in the same call chain we're
99 tracker->SearchCommitted(); 90 // currently in.
91 if (!client_->IsListeningForNavigationStart())
92 client_->SetListeningForNavigationStart(true);
93 }
100 } 94 }
101 95
102 void GoogleURLTracker::AcceptGoogleURL(bool redo_searches) { 96 void GoogleURLTracker::AcceptGoogleURL(bool redo_searches) {
103 GURL old_google_url = google_url_; 97 GURL old_google_url = google_url_;
104 google_url_ = fetched_google_url_; 98 google_url_ = fetched_google_url_;
105 PrefService* prefs = profile_->GetPrefs(); 99 PrefService* prefs = profile_->GetPrefs();
106 prefs->SetString(prefs::kLastKnownGoogleURL, google_url_.spec()); 100 prefs->SetString(prefs::kLastKnownGoogleURL, google_url_.spec());
107 prefs->SetString(prefs::kLastPromptedGoogleURL, google_url_.spec()); 101 prefs->SetString(prefs::kLastPromptedGoogleURL, google_url_.spec());
108 NotifyGoogleURLUpdated(old_google_url, google_url_); 102 NotifyGoogleURLUpdated(old_google_url, google_url_);
109 103
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 net::LOAD_DO_NOT_SAVE_COOKIES); 248 net::LOAD_DO_NOT_SAVE_COOKIES);
255 fetcher_->SetRequestContext(profile_->GetRequestContext()); 249 fetcher_->SetRequestContext(profile_->GetRequestContext());
256 250
257 // Configure to max_retries at most kMaxRetries times for 5xx errors. 251 // Configure to max_retries at most kMaxRetries times for 5xx errors.
258 static const int kMaxRetries = 5; 252 static const int kMaxRetries = 5;
259 fetcher_->SetMaxRetriesOn5xx(kMaxRetries); 253 fetcher_->SetMaxRetriesOn5xx(kMaxRetries);
260 254
261 fetcher_->Start(); 255 fetcher_->Start();
262 } 256 }
263 257
264 void GoogleURLTracker::SearchCommitted() {
265 if (need_to_prompt_) {
266 search_committed_ = true;
267 // These notifications will fire a bit later in the same call chain we're
268 // currently in.
269 if (!client_->IsListeningForNavigationStart())
270 client_->SetListeningForNavigationStart(true);
271 }
272 }
273
274 void GoogleURLTracker::OnNavigationPending( 258 void GoogleURLTracker::OnNavigationPending(
275 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, 259 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper,
276 infobars::InfoBarManager* infobar_manager, 260 infobars::InfoBarManager* infobar_manager,
277 int pending_id) { 261 int pending_id) {
278 GoogleURLTrackerMapEntry* map_entry = NULL; 262 GoogleURLTrackerMapEntry* map_entry = NULL;
279 263
280 EntryMap::iterator i(entry_map_.find(infobar_manager)); 264 EntryMap::iterator i(entry_map_.find(infobar_manager));
281 if (i != entry_map_.end()) 265 if (i != entry_map_.end())
282 map_entry = i->second; 266 map_entry = i->second;
283 267
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 400 }
417 if (client_->IsListeningForNavigationStart()) { 401 if (client_->IsListeningForNavigationStart()) {
418 DCHECK(!search_committed_); 402 DCHECK(!search_committed_);
419 client_->SetListeningForNavigationStart(false); 403 client_->SetListeningForNavigationStart(false);
420 } 404 }
421 } 405 }
422 406
423 void GoogleURLTracker::NotifyGoogleURLUpdated(GURL old_url, GURL new_url) { 407 void GoogleURLTracker::NotifyGoogleURLUpdated(GURL old_url, GURL new_url) {
424 callback_list_.Notify(old_url, new_url); 408 callback_list_.Notify(old_url, new_url);
425 } 409 }
OLDNEW
« no previous file with comments | « chrome/browser/google/google_url_tracker.h ('k') | chrome/browser/google/google_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698