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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/webui/signin/user_manager_screen_handler.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/profiles/profile_window.h" 5 #include "chrome/browser/profiles/profile_window.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_dialogs.h" 13 #include "chrome/browser/ui/browser_dialogs.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/user_metrics.h" 15 #include "content/public/browser/user_metrics.h"
16 16
17 #if !defined(OS_IOS) 17 #if !defined(OS_IOS)
18 #include "chrome/browser/ui/browser_finder.h" 18 #include "chrome/browser/ui/browser_finder.h"
19 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
20 #include "chrome/browser/ui/browser_list_observer.h" 20 #include "chrome/browser/ui/browser_list_observer.h"
21 #include "chrome/browser/ui/browser_window.h" 21 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/browser/ui/startup/startup_browser_creator.h" 22 #include "chrome/browser/ui/startup/startup_browser_creator.h"
23 #endif // !defined (OS_IOS) 23 #endif // !defined (OS_IOS)
24 24
25 using base::UserMetricsAction; 25 using base::UserMetricsAction;
26 using content::BrowserThread; 26 using content::BrowserThread;
27 27
28 namespace { 28 namespace {
29 29
30 // Handles running a callback when a new Browser has been completely created. 30 // Handles running a callback when a new Browser for the given profile
31 class BrowserAddedObserver : public chrome::BrowserListObserver { 31 // has been completely created.
32 class BrowserAddedForProfileObserver : public chrome::BrowserListObserver {
32 public: 33 public:
33 explicit BrowserAddedObserver( 34 BrowserAddedForProfileObserver(
34 profiles::ProfileSwitchingDoneCallback callback) : callback_(callback) { 35 Profile* profile,
36 profiles::ProfileSwitchingDoneCallback callback)
37 : profile_(profile),
38 callback_(callback) {
39 DCHECK(!callback_.is_null());
35 BrowserList::AddObserver(this); 40 BrowserList::AddObserver(this);
36 } 41 }
37 virtual ~BrowserAddedObserver() { 42 virtual ~BrowserAddedForProfileObserver() {
38 BrowserList::RemoveObserver(this);
39 } 43 }
40 44
41 private: 45 private:
42 // Overridden from BrowserListObserver: 46 // Overridden from BrowserListObserver:
43 virtual void OnBrowserAdded(Browser* browser) OVERRIDE { 47 virtual void OnBrowserAdded(Browser* browser) OVERRIDE {
44 DCHECK(!callback_.is_null()); 48 if (browser->profile() == profile_) {
45 callback_.Run(); 49 BrowserList::RemoveObserver(this);
50 callback_.Run();
51 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
52 }
46 } 53 }
47 54
55 // Profile for which the browser should be opened.
56 Profile* profile_;
48 profiles::ProfileSwitchingDoneCallback callback_; 57 profiles::ProfileSwitchingDoneCallback callback_;
49 58
50 DISALLOW_COPY_AND_ASSIGN(BrowserAddedObserver); 59 DISALLOW_COPY_AND_ASSIGN(BrowserAddedForProfileObserver);
51 }; 60 };
52 61
53 void OpenBrowserWindowForProfile( 62 void OpenBrowserWindowForProfile(
54 profiles::ProfileSwitchingDoneCallback callback, 63 profiles::ProfileSwitchingDoneCallback callback,
55 bool always_create, 64 bool always_create,
56 bool is_new_profile, 65 bool is_new_profile,
57 chrome::HostDesktopType desktop_type, 66 chrome::HostDesktopType desktop_type,
58 Profile* profile, 67 Profile* profile,
59 Profile::CreateStatus status) { 68 Profile::CreateStatus status) {
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 20 matching lines...) Expand all
81 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); 90 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type);
82 if (browser) { 91 if (browser) {
83 browser->window()->Activate(); 92 browser->window()->Activate();
84 if (!callback.is_null()) 93 if (!callback.is_null())
85 callback.Run(); 94 callback.Run();
86 return; 95 return;
87 } 96 }
88 } 97 }
89 98
90 // If there is a callback, create an observer to make sure it is only 99 // If there is a callback, create an observer to make sure it is only
91 // run when the browser has been completely created. 100 // run when the browser has been completely created. This observer will
92 scoped_ptr<BrowserAddedObserver> browser_added_observer; 101 // delete itself once that happens. This should not leak, because we are
102 // passing |always_create| = true to FindOrCreateNewWindow below, which ends
103 // up calling LaunchBrowser and opens a new window. If for whatever reason
104 // that fails, either something has crashed, or the observer will be cleaned
105 // up when a different browser for this profile is opened.
93 if (!callback.is_null()) 106 if (!callback.is_null())
94 browser_added_observer.reset(new BrowserAddedObserver(callback)); 107 new BrowserAddedForProfileObserver(profile, callback);
95 108
96 // We already dealt with the case when |always_create| was false and a browser 109 // We already dealt with the case when |always_create| was false and a browser
97 // existed, which means that here a browser definitely needs to be created. 110 // existed, which means that here a browser definitely needs to be created.
98 // Passing true for |always_create| means we won't duplicate the code that 111 // Passing true for |always_create| means we won't duplicate the code that
99 // tries to find a browser. 112 // tries to find a browser.
100 profiles::FindOrCreateNewWindowForProfile( 113 profiles::FindOrCreateNewWindowForProfile(
101 profile, 114 profile,
102 is_process_startup, 115 is_process_startup,
103 is_first_run, 116 is_first_run,
104 desktop_type, 117 desktop_type,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 ProfileInfoCache& cache = 213 ProfileInfoCache& cache =
201 g_browser_process->profile_manager()->GetProfileInfoCache(); 214 g_browser_process->profile_manager()->GetProfileInfoCache();
202 215
203 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 216 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
204 cache.SetProfileSigninRequiredAtIndex(index, true); 217 cache.SetProfileSigninRequiredAtIndex(index, true);
205 chrome::ShowUserManager(profile->GetPath()); 218 chrome::ShowUserManager(profile->GetPath());
206 BrowserList::CloseAllBrowsersWithProfile(profile); 219 BrowserList::CloseAllBrowsersWithProfile(profile);
207 } 220 }
208 221
209 } // namespace profiles 222 } // namespace profiles
OLDNEW
« 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