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

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

Issue 10262026: A few small tweaks based on further analysis of GoogleURLTracker: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 | « no previous file | chrome/browser/infobars/infobar_tab_helper.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 <vector> 7 #include <vector>
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 content::OpenURLParams params(google_util::AppendGoogleLocaleParam(GURL( 79 content::OpenURLParams params(google_util::AppendGoogleLocaleParam(GURL(
80 "https://www.google.com/support/chrome/bin/answer.py?answer=1618699")), 80 "https://www.google.com/support/chrome/bin/answer.py?answer=1618699")),
81 content::Referrer(), 81 content::Referrer(),
82 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, 82 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
83 content::PAGE_TRANSITION_LINK, false); 83 content::PAGE_TRANSITION_LINK, false);
84 owner()->web_contents()->OpenURL(params); 84 owner()->web_contents()->OpenURL(params);
85 return false; 85 return false;
86 } 86 }
87 87
88 void GoogleURLTrackerInfoBarDelegate::Show() { 88 void GoogleURLTrackerInfoBarDelegate::Show() {
89 owner()->AddInfoBar(this);
90 showing_ = true; 89 showing_ = true;
90 owner()->AddInfoBar(this); // May delete |this| on failure!
91 } 91 }
92 92
93 void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) { 93 void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) {
94 if (redo_search) {
95 // Re-do the user's search on the new domain.
96 url_canon::Replacements<char> replacements;
97 const std::string& host(new_google_url_.host());
98 replacements.SetHost(host.data(), url_parse::Component(0, host.length()));
99 GURL new_search_url(search_url_.ReplaceComponents(replacements));
100 if (new_search_url.is_valid()) {
101 content::OpenURLParams params(new_search_url, content::Referrer(),
102 CURRENT_TAB, content::PAGE_TRANSITION_GENERATED, false);
103 owner()->web_contents()->OpenURL(params);
104 }
105 }
106
94 if (!showing_) { 107 if (!showing_) {
95 // We haven't been added to a tab, so just delete ourselves. 108 // We haven't been added to a tab, so just delete ourselves.
96 delete this; 109 delete this;
97 return; 110 return;
98 } 111 }
99 112
100 // Synchronously remove ourselves from the URL tracker's list, because the 113 // Synchronously remove ourselves from the URL tracker's list, because the
101 // RemoveInfoBar() call below may result in either a synchronous or an 114 // RemoveInfoBar() call below may result in either a synchronous or an
102 // asynchronous call back to InfoBarClosed(), and it's easier to handle when 115 // asynchronous call back to InfoBarClosed(), and it's easier to handle when
103 // we just guarantee the removal is synchronous. 116 // we just guarantee the removal is synchronous.
104 google_url_tracker_->InfoBarClosed(map_key_); 117 google_url_tracker_->InfoBarClosed(map_key_);
105 google_url_tracker_ = NULL; 118 google_url_tracker_ = NULL;
106 119
107 // If we were showing in a background tab that was then closed, we could have 120 // If we're already animating closed, we won't have an owner. Do nothing in
108 // been leaked, and subsequently reached here due to 121 // this case.
109 // GoogleURLTracker::CloseAllInfoBars(). In this case our owner is now NULL 122 // TODO(pkasting): For now, this can also happen if we were showing in a
110 // so we should just do nothing. 123 // background tab that was then closed, in which case we'll have leaked and
111 // TODO(pkasting): This can go away once the InfoBar ownership model is fixed 124 // subsequently reached here due to GoogleURLTracker::CloseAllInfoBars().
112 // so that infobars in background tabs don't leak on tab closure. 125 // This case will no longer happen once infobars are refactored to own their
113 if (!owner()) 126 // delegates.
114 return; 127 if (owner())
115 128 owner()->RemoveInfoBar(this);
116 if (redo_search) {
117 // Re-do the user's search on the new domain.
118 url_canon::Replacements<char> replacements;
119 const std::string& host(new_google_url_.host());
120 replacements.SetHost(host.data(), url_parse::Component(0, host.length()));
121 GURL new_search_url(search_url_.ReplaceComponents(replacements));
122 if (new_search_url.is_valid()) {
123 content::OpenURLParams params(new_search_url, content::Referrer(),
124 CURRENT_TAB, content::PAGE_TRANSITION_GENERATED, false);
125 owner()->web_contents()->OpenURL(params);
126 }
127 }
128
129 owner()->RemoveInfoBar(this);
130 } 129 }
131 130
132 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { 131 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() {
133 if (google_url_tracker_) 132 if (google_url_tracker_)
134 google_url_tracker_->InfoBarClosed(map_key_); 133 google_url_tracker_->InfoBarClosed(map_key_);
135 } 134 }
136 135
137 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { 136 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const {
138 return l10n_util::GetStringFUTF16(IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE, 137 return l10n_util::GetStringFUTF16(IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE,
139 GetHost(true), GetHost(false)); 138 GetHost(true), GetHost(false));
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 452
454 void GoogleURLTracker::CloseAllInfoBars(bool redo_searches) { 453 void GoogleURLTracker::CloseAllInfoBars(bool redo_searches) {
455 // Close all infobars, whether they've been added to tabs or not. 454 // Close all infobars, whether they've been added to tabs or not.
456 while (!infobar_map_.empty()) 455 while (!infobar_map_.empty())
457 infobar_map_.begin()->second->Close(redo_searches); 456 infobar_map_.begin()->second->Close(redo_searches);
458 457
459 // Any registered listeners for NAV_ENTRY_COMMITTED and TAB_CLOSED are now 458 // Any registered listeners for NAV_ENTRY_COMMITTED and TAB_CLOSED are now
460 // irrelevant as the associated infobars are gone. 459 // irrelevant as the associated infobars are gone.
461 registrar_.RemoveAll(); 460 registrar_.RemoveAll();
462 } 461 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/infobars/infobar_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698