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

Side by Side Diff: chrome/browser/ui/browser_list.cc

Issue 1803143002: Replace BrowserProces::AddRefModule/RemoveModule by ScopedKeepAlive (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 9 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
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/ui/browser_list.h" 5 #include "chrome/browser/ui/browser_list.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 if (!*list) 48 if (!*list)
49 *list = new BrowserList; 49 *list = new BrowserList;
50 return *list; 50 return *list;
51 } 51 }
52 52
53 // static 53 // static
54 void BrowserList::AddBrowser(Browser* browser) { 54 void BrowserList::AddBrowser(Browser* browser) {
55 DCHECK(browser); 55 DCHECK(browser);
56 GetInstance()->browsers_.push_back(browser); 56 GetInstance()->browsers_.push_back(browser);
57 57
58 g_browser_process->AddRefModule(); 58 browser->RegisterKeepAlive();
59 59
60 content::NotificationService::current()->Notify( 60 content::NotificationService::current()->Notify(
61 chrome::NOTIFICATION_BROWSER_OPENED, 61 chrome::NOTIFICATION_BROWSER_OPENED,
62 content::Source<Browser>(browser), 62 content::Source<Browser>(browser),
63 content::NotificationService::NoDetails()); 63 content::NotificationService::NoDetails());
64 64
65 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(), 65 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(),
66 OnBrowserAdded(browser)); 66 OnBrowserAdded(browser));
67 } 67 }
68 68
69 // static 69 // static
70 void BrowserList::RemoveBrowser(Browser* browser) { 70 void BrowserList::RemoveBrowser(Browser* browser) {
71 // Remove |browser| from the appropriate list instance. 71 // Remove |browser| from the appropriate list instance.
72 BrowserList* browser_list = GetInstance(); 72 BrowserList* browser_list = GetInstance();
73 RemoveBrowserFrom(browser, &browser_list->last_active_browsers_); 73 RemoveBrowserFrom(browser, &browser_list->last_active_browsers_);
74 74
75 content::NotificationService::current()->Notify( 75 content::NotificationService::current()->Notify(
76 chrome::NOTIFICATION_BROWSER_CLOSED, 76 chrome::NOTIFICATION_BROWSER_CLOSED,
77 content::Source<Browser>(browser), 77 content::Source<Browser>(browser),
78 content::NotificationService::NoDetails()); 78 content::NotificationService::NoDetails());
79 79
80 RemoveBrowserFrom(browser, &browser_list->browsers_); 80 RemoveBrowserFrom(browser, &browser_list->browsers_);
81 81
82 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(), 82 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(),
83 OnBrowserRemoved(browser)); 83 OnBrowserRemoved(browser));
84 84
85 g_browser_process->ReleaseModule(); 85 browser->UnregisterKeepAlive();
86 86
87 // If we're exiting, send out the APP_TERMINATING notification to allow other 87 // If we're exiting, send out the APP_TERMINATING notification to allow other
88 // modules to shut themselves down. 88 // modules to shut themselves down.
89 if (chrome::GetTotalBrowserCount() == 0 && 89 if (chrome::GetTotalBrowserCount() == 0 &&
90 (browser_shutdown::IsTryingToQuit() || 90 (browser_shutdown::IsTryingToQuit() ||
91 g_browser_process->IsShuttingDown())) { 91 g_browser_process->IsShuttingDown())) {
92 // Last browser has just closed, and this is a user-initiated quit or there 92 // Last browser has just closed, and this is a user-initiated quit or there
93 // is no module keeping the app alive, so send out our notification. No need 93 // is no module keeping the app alive, so send out our notification. No need
94 // to call ProfileManager::ShutdownSessionServices() as part of the 94 // to call ProfileManager::ShutdownSessionServices() as part of the
95 // shutdown, because Browser::WindowClosing() already makes sure that the 95 // shutdown, because Browser::WindowClosing() already makes sure that the
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 227 }
228 228
229 // static 229 // static
230 void BrowserList::RemoveBrowserFrom(Browser* browser, 230 void BrowserList::RemoveBrowserFrom(Browser* browser,
231 BrowserVector* browser_list) { 231 BrowserVector* browser_list) {
232 BrowserVector::iterator remove_browser = 232 BrowserVector::iterator remove_browser =
233 std::find(browser_list->begin(), browser_list->end(), browser); 233 std::find(browser_list->begin(), browser_list->end(), browser);
234 if (remove_browser != browser_list->end()) 234 if (remove_browser != browser_list->end())
235 browser_list->erase(remove_browser); 235 browser_list->erase(remove_browser);
236 } 236 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/startup/startup_browser_creator_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698