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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/browser_navigator_browsertest.h » ('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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/browser_shutdown.h" 12 #include "chrome/browser/browser_shutdown.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/printing/background_printing_manager.h" 14 #include "chrome/browser/printing/background_printing_manager.h"
15 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
18 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "content/browser/renderer_host/render_process_host.h" 20 #include "content/browser/renderer_host/render_process_host.h"
20 #include "content/browser/tab_contents/navigation_details.h" 21 #include "content/browser/tab_contents/navigation_details.h"
21 #include "content/common/notification_registrar.h" 22 #include "content/common/notification_registrar.h"
22 #include "content/common/notification_service.h" 23 #include "content/common/notification_service.h"
23 #include "content/common/result_codes.h" 24 #include "content/common/result_codes.h"
24 25
25 #if defined(OS_MACOSX) 26 #if defined(OS_MACOSX)
26 #include "chrome/browser/chrome_browser_application_mac.h" 27 #include "chrome/browser/chrome_browser_application_mac.h"
27 #endif 28 #endif
28 29
29 #if defined(OS_CHROMEOS) 30 #if defined(OS_CHROMEOS)
30 #include "chrome/browser/chromeos/boot_times_loader.h" 31 #include "chrome/browser/chromeos/boot_times_loader.h"
31 #include "chrome/browser/chromeos/cros/cros_library.h" 32 #include "chrome/browser/chromeos/cros/cros_library.h"
32 #include "chrome/browser/chromeos/cros/login_library.h" 33 #include "chrome/browser/chromeos/cros/login_library.h"
33 #include "chrome/browser/chromeos/cros/update_library.h" 34 #include "chrome/browser/chromeos/cros/update_library.h"
34 #include "chrome/browser/chromeos/wm_ipc.h" 35 #include "chrome/browser/chromeos/wm_ipc.h"
35 #endif 36 #endif
36 37
37 namespace { 38 namespace {
38 39
39 // This object is instantiated when the first Browser object is added to the 40 // This object is instantiated when the first Browser object is added to the
40 // list and delete when the last one is removed. It watches for loads and 41 // list and delete when the last one is removed. It watches for loads and
41 // creates histograms of some global object counts. 42 // creates histograms of some global object counts.
42 class BrowserActivityObserver : public NotificationObserver { 43 class BrowserActivityObserver : public NotificationObserver {
43 public: 44 public:
44 BrowserActivityObserver() { 45 BrowserActivityObserver() {
45 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, 46 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
46 NotificationService::AllSources()); 47 NotificationService::AllSources());
47 } 48 }
48 ~BrowserActivityObserver() {} 49 ~BrowserActivityObserver() {}
49 50
50 private: 51 private:
51 // NotificationObserver implementation. 52 // NotificationObserver implementation.
52 virtual void Observe(NotificationType type, 53 virtual void Observe(int type,
53 const NotificationSource& source, 54 const NotificationSource& source,
54 const NotificationDetails& details) { 55 const NotificationDetails& details) {
55 DCHECK(type == NotificationType::NAV_ENTRY_COMMITTED); 56 DCHECK(type == content::NOTIFICATION_NAV_ENTRY_COMMITTED);
56 const content::LoadCommittedDetails& load = 57 const content::LoadCommittedDetails& load =
57 *Details<content::LoadCommittedDetails>(details).ptr(); 58 *Details<content::LoadCommittedDetails>(details).ptr();
58 if (!load.is_navigation_to_different_page()) 59 if (!load.is_navigation_to_different_page())
59 return; // Don't log for subframes or other trivial types. 60 return; // Don't log for subframes or other trivial types.
60 61
61 LogRenderProcessHostCount(); 62 LogRenderProcessHostCount();
62 LogBrowserTabCount(); 63 LogBrowserTabCount();
63 } 64 }
64 65
65 // Counts the number of active RenderProcessHosts and logs them. 66 // Counts the number of active RenderProcessHosts and logs them.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 void BrowserList::AddBrowser(Browser* browser) { 236 void BrowserList::AddBrowser(Browser* browser) {
236 DCHECK(browser); 237 DCHECK(browser);
237 browsers_.push_back(browser); 238 browsers_.push_back(browser);
238 239
239 g_browser_process->AddRefModule(); 240 g_browser_process->AddRefModule();
240 241
241 if (!activity_observer) 242 if (!activity_observer)
242 activity_observer = new BrowserActivityObserver; 243 activity_observer = new BrowserActivityObserver;
243 244
244 NotificationService::current()->Notify( 245 NotificationService::current()->Notify(
245 NotificationType::BROWSER_OPENED, 246 chrome::NOTIFICATION_BROWSER_OPENED,
246 Source<Browser>(browser), 247 Source<Browser>(browser),
247 NotificationService::NoDetails()); 248 NotificationService::NoDetails());
248 249
249 // Send out notifications after add has occurred. Do some basic checking to 250 // Send out notifications after add has occurred. Do some basic checking to
250 // try to catch evil observers that change the list from under us. 251 // try to catch evil observers that change the list from under us.
251 size_t original_count = observers_.size(); 252 size_t original_count = observers_.size();
252 FOR_EACH_OBSERVER(Observer, observers_, OnBrowserAdded(browser)); 253 FOR_EACH_OBSERVER(Observer, observers_, OnBrowserAdded(browser));
253 DCHECK_EQ(original_count, observers_.size()) 254 DCHECK_EQ(original_count, observers_.size())
254 << "observer list modified during notification"; 255 << "observer list modified during notification";
255 } 256 }
256 257
257 // static 258 // static
258 void BrowserList::MarkAsCleanShutdown() { 259 void BrowserList::MarkAsCleanShutdown() {
259 for (const_iterator i = begin(); i != end(); ++i) { 260 for (const_iterator i = begin(); i != end(); ++i) {
260 (*i)->profile()->MarkAsCleanShutdown(); 261 (*i)->profile()->MarkAsCleanShutdown();
261 } 262 }
262 } 263 }
263 264
264 void BrowserList::AttemptExitInternal() { 265 void BrowserList::AttemptExitInternal() {
265 NotificationService::current()->Notify( 266 NotificationService::current()->Notify(
266 NotificationType::APP_EXITING, 267 content::NOTIFICATION_APP_EXITING,
267 NotificationService::AllSources(), 268 NotificationService::AllSources(),
268 NotificationService::NoDetails()); 269 NotificationService::NoDetails());
269 270
270 #if !defined(OS_MACOSX) 271 #if !defined(OS_MACOSX)
271 // On most platforms, closing all windows causes the application to exit. 272 // On most platforms, closing all windows causes the application to exit.
272 CloseAllBrowsers(); 273 CloseAllBrowsers();
273 #else 274 #else
274 // On the Mac, the application continues to run once all windows are closed. 275 // On the Mac, the application continues to run once all windows are closed.
275 // Terminate will result in a CloseAllBrowsers() call, and once (and if) 276 // Terminate will result in a CloseAllBrowsers() call, and once (and if)
276 // that is done, will cause the application to exit cleanly. 277 // that is done, will cause the application to exit cleanly.
277 chrome_browser_application_mac::Terminate(); 278 chrome_browser_application_mac::Terminate();
278 #endif 279 #endif
279 } 280 }
280 281
281 // static 282 // static
282 void BrowserList::NotifyAndTerminate(bool fast_path) { 283 void BrowserList::NotifyAndTerminate(bool fast_path) {
283 #if defined(OS_CHROMEOS) 284 #if defined(OS_CHROMEOS)
284 if (!signout) 285 if (!signout)
285 return; 286 return;
286 #endif 287 #endif
287 288
288 if (fast_path) { 289 if (fast_path) {
289 NotificationService::current()->Notify(NotificationType::APP_TERMINATING, 290 NotificationService::current()->Notify(
290 NotificationService::AllSources(), 291 content::NOTIFICATION_APP_TERMINATING,
291 NotificationService::NoDetails()); 292 NotificationService::AllSources(),
293 NotificationService::NoDetails());
292 } 294 }
293 295
294 #if defined(OS_CHROMEOS) 296 #if defined(OS_CHROMEOS)
295 NotifyWindowManagerAboutSignout(); 297 NotifyWindowManagerAboutSignout();
296 chromeos::CrosLibrary* cros_library = chromeos::CrosLibrary::Get(); 298 chromeos::CrosLibrary* cros_library = chromeos::CrosLibrary::Get();
297 if (cros_library->EnsureLoaded()) { 299 if (cros_library->EnsureLoaded()) {
298 // If update has been installed, reboot, otherwise, sign out. 300 // If update has been installed, reboot, otherwise, sign out.
299 if (cros_library->GetUpdateLibrary()->status().status == 301 if (cros_library->GetUpdateLibrary()->status().status ==
300 chromeos::UPDATE_STATUS_UPDATED_NEED_REBOOT) { 302 chromeos::UPDATE_STATUS_UPDATED_NEED_REBOOT) {
301 cros_library->GetUpdateLibrary()->RebootAfterUpdate(); 303 cros_library->GetUpdateLibrary()->RebootAfterUpdate();
(...skipping 10 matching lines...) Expand all
312 // static 314 // static
313 void BrowserList::RemoveBrowser(Browser* browser) { 315 void BrowserList::RemoveBrowser(Browser* browser) {
314 RemoveBrowserFrom(browser, &last_active_browsers_); 316 RemoveBrowserFrom(browser, &last_active_browsers_);
315 317
316 // Closing all windows does not indicate quitting the application on the Mac, 318 // Closing all windows does not indicate quitting the application on the Mac,
317 // however, many UI tests rely on this behavior so leave it be for now and 319 // however, many UI tests rely on this behavior so leave it be for now and
318 // simply ignore the behavior on the Mac outside of unit tests. 320 // simply ignore the behavior on the Mac outside of unit tests.
319 // TODO(andybons): Fix the UI tests to Do The Right Thing. 321 // TODO(andybons): Fix the UI tests to Do The Right Thing.
320 bool closing_last_browser = (browsers_.size() == 1); 322 bool closing_last_browser = (browsers_.size() == 1);
321 NotificationService::current()->Notify( 323 NotificationService::current()->Notify(
322 NotificationType::BROWSER_CLOSED, 324 chrome::NOTIFICATION_BROWSER_CLOSED,
323 Source<Browser>(browser), Details<bool>(&closing_last_browser)); 325 Source<Browser>(browser), Details<bool>(&closing_last_browser));
324 326
325 RemoveBrowserFrom(browser, &browsers_); 327 RemoveBrowserFrom(browser, &browsers_);
326 328
327 // Do some basic checking to try to catch evil observers 329 // Do some basic checking to try to catch evil observers
328 // that change the list from under us. 330 // that change the list from under us.
329 size_t original_count = observers_.size(); 331 size_t original_count = observers_.size();
330 FOR_EACH_OBSERVER(Observer, observers_, OnBrowserRemoved(browser)); 332 FOR_EACH_OBSERVER(Observer, observers_, OnBrowserRemoved(browser));
331 DCHECK_EQ(original_count, observers_.size()) 333 DCHECK_EQ(original_count, observers_.size())
332 << "observer list modified during notification"; 334 << "observer list modified during notification";
(...skipping 10 matching lines...) Expand all
343 // If we're exiting, send out the APP_TERMINATING notification to allow other 345 // If we're exiting, send out the APP_TERMINATING notification to allow other
344 // modules to shut themselves down. 346 // modules to shut themselves down.
345 if (browsers_.empty() && 347 if (browsers_.empty() &&
346 (browser_shutdown::IsTryingToQuit() || 348 (browser_shutdown::IsTryingToQuit() ||
347 g_browser_process->IsShuttingDown())) { 349 g_browser_process->IsShuttingDown())) {
348 // Last browser has just closed, and this is a user-initiated quit or there 350 // Last browser has just closed, and this is a user-initiated quit or there
349 // is no module keeping the app alive, so send out our notification. No need 351 // is no module keeping the app alive, so send out our notification. No need
350 // to call ProfileManager::ShutdownSessionServices() as part of the 352 // to call ProfileManager::ShutdownSessionServices() as part of the
351 // shutdown, because Browser::WindowClosing() already makes sure that the 353 // shutdown, because Browser::WindowClosing() already makes sure that the
352 // SessionService is created and notified. 354 // SessionService is created and notified.
353 NotificationService::current()->Notify(NotificationType::APP_TERMINATING, 355 NotificationService::current()->Notify(
354 NotificationService::AllSources(), 356 content::NOTIFICATION_APP_TERMINATING,
355 NotificationService::NoDetails()); 357 NotificationService::AllSources(),
358 NotificationService::NoDetails());
356 AllBrowsersClosedAndAppExiting(); 359 AllBrowsersClosedAndAppExiting();
357 } 360 }
358 } 361 }
359 362
360 // static 363 // static
361 void BrowserList::AddObserver(BrowserList::Observer* observer) { 364 void BrowserList::AddObserver(BrowserList::Observer* observer) {
362 observers_.AddObserver(observer); 365 observers_.AddObserver(observer);
363 } 366 }
364 367
365 // static 368 // static
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 static bool already_ended = false; 509 static bool already_ended = false;
507 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852 510 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852
508 // In this case, do nothing. 511 // In this case, do nothing.
509 if (already_ended || !NotificationService::current()) 512 if (already_ended || !NotificationService::current())
510 return; 513 return;
511 already_ended = true; 514 already_ended = true;
512 515
513 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); 516 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION);
514 517
515 NotificationService::current()->Notify( 518 NotificationService::current()->Notify(
516 NotificationType::APP_EXITING, 519 content::NOTIFICATION_APP_EXITING,
517 NotificationService::AllSources(), 520 NotificationService::AllSources(),
518 NotificationService::NoDetails()); 521 NotificationService::NoDetails());
519 522
520 // Write important data first. 523 // Write important data first.
521 g_browser_process->EndSession(); 524 g_browser_process->EndSession();
522 525
523 BrowserList::CloseAllBrowsers(); 526 BrowserList::CloseAllBrowsers();
524 527
525 // Send out notification. This is used during testing so that the test harness 528 // Send out notification. This is used during testing so that the test harness
526 // can properly shutdown before we exit. 529 // can properly shutdown before we exit.
527 NotificationService::current()->Notify( 530 NotificationService::current()->Notify(
528 NotificationType::SESSION_END, 531 chrome::NOTIFICATION_SESSION_END,
529 NotificationService::AllSources(), 532 NotificationService::AllSources(),
530 NotificationService::NoDetails()); 533 NotificationService::NoDetails());
531 534
532 // And shutdown. 535 // And shutdown.
533 browser_shutdown::Shutdown(); 536 browser_shutdown::Shutdown();
534 537
535 #if defined(OS_WIN) 538 #if defined(OS_WIN)
536 // At this point the message loop is still running yet we've shut everything 539 // At this point the message loop is still running yet we've shut everything
537 // down. If any messages are processed we'll likely crash. Exit now. 540 // down. If any messages are processed we'll likely crash. Exit now.
538 ExitProcess(ResultCodes::NORMAL_EXIT); 541 ExitProcess(ResultCodes::NORMAL_EXIT);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 // If no more TabContents from Browsers, check the BackgroundPrintingManager. 743 // If no more TabContents from Browsers, check the BackgroundPrintingManager.
741 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { 744 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) {
742 cur_ = *bg_printing_iterator_; 745 cur_ = *bg_printing_iterator_;
743 CHECK(cur_); 746 CHECK(cur_);
744 ++bg_printing_iterator_; 747 ++bg_printing_iterator_;
745 return; 748 return;
746 } 749 }
747 // Reached the end - no more TabContents. 750 // Reached the end - no more TabContents.
748 cur_ = NULL; 751 cur_ = NULL;
749 } 752 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/browser_navigator_browsertest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698