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

Side by Side Diff: chrome/browser/sessions/session_service.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
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/sessions/session_service.h" 5 #include "chrome/browser/sessions/session_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/sessions/restore_tab_helper.h" 21 #include "chrome/browser/sessions/restore_tab_helper.h"
22 #include "chrome/browser/sessions/session_backend.h" 22 #include "chrome/browser/sessions/session_backend.h"
23 #include "chrome/browser/sessions/session_command.h" 23 #include "chrome/browser/sessions/session_command.h"
24 #include "chrome/browser/sessions/session_restore.h" 24 #include "chrome/browser/sessions/session_restore.h"
25 #include "chrome/browser/sessions/session_types.h" 25 #include "chrome/browser/sessions/session_types.h"
26 #include "chrome/browser/tabs/tab_strip_model.h" 26 #include "chrome/browser/tabs/tab_strip_model.h"
27 #include "chrome/browser/ui/browser_init.h" 27 #include "chrome/browser/ui/browser_init.h"
28 #include "chrome/browser/ui/browser_list.h" 28 #include "chrome/browser/ui/browser_list.h"
29 #include "chrome/browser/ui/browser_window.h" 29 #include "chrome/browser/ui/browser_window.h"
30 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 30 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
31 #include "chrome/common/chrome_notification_types.h"
31 #include "chrome/common/extensions/extension.h" 32 #include "chrome/common/extensions/extension.h"
32 #include "content/browser/tab_contents/navigation_details.h" 33 #include "content/browser/tab_contents/navigation_details.h"
33 #include "content/browser/tab_contents/navigation_entry.h" 34 #include "content/browser/tab_contents/navigation_entry.h"
34 #include "content/browser/tab_contents/tab_contents.h" 35 #include "content/browser/tab_contents/tab_contents.h"
35 #include "content/common/notification_details.h" 36 #include "content/common/notification_details.h"
36 #include "content/common/notification_service.h" 37 #include "content/common/notification_service.h"
37 38
38 #if defined(OS_MACOSX) 39 #if defined(OS_MACOSX)
39 #include "chrome/browser/app_controller_cppsafe_mac.h" 40 #include "chrome/browser/app_controller_cppsafe_mac.h"
40 #endif 41 #endif
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 new InternalSessionRequest( 439 new InternalSessionRequest(
439 NewCallback(this, &SessionService::OnGotSessionCommands), 440 NewCallback(this, &SessionService::OnGotSessionCommands),
440 callback), consumer); 441 callback), consumer);
441 } 442 }
442 } 443 }
443 444
444 void SessionService::Save() { 445 void SessionService::Save() {
445 bool had_commands = !pending_commands().empty(); 446 bool had_commands = !pending_commands().empty();
446 BaseSessionService::Save(); 447 BaseSessionService::Save();
447 if (had_commands) { 448 if (had_commands) {
448 RecordSessionUpdateHistogramData(NotificationType::SESSION_SERVICE_SAVED, 449 RecordSessionUpdateHistogramData(
450 chrome::NOTIFICATION_SESSION_SERVICE_SAVED,
449 &last_updated_save_time_); 451 &last_updated_save_time_);
450 NotificationService::current()->Notify( 452 NotificationService::current()->Notify(
451 NotificationType::SESSION_SERVICE_SAVED, 453 chrome::NOTIFICATION_SESSION_SERVICE_SAVED,
452 Source<Profile>(profile()), 454 Source<Profile>(profile()),
453 NotificationService::NoDetails()); 455 NotificationService::NoDetails());
454 } 456 }
455 } 457 }
456 458
457 void SessionService::Init() { 459 void SessionService::Init() {
458 // Register for the notifications we're interested in. 460 // Register for the notifications we're interested in.
459 registrar_.Add(this, NotificationType::TAB_PARENTED, 461 registrar_.Add(this, content::NOTIFICATION_TAB_PARENTED,
460 NotificationService::AllSources()); 462 NotificationService::AllSources());
461 registrar_.Add(this, NotificationType::TAB_CLOSED, 463 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED,
462 NotificationService::AllSources()); 464 NotificationService::AllSources());
463 registrar_.Add(this, NotificationType::NAV_LIST_PRUNED, 465 registrar_.Add(this, content::NOTIFICATION_NAV_LIST_PRUNED,
464 NotificationService::AllSources()); 466 NotificationService::AllSources());
465 registrar_.Add(this, NotificationType::NAV_ENTRY_CHANGED, 467 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED,
466 NotificationService::AllSources()); 468 NotificationService::AllSources());
467 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, 469 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
468 NotificationService::AllSources()); 470 NotificationService::AllSources());
469 registrar_.Add(this, NotificationType::BROWSER_OPENED, 471 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED,
470 NotificationService::AllSources()); 472 NotificationService::AllSources());
471 registrar_.Add(this, 473 registrar_.Add(
472 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, 474 this, chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
473 NotificationService::AllSources()); 475 NotificationService::AllSources());
474 } 476 }
475 477
476 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open, 478 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open,
477 Browser* browser) { 479 Browser* browser) {
478 if (!has_open_trackable_browsers_ && !BrowserInit::InProcessStartup() && 480 if (!has_open_trackable_browsers_ && !BrowserInit::InProcessStartup() &&
479 !SessionRestore::IsRestoring() 481 !SessionRestore::IsRestoring()
480 #if defined(OS_MACOSX) 482 #if defined(OS_MACOSX)
481 // OSX has a fairly different idea of application lifetime than the 483 // OSX has a fairly different idea of application lifetime than the
482 // other platforms. We need to check that we aren't opening a window 484 // other platforms. We need to check that we aren't opening a window
483 // from the dock or the menubar. 485 // from the dock or the menubar.
(...skipping 12 matching lines...) Expand all
496 SessionRestore::RestoreSession( 498 SessionRestore::RestoreSession(
497 profile(), browser, 499 profile(), browser,
498 browser ? 0 : SessionRestore::ALWAYS_CREATE_TABBED_BROWSER, 500 browser ? 0 : SessionRestore::ALWAYS_CREATE_TABBED_BROWSER,
499 urls_to_open); 501 urls_to_open);
500 return true; 502 return true;
501 } 503 }
502 } 504 }
503 return false; 505 return false;
504 } 506 }
505 507
506 void SessionService::Observe(NotificationType type, 508 void SessionService::Observe(int type,
507 const NotificationSource& source, 509 const NotificationSource& source,
508 const NotificationDetails& details) { 510 const NotificationDetails& details) {
509 // All of our messages have the NavigationController as the source. 511 // All of our messages have the NavigationController as the source.
510 switch (type.value) { 512 switch (type) {
511 case NotificationType::BROWSER_OPENED: { 513 case chrome::NOTIFICATION_BROWSER_OPENED: {
512 Browser* browser = Source<Browser>(source).ptr(); 514 Browser* browser = Source<Browser>(source).ptr();
513 if (browser->profile() != profile() || 515 if (browser->profile() != profile() ||
514 !should_track_changes_for_browser_type(browser->type())) { 516 !should_track_changes_for_browser_type(browser->type())) {
515 return; 517 return;
516 } 518 }
517 519
518 RestoreIfNecessary(std::vector<GURL>(), browser); 520 RestoreIfNecessary(std::vector<GURL>(), browser);
519 SetWindowType(browser->session_id(), browser->type()); 521 SetWindowType(browser->session_id(), browser->type());
520 break; 522 break;
521 } 523 }
522 524
523 case NotificationType::TAB_PARENTED: { 525 case content::NOTIFICATION_TAB_PARENTED: {
524 TabContentsWrapper* tab = Source<TabContentsWrapper>(source).ptr(); 526 TabContentsWrapper* tab = Source<TabContentsWrapper>(source).ptr();
525 SetTabWindow(tab->restore_tab_helper()->window_id(), 527 SetTabWindow(tab->restore_tab_helper()->window_id(),
526 tab->restore_tab_helper()->session_id()); 528 tab->restore_tab_helper()->session_id());
527 if (tab->extension_tab_helper()->extension_app()) { 529 if (tab->extension_tab_helper()->extension_app()) {
528 SetTabExtensionAppID( 530 SetTabExtensionAppID(
529 tab->restore_tab_helper()->window_id(), 531 tab->restore_tab_helper()->window_id(),
530 tab->restore_tab_helper()->session_id(), 532 tab->restore_tab_helper()->session_id(),
531 tab->extension_tab_helper()->extension_app()->id()); 533 tab->extension_tab_helper()->extension_app()->id());
532 } 534 }
533 break; 535 break;
534 } 536 }
535 537
536 case NotificationType::TAB_CLOSED: { 538 case content::NOTIFICATION_TAB_CLOSED: {
537 TabContentsWrapper* tab = 539 TabContentsWrapper* tab =
538 TabContentsWrapper::GetCurrentWrapperForContents( 540 TabContentsWrapper::GetCurrentWrapperForContents(
539 Source<NavigationController>(source).ptr()->tab_contents()); 541 Source<NavigationController>(source).ptr()->tab_contents());
540 if (!tab) 542 if (!tab)
541 break; 543 break;
542 TabClosed(tab->restore_tab_helper()->window_id(), 544 TabClosed(tab->restore_tab_helper()->window_id(),
543 tab->restore_tab_helper()->session_id(), 545 tab->restore_tab_helper()->session_id(),
544 tab->tab_contents()->closed_by_user_gesture()); 546 tab->tab_contents()->closed_by_user_gesture());
545 RecordSessionUpdateHistogramData(NotificationType::TAB_CLOSED, 547 RecordSessionUpdateHistogramData(content::NOTIFICATION_TAB_CLOSED,
546 &last_updated_tab_closed_time_); 548 &last_updated_tab_closed_time_);
547 break; 549 break;
548 } 550 }
549 551
550 case NotificationType::NAV_LIST_PRUNED: { 552 case content::NOTIFICATION_NAV_LIST_PRUNED: {
551 TabContentsWrapper* tab = 553 TabContentsWrapper* tab =
552 TabContentsWrapper::GetCurrentWrapperForContents( 554 TabContentsWrapper::GetCurrentWrapperForContents(
553 Source<NavigationController>(source).ptr()->tab_contents()); 555 Source<NavigationController>(source).ptr()->tab_contents());
554 if (!tab) 556 if (!tab)
555 break; 557 break;
556 Details<content::PrunedDetails> pruned_details(details); 558 Details<content::PrunedDetails> pruned_details(details);
557 if (pruned_details->from_front) { 559 if (pruned_details->from_front) {
558 TabNavigationPathPrunedFromFront( 560 TabNavigationPathPrunedFromFront(
559 tab->restore_tab_helper()->window_id(), 561 tab->restore_tab_helper()->window_id(),
560 tab->restore_tab_helper()->session_id(), 562 tab->restore_tab_helper()->session_id(),
561 pruned_details->count); 563 pruned_details->count);
562 } else { 564 } else {
563 TabNavigationPathPrunedFromBack( 565 TabNavigationPathPrunedFromBack(
564 tab->restore_tab_helper()->window_id(), 566 tab->restore_tab_helper()->window_id(),
565 tab->restore_tab_helper()->session_id(), 567 tab->restore_tab_helper()->session_id(),
566 tab->controller().entry_count()); 568 tab->controller().entry_count());
567 } 569 }
568 RecordSessionUpdateHistogramData(NotificationType::NAV_LIST_PRUNED, 570 RecordSessionUpdateHistogramData(content::NOTIFICATION_NAV_LIST_PRUNED,
569 &last_updated_nav_list_pruned_time_); 571 &last_updated_nav_list_pruned_time_);
570 break; 572 break;
571 } 573 }
572 574
573 case NotificationType::NAV_ENTRY_CHANGED: { 575 case content::NOTIFICATION_NAV_ENTRY_CHANGED: {
574 TabContentsWrapper* tab = 576 TabContentsWrapper* tab =
575 TabContentsWrapper::GetCurrentWrapperForContents( 577 TabContentsWrapper::GetCurrentWrapperForContents(
576 Source<NavigationController>(source).ptr()->tab_contents()); 578 Source<NavigationController>(source).ptr()->tab_contents());
577 if (!tab) 579 if (!tab)
578 break; 580 break;
579 Details<content::EntryChangedDetails> changed(details); 581 Details<content::EntryChangedDetails> changed(details);
580 UpdateTabNavigation( 582 UpdateTabNavigation(
581 tab->restore_tab_helper()->window_id(), 583 tab->restore_tab_helper()->window_id(),
582 tab->restore_tab_helper()->session_id(), 584 tab->restore_tab_helper()->session_id(),
583 changed->index, *changed->changed_entry); 585 changed->index, *changed->changed_entry);
584 break; 586 break;
585 } 587 }
586 588
587 case NotificationType::NAV_ENTRY_COMMITTED: { 589 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
588 TabContentsWrapper* tab = 590 TabContentsWrapper* tab =
589 TabContentsWrapper::GetCurrentWrapperForContents( 591 TabContentsWrapper::GetCurrentWrapperForContents(
590 Source<NavigationController>(source).ptr()->tab_contents()); 592 Source<NavigationController>(source).ptr()->tab_contents());
591 if (!tab) 593 if (!tab)
592 break; 594 break;
593 int current_entry_index = tab->controller().GetCurrentEntryIndex(); 595 int current_entry_index = tab->controller().GetCurrentEntryIndex();
594 SetSelectedNavigationIndex(tab->restore_tab_helper()->window_id(), 596 SetSelectedNavigationIndex(tab->restore_tab_helper()->window_id(),
595 tab->restore_tab_helper()->session_id(), 597 tab->restore_tab_helper()->session_id(),
596 current_entry_index); 598 current_entry_index);
597 UpdateTabNavigation( 599 UpdateTabNavigation(
598 tab->restore_tab_helper()->window_id(), 600 tab->restore_tab_helper()->window_id(),
599 tab->restore_tab_helper()->session_id(), 601 tab->restore_tab_helper()->session_id(),
600 current_entry_index, 602 current_entry_index,
601 *tab->controller().GetEntryAtIndex(current_entry_index)); 603 *tab->controller().GetEntryAtIndex(current_entry_index));
602 Details<content::LoadCommittedDetails> changed(details); 604 Details<content::LoadCommittedDetails> changed(details);
603 if (changed->type == NavigationType::NEW_PAGE || 605 if (changed->type == NavigationType::NEW_PAGE ||
604 changed->type == NavigationType::EXISTING_PAGE) { 606 changed->type == NavigationType::EXISTING_PAGE) {
605 RecordSessionUpdateHistogramData(NotificationType::NAV_ENTRY_COMMITTED, 607 RecordSessionUpdateHistogramData(
608 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
606 &last_updated_nav_entry_commit_time_); 609 &last_updated_nav_entry_commit_time_);
607 } 610 }
608 break; 611 break;
609 } 612 }
610 613
611 case NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: { 614 case chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: {
612 ExtensionTabHelper* extension_tab_helper = 615 ExtensionTabHelper* extension_tab_helper =
613 Source<ExtensionTabHelper>(source).ptr(); 616 Source<ExtensionTabHelper>(source).ptr();
614 if (extension_tab_helper->extension_app()) { 617 if (extension_tab_helper->extension_app()) {
615 RestoreTabHelper* helper = 618 RestoreTabHelper* helper =
616 extension_tab_helper->tab_contents_wrapper()->restore_tab_helper(); 619 extension_tab_helper->tab_contents_wrapper()->restore_tab_helper();
617 SetTabExtensionAppID(helper->window_id(), 620 SetTabExtensionAppID(helper->window_id(),
618 helper->session_id(), 621 helper->session_id(),
619 extension_tab_helper->extension_app()->id()); 622 extension_tab_helper->extension_app()->id());
620 } 623 }
621 break; 624 break;
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 Browser::Type SessionService::BrowserTypeForWindowType(WindowType type) { 1347 Browser::Type SessionService::BrowserTypeForWindowType(WindowType type) {
1345 switch (type) { 1348 switch (type) {
1346 case TYPE_POPUP: 1349 case TYPE_POPUP:
1347 return Browser::TYPE_POPUP; 1350 return Browser::TYPE_POPUP;
1348 case TYPE_TABBED: 1351 case TYPE_TABBED:
1349 default: 1352 default:
1350 return Browser::TYPE_TABBED; 1353 return Browser::TYPE_TABBED;
1351 } 1354 }
1352 } 1355 }
1353 1356
1354 void SessionService::RecordSessionUpdateHistogramData(NotificationType type, 1357 void SessionService::RecordSessionUpdateHistogramData(int type,
1355 base::TimeTicks* last_updated_time) { 1358 base::TimeTicks* last_updated_time) {
1356 if (!last_updated_time->is_null()) { 1359 if (!last_updated_time->is_null()) {
1357 base::TimeDelta delta = base::TimeTicks::Now() - *last_updated_time; 1360 base::TimeDelta delta = base::TimeTicks::Now() - *last_updated_time;
1358 // We're interested in frequent updates periods longer than 1361 // We're interested in frequent updates periods longer than
1359 // 10 minutes. 1362 // 10 minutes.
1360 bool use_long_period = false; 1363 bool use_long_period = false;
1361 if (delta >= save_delay_in_mins_) { 1364 if (delta >= save_delay_in_mins_) {
1362 use_long_period = true; 1365 use_long_period = true;
1363 } 1366 }
1364 switch (type.value) { 1367 switch (type) {
1365 case NotificationType::SESSION_SERVICE_SAVED : 1368 case chrome::NOTIFICATION_SESSION_SERVICE_SAVED :
1366 RecordUpdatedSaveTime(delta, use_long_period); 1369 RecordUpdatedSaveTime(delta, use_long_period);
1367 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); 1370 RecordUpdatedSessionNavigationOrTab(delta, use_long_period);
1368 break; 1371 break;
1369 case NotificationType::TAB_CLOSED: 1372 case content::NOTIFICATION_TAB_CLOSED:
1370 RecordUpdatedTabClosed(delta, use_long_period); 1373 RecordUpdatedTabClosed(delta, use_long_period);
1371 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); 1374 RecordUpdatedSessionNavigationOrTab(delta, use_long_period);
1372 break; 1375 break;
1373 case NotificationType::NAV_LIST_PRUNED: 1376 case content::NOTIFICATION_NAV_LIST_PRUNED:
1374 RecordUpdatedNavListPruned(delta, use_long_period); 1377 RecordUpdatedNavListPruned(delta, use_long_period);
1375 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); 1378 RecordUpdatedSessionNavigationOrTab(delta, use_long_period);
1376 break; 1379 break;
1377 case NotificationType::NAV_ENTRY_COMMITTED: 1380 case content::NOTIFICATION_NAV_ENTRY_COMMITTED:
1378 RecordUpdatedNavEntryCommit(delta, use_long_period); 1381 RecordUpdatedNavEntryCommit(delta, use_long_period);
1379 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); 1382 RecordUpdatedSessionNavigationOrTab(delta, use_long_period);
1380 break; 1383 break;
1381 default: 1384 default:
1382 NOTREACHED() << "Bad type sent to RecordSessionUpdateHistogramData"; 1385 NOTREACHED() << "Bad type sent to RecordSessionUpdateHistogramData";
1383 break; 1386 break;
1384 } 1387 }
1385 } 1388 }
1386 (*last_updated_time) = base::TimeTicks::Now(); 1389 (*last_updated_time) = base::TimeTicks::Now();
1387 } 1390 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 50); 1476 50);
1474 if (use_long_period) { 1477 if (use_long_period) {
1475 std::string long_name_("SessionRestore.SaveLongPeriod"); 1478 std::string long_name_("SessionRestore.SaveLongPeriod");
1476 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, 1479 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_,
1477 delta, 1480 delta,
1478 save_delay_in_mins_, 1481 save_delay_in_mins_,
1479 save_delay_in_hrs_, 1482 save_delay_in_hrs_,
1480 50); 1483 50);
1481 } 1484 }
1482 } 1485 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_service.h ('k') | chrome/browser/sessions/session_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698