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

Unified Diff: chrome/browser/profiles/profile_window.cc

Issue 149883004: Fix sketchy User Manager code :( (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/webui/signin/user_manager_screen_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/profiles/profile_window.cc
diff --git a/chrome/browser/profiles/profile_window.cc b/chrome/browser/profiles/profile_window.cc
index b44b33e1fab5e4ab1338f932bdf4008561eb0f94..bd0d533fd215ae552e91e75ee1d62fcf42c1c468 100644
--- a/chrome/browser/profiles/profile_window.cc
+++ b/chrome/browser/profiles/profile_window.cc
@@ -27,27 +27,36 @@ using content::BrowserThread;
namespace {
-// Handles running a callback when a new Browser has been completely created.
-class BrowserAddedObserver : public chrome::BrowserListObserver {
+// Handles running a callback when a new Browser for the given profile
+// has been completely created.
+class BrowserAddedForProfileObserver : public chrome::BrowserListObserver {
public:
- explicit BrowserAddedObserver(
- profiles::ProfileSwitchingDoneCallback callback) : callback_(callback) {
+ BrowserAddedForProfileObserver(
+ Profile* profile,
+ profiles::ProfileSwitchingDoneCallback callback)
+ : profile_(profile),
+ callback_(callback) {
+ DCHECK(!callback_.is_null());
BrowserList::AddObserver(this);
}
- virtual ~BrowserAddedObserver() {
- BrowserList::RemoveObserver(this);
+ virtual ~BrowserAddedForProfileObserver() {
}
private:
// Overridden from BrowserListObserver:
virtual void OnBrowserAdded(Browser* browser) OVERRIDE {
- DCHECK(!callback_.is_null());
- callback_.Run();
+ if (browser->profile() == profile_) {
+ BrowserList::RemoveObserver(this);
+ callback_.Run();
+ base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
+ }
}
+ // Profile for which the browser should be opened.
+ Profile* profile_;
profiles::ProfileSwitchingDoneCallback callback_;
- DISALLOW_COPY_AND_ASSIGN(BrowserAddedObserver);
+ DISALLOW_COPY_AND_ASSIGN(BrowserAddedForProfileObserver);
};
void OpenBrowserWindowForProfile(
@@ -88,10 +97,14 @@ void OpenBrowserWindowForProfile(
}
// If there is a callback, create an observer to make sure it is only
- // run when the browser has been completely created.
- scoped_ptr<BrowserAddedObserver> browser_added_observer;
+ // run when the browser has been completely created. This observer will
+ // delete itself once that happens. This should not leak, because we are
+ // passing |always_create| = true to FindOrCreateNewWindow below, which ends
+ // up calling LaunchBrowser and opens a new window. If for whatever reason
+ // that fails, either something has crashed, or the observer will be cleaned
+ // up when a different browser for this profile is opened.
if (!callback.is_null())
- browser_added_observer.reset(new BrowserAddedObserver(callback));
+ new BrowserAddedForProfileObserver(profile, callback);
// We already dealt with the case when |always_create| was false and a browser
// existed, which means that here a browser definitely needs to be created.
« no previous file with comments | « no previous file | chrome/browser/ui/webui/signin/user_manager_screen_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698