| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 if (tracker) | 100 if (tracker) |
| 101 tracker->SearchCommitted(); | 101 tracker->SearchCommitted(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void GoogleURLTracker::AcceptGoogleURL(bool redo_searches) { | 104 void GoogleURLTracker::AcceptGoogleURL(bool redo_searches) { |
| 105 UpdatedDetails urls(google_url_, fetched_google_url_); | 105 UpdatedDetails urls(google_url_, fetched_google_url_); |
| 106 google_url_ = fetched_google_url_; | 106 google_url_ = fetched_google_url_; |
| 107 PrefService* prefs = profile_->GetPrefs(); | 107 PrefService* prefs = profile_->GetPrefs(); |
| 108 prefs->SetString(prefs::kLastKnownGoogleURL, google_url_.spec()); | 108 prefs->SetString(prefs::kLastKnownGoogleURL, google_url_.spec()); |
| 109 prefs->SetString(prefs::kLastPromptedGoogleURL, google_url_.spec()); | 109 prefs->SetString(prefs::kLastPromptedGoogleURL, google_url_.spec()); |
| 110 NotifyGoogleURLUpdated(urls.first, urls.second); |
| 111 |
| 112 // TODO(blundell): Convert all clients to use the callback interface and |
| 113 // eliminate this notification. crbug.com/373237 |
| 110 content::NotificationService::current()->Notify( | 114 content::NotificationService::current()->Notify( |
| 111 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 115 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
| 112 content::Source<Profile>(profile_), | 116 content::Source<Profile>(profile_), |
| 113 content::Details<UpdatedDetails>(&urls)); | 117 content::Details<UpdatedDetails>(&urls)); |
| 114 need_to_prompt_ = false; | 118 need_to_prompt_ = false; |
| 115 CloseAllEntries(redo_searches); | 119 CloseAllEntries(redo_searches); |
| 116 } | 120 } |
| 117 | 121 |
| 118 void GoogleURLTracker::CancelGoogleURL() { | 122 void GoogleURLTracker::CancelGoogleURL() { |
| 119 profile_->GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, | 123 profile_->GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 // here might (and have comments pointing back here). | 371 // here might (and have comments pointing back here). |
| 368 for (EntryMap::iterator i(entry_map_.begin()); i != entry_map_.end(); ++i) { | 372 for (EntryMap::iterator i(entry_map_.begin()); i != entry_map_.end(); ++i) { |
| 369 if (i->second->navigation_controller() == navigation_controller) { | 373 if (i->second->navigation_controller() == navigation_controller) { |
| 370 i->second->Close(false); | 374 i->second->Close(false); |
| 371 return; | 375 return; |
| 372 } | 376 } |
| 373 } | 377 } |
| 374 NOTREACHED(); | 378 NOTREACHED(); |
| 375 } | 379 } |
| 376 | 380 |
| 381 scoped_ptr<GoogleURLTracker::Subscription> GoogleURLTracker::RegisterCallback( |
| 382 const OnGoogleURLUpdatedCallback& cb) { |
| 383 return callback_list_.Add(cb); |
| 384 } |
| 385 |
| 377 void GoogleURLTracker::CloseAllEntries(bool redo_searches) { | 386 void GoogleURLTracker::CloseAllEntries(bool redo_searches) { |
| 378 // Delete all entries, whether they have infobars or not. | 387 // Delete all entries, whether they have infobars or not. |
| 379 while (!entry_map_.empty()) | 388 while (!entry_map_.empty()) |
| 380 entry_map_.begin()->second->Close(redo_searches); | 389 entry_map_.begin()->second->Close(redo_searches); |
| 381 } | 390 } |
| 382 | 391 |
| 383 void GoogleURLTracker::UnregisterForEntrySpecificNotifications( | 392 void GoogleURLTracker::UnregisterForEntrySpecificNotifications( |
| 384 const GoogleURLTrackerMapEntry& map_entry, | 393 const GoogleURLTrackerMapEntry& map_entry, |
| 385 bool must_be_listening_for_commit) { | 394 bool must_be_listening_for_commit) { |
| 386 // For tabs with map entries but no infobars, we should always be listening | 395 // For tabs with map entries but no infobars, we should always be listening |
| (...skipping 27 matching lines...) Expand all Loading... |
| 414 i->second->navigation_controller())) { | 423 i->second->navigation_controller())) { |
| 415 DCHECK(nav_helper_->IsListeningForNavigationStart()); | 424 DCHECK(nav_helper_->IsListeningForNavigationStart()); |
| 416 return; | 425 return; |
| 417 } | 426 } |
| 418 } | 427 } |
| 419 if (nav_helper_->IsListeningForNavigationStart()) { | 428 if (nav_helper_->IsListeningForNavigationStart()) { |
| 420 DCHECK(!search_committed_); | 429 DCHECK(!search_committed_); |
| 421 nav_helper_->SetListeningForNavigationStart(false); | 430 nav_helper_->SetListeningForNavigationStart(false); |
| 422 } | 431 } |
| 423 } | 432 } |
| 433 |
| 434 void GoogleURLTracker::NotifyGoogleURLUpdated(GURL old_url, GURL new_url) { |
| 435 callback_list_.Notify(old_url, new_url); |
| 436 } |
| OLD | NEW |