OLD | NEW |
---|---|
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 has been completely created. |
Alexei Svitkine (slow)
2014/02/07 15:44:43
Expand comment to say "a new Browser for the given
noms (inactive)
2014/02/07 16:30:58
Done.
| |
31 class BrowserAddedObserver : public chrome::BrowserListObserver { | 31 class BrowserAddedForProfileObserver : public chrome::BrowserListObserver { |
32 public: | 32 public: |
33 explicit BrowserAddedObserver( | 33 BrowserAddedForProfileObserver( |
34 profiles::ProfileSwitchingDoneCallback callback) : callback_(callback) { | 34 Profile* profile, profiles::ProfileSwitchingDoneCallback callback) |
Alexei Svitkine (slow)
2014/02/07 15:44:43
1 param per line
noms (inactive)
2014/02/07 16:30:58
Done.
| |
35 : profile_(profile), | |
36 callback_(callback) { | |
37 DCHECK(!callback_.is_null()); | |
35 BrowserList::AddObserver(this); | 38 BrowserList::AddObserver(this); |
36 } | 39 } |
37 virtual ~BrowserAddedObserver() { | 40 virtual ~BrowserAddedForProfileObserver() { |
38 BrowserList::RemoveObserver(this); | |
39 } | 41 } |
40 | 42 |
41 private: | 43 private: |
42 // Overridden from BrowserListObserver: | 44 // Overridden from BrowserListObserver: |
43 virtual void OnBrowserAdded(Browser* browser) OVERRIDE { | 45 virtual void OnBrowserAdded(Browser* browser) OVERRIDE { |
44 DCHECK(!callback_.is_null()); | 46 if (browser->profile() == profile_) { |
45 callback_.Run(); | 47 BrowserList::RemoveObserver(this); |
48 callback_.Run(); | |
49 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
50 } | |
46 } | 51 } |
47 | 52 |
53 // Profile for which the browser should be opened. | |
54 Profile* profile_; | |
48 profiles::ProfileSwitchingDoneCallback callback_; | 55 profiles::ProfileSwitchingDoneCallback callback_; |
49 | 56 |
50 DISALLOW_COPY_AND_ASSIGN(BrowserAddedObserver); | 57 DISALLOW_COPY_AND_ASSIGN(BrowserAddedObserver); |
51 }; | 58 }; |
52 | 59 |
53 void OpenBrowserWindowForProfile( | 60 void OpenBrowserWindowForProfile( |
54 profiles::ProfileSwitchingDoneCallback callback, | 61 profiles::ProfileSwitchingDoneCallback callback, |
55 bool always_create, | 62 bool always_create, |
56 bool is_new_profile, | 63 bool is_new_profile, |
57 chrome::HostDesktopType desktop_type, | 64 chrome::HostDesktopType desktop_type, |
(...skipping 28 matching lines...) Expand all Loading... | |
86 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); | 93 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); |
87 if (browser) { | 94 if (browser) { |
88 browser->window()->Activate(); | 95 browser->window()->Activate(); |
89 if (!callback.is_null()) | 96 if (!callback.is_null()) |
90 callback.Run(); | 97 callback.Run(); |
91 return; | 98 return; |
92 } | 99 } |
93 } | 100 } |
94 | 101 |
95 // If there is a callback, create an observer to make sure it is only | 102 // If there is a callback, create an observer to make sure it is only |
96 // run when the browser has been completely created. | 103 // run when the browser has been completely created. This observer will |
97 scoped_ptr<BrowserAddedObserver> browser_added_observer; | 104 // delete itself once that happens. This should not leak, because we are |
105 // passing |always_create| = true to FindOrCreateNewWindow below, which ends | |
106 // up calling LaunchBrowser and opens a new window. If for whatever reason | |
107 // that fails, either something has crashed, or the observer will be cleaned | |
108 // up when a different browser for this profile is opened. | |
98 if (!callback.is_null()) | 109 if (!callback.is_null()) |
99 browser_added_observer.reset(new BrowserAddedObserver(callback)); | 110 new BrowserAddedForProfileObserver(profile, callback); |
100 | 111 |
101 // We already dealt with the case when |always_create| was false and a browser | 112 // We already dealt with the case when |always_create| was false and a browser |
102 // existed, which means that here a browser definitely needs to be created. | 113 // existed, which means that here a browser definitely needs to be created. |
103 // Passing true for |always_create| means we won't duplicate the code that | 114 // Passing true for |always_create| means we won't duplicate the code that |
104 // tries to find a browser. | 115 // tries to find a browser. |
105 profiles::FindOrCreateNewWindowForProfile( | 116 profiles::FindOrCreateNewWindowForProfile( |
106 profile, | 117 profile, |
107 is_process_startup, | 118 is_process_startup, |
108 is_first_run, | 119 is_first_run, |
109 desktop_type, | 120 desktop_type, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 ProfileInfoCache& cache = | 216 ProfileInfoCache& cache = |
206 g_browser_process->profile_manager()->GetProfileInfoCache(); | 217 g_browser_process->profile_manager()->GetProfileInfoCache(); |
207 | 218 |
208 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 219 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
209 cache.SetProfileSigninRequiredAtIndex(index, true); | 220 cache.SetProfileSigninRequiredAtIndex(index, true); |
210 chrome::ShowUserManager(profile->GetPath()); | 221 chrome::ShowUserManager(profile->GetPath()); |
211 BrowserList::CloseAllBrowsersWithProfile(profile); | 222 BrowserList::CloseAllBrowsersWithProfile(profile); |
212 } | 223 } |
213 | 224 |
214 } // namespace profiles | 225 } // namespace profiles |
OLD | NEW |