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" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 explicit BrowserAddedObserver( | 33 explicit BrowserAddedObserver( |
34 profiles::ProfileSwitchingDoneCallback callback) : callback_(callback) { | 34 profiles::ProfileSwitchingDoneCallback callback) : callback_(callback) { |
35 BrowserList::AddObserver(this); | 35 BrowserList::AddObserver(this); |
36 } | 36 } |
37 virtual ~BrowserAddedObserver() { | 37 virtual ~BrowserAddedObserver() { |
38 BrowserList::RemoveObserver(this); | 38 BrowserList::RemoveObserver(this); |
39 } | 39 } |
40 | 40 |
41 private: | 41 private: |
42 // Overridden from BrowserListObserver: | 42 // Overridden from BrowserListObserver: |
43 virtual void OnBrowserAdded(Browser* browser) OVERRIDE { | 43 virtual void OnBrowserAdded(Browser* browser) OVERRIDE { |
Alexei Svitkine (slow)
2014/02/06 22:02:12
I think this should check for the profile of the b
noms (inactive)
2014/02/06 22:51:34
Done.
| |
44 DCHECK(!callback_.is_null()); | 44 DCHECK(!callback_.is_null()); |
Alexei Svitkine (slow)
2014/02/06 22:02:12
This check should probably be in the ctor.
noms (inactive)
2014/02/06 22:51:34
Done.
| |
45 callback_.Run(); | 45 callback_.Run(); |
Alexei Svitkine (slow)
2014/02/06 22:02:12
I think this should unregister itself as an observ
noms (inactive)
2014/02/06 22:51:34
Done.
| |
46 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
46 } | 47 } |
47 | 48 |
48 profiles::ProfileSwitchingDoneCallback callback_; | 49 profiles::ProfileSwitchingDoneCallback callback_; |
49 | 50 |
50 DISALLOW_COPY_AND_ASSIGN(BrowserAddedObserver); | 51 DISALLOW_COPY_AND_ASSIGN(BrowserAddedObserver); |
51 }; | 52 }; |
52 | 53 |
53 void OpenBrowserWindowForProfile( | 54 void OpenBrowserWindowForProfile( |
54 profiles::ProfileSwitchingDoneCallback callback, | 55 profiles::ProfileSwitchingDoneCallback callback, |
55 bool always_create, | 56 bool always_create, |
(...skipping 30 matching lines...) Expand all Loading... | |
86 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); | 87 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); |
87 if (browser) { | 88 if (browser) { |
88 browser->window()->Activate(); | 89 browser->window()->Activate(); |
89 if (!callback.is_null()) | 90 if (!callback.is_null()) |
90 callback.Run(); | 91 callback.Run(); |
91 return; | 92 return; |
92 } | 93 } |
93 } | 94 } |
94 | 95 |
95 // If there is a callback, create an observer to make sure it is only | 96 // If there is a callback, create an observer to make sure it is only |
96 // run when the browser has been completely created. | 97 // run when the browser has been completely created. This observer will |
97 scoped_ptr<BrowserAddedObserver> browser_added_observer; | 98 // delete itself that happens. This should not leak, because we are passing |
Alexei Svitkine (slow)
2014/02/06 22:02:12
Missing a word after "delete itself".
noms (inactive)
2014/02/06 22:51:34
Done.
| |
99 // |always_create| = true to FindOrCreateNewWindow below, which ends up | |
100 // calling LaunchBrowser and opens a new window. If for whatever reason that | |
101 // fails, either something has crashed, or the observer will be cleaned up | |
102 // when a different browser is opened. | |
98 if (!callback.is_null()) | 103 if (!callback.is_null()) |
99 browser_added_observer.reset(new BrowserAddedObserver(callback)); | 104 new BrowserAddedObserver(callback); |
100 | 105 |
101 // We already dealt with the case when |always_create| was false and a browser | 106 // 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. | 107 // 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 | 108 // Passing true for |always_create| means we won't duplicate the code that |
104 // tries to find a browser. | 109 // tries to find a browser. |
105 profiles::FindOrCreateNewWindowForProfile( | 110 profiles::FindOrCreateNewWindowForProfile( |
106 profile, | 111 profile, |
107 is_process_startup, | 112 is_process_startup, |
108 is_first_run, | 113 is_first_run, |
109 desktop_type, | 114 desktop_type, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 ProfileInfoCache& cache = | 210 ProfileInfoCache& cache = |
206 g_browser_process->profile_manager()->GetProfileInfoCache(); | 211 g_browser_process->profile_manager()->GetProfileInfoCache(); |
207 | 212 |
208 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 213 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
209 cache.SetProfileSigninRequiredAtIndex(index, true); | 214 cache.SetProfileSigninRequiredAtIndex(index, true); |
210 chrome::ShowUserManager(profile->GetPath()); | 215 chrome::ShowUserManager(profile->GetPath()); |
211 BrowserList::CloseAllBrowsersWithProfile(profile); | 216 BrowserList::CloseAllBrowsersWithProfile(profile); |
212 } | 217 } |
213 | 218 |
214 } // namespace profiles | 219 } // namespace profiles |
OLD | NEW |