| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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(chrome::SESSION_SERVICE_SAVED, |
| 449 &last_updated_save_time_); | 450 &last_updated_save_time_); |
| 450 NotificationService::current()->Notify( | 451 NotificationService::current()->Notify( |
| 451 NotificationType::SESSION_SERVICE_SAVED, | 452 chrome::SESSION_SERVICE_SAVED, |
| 452 Source<Profile>(profile()), | 453 Source<Profile>(profile()), |
| 453 NotificationService::NoDetails()); | 454 NotificationService::NoDetails()); |
| 454 } | 455 } |
| 455 } | 456 } |
| 456 | 457 |
| 457 void SessionService::Init() { | 458 void SessionService::Init() { |
| 458 // Register for the notifications we're interested in. | 459 // Register for the notifications we're interested in. |
| 459 registrar_.Add(this, NotificationType::TAB_PARENTED, | 460 registrar_.Add(this, NotificationType::TAB_PARENTED, |
| 460 NotificationService::AllSources()); | 461 NotificationService::AllSources()); |
| 461 registrar_.Add(this, NotificationType::TAB_CLOSED, | 462 registrar_.Add(this, NotificationType::TAB_CLOSED, |
| 462 NotificationService::AllSources()); | 463 NotificationService::AllSources()); |
| 463 registrar_.Add(this, NotificationType::NAV_LIST_PRUNED, | 464 registrar_.Add(this, NotificationType::NAV_LIST_PRUNED, |
| 464 NotificationService::AllSources()); | 465 NotificationService::AllSources()); |
| 465 registrar_.Add(this, NotificationType::NAV_ENTRY_CHANGED, | 466 registrar_.Add(this, NotificationType::NAV_ENTRY_CHANGED, |
| 466 NotificationService::AllSources()); | 467 NotificationService::AllSources()); |
| 467 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 468 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
| 468 NotificationService::AllSources()); | 469 NotificationService::AllSources()); |
| 469 registrar_.Add(this, NotificationType::BROWSER_OPENED, | 470 registrar_.Add(this, chrome::BROWSER_OPENED, |
| 470 NotificationService::AllSources()); | 471 NotificationService::AllSources()); |
| 471 registrar_.Add(this, | 472 registrar_.Add(this, |
| 472 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, | 473 chrome::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
| 473 NotificationService::AllSources()); | 474 NotificationService::AllSources()); |
| 474 } | 475 } |
| 475 | 476 |
| 476 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open, | 477 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open, |
| 477 Browser* browser) { | 478 Browser* browser) { |
| 478 if (!has_open_trackable_browsers_ && !BrowserInit::InProcessStartup() && | 479 if (!has_open_trackable_browsers_ && !BrowserInit::InProcessStartup() && |
| 479 !SessionRestore::IsRestoring() | 480 !SessionRestore::IsRestoring() |
| 480 #if defined(OS_MACOSX) | 481 #if defined(OS_MACOSX) |
| 481 // OSX has a fairly different idea of application lifetime than the | 482 // 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 | 483 // other platforms. We need to check that we aren't opening a window |
| (...skipping 18 matching lines...) Expand all Loading... |
| 501 } | 502 } |
| 502 } | 503 } |
| 503 return false; | 504 return false; |
| 504 } | 505 } |
| 505 | 506 |
| 506 void SessionService::Observe(NotificationType type, | 507 void SessionService::Observe(NotificationType type, |
| 507 const NotificationSource& source, | 508 const NotificationSource& source, |
| 508 const NotificationDetails& details) { | 509 const NotificationDetails& details) { |
| 509 // All of our messages have the NavigationController as the source. | 510 // All of our messages have the NavigationController as the source. |
| 510 switch (type.value) { | 511 switch (type.value) { |
| 511 case NotificationType::BROWSER_OPENED: { | 512 case chrome::BROWSER_OPENED: { |
| 512 Browser* browser = Source<Browser>(source).ptr(); | 513 Browser* browser = Source<Browser>(source).ptr(); |
| 513 if (browser->profile() != profile() || | 514 if (browser->profile() != profile() || |
| 514 !should_track_changes_for_browser_type(browser->type())) { | 515 !should_track_changes_for_browser_type(browser->type())) { |
| 515 return; | 516 return; |
| 516 } | 517 } |
| 517 | 518 |
| 518 RestoreIfNecessary(std::vector<GURL>(), browser); | 519 RestoreIfNecessary(std::vector<GURL>(), browser); |
| 519 SetWindowType(browser->session_id(), browser->type()); | 520 SetWindowType(browser->session_id(), browser->type()); |
| 520 break; | 521 break; |
| 521 } | 522 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 *tab->controller().GetEntryAtIndex(current_entry_index)); | 602 *tab->controller().GetEntryAtIndex(current_entry_index)); |
| 602 Details<content::LoadCommittedDetails> changed(details); | 603 Details<content::LoadCommittedDetails> changed(details); |
| 603 if (changed->type == NavigationType::NEW_PAGE || | 604 if (changed->type == NavigationType::NEW_PAGE || |
| 604 changed->type == NavigationType::EXISTING_PAGE) { | 605 changed->type == NavigationType::EXISTING_PAGE) { |
| 605 RecordSessionUpdateHistogramData(NotificationType::NAV_ENTRY_COMMITTED, | 606 RecordSessionUpdateHistogramData(NotificationType::NAV_ENTRY_COMMITTED, |
| 606 &last_updated_nav_entry_commit_time_); | 607 &last_updated_nav_entry_commit_time_); |
| 607 } | 608 } |
| 608 break; | 609 break; |
| 609 } | 610 } |
| 610 | 611 |
| 611 case NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: { | 612 case chrome::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: { |
| 612 ExtensionTabHelper* extension_tab_helper = | 613 ExtensionTabHelper* extension_tab_helper = |
| 613 Source<ExtensionTabHelper>(source).ptr(); | 614 Source<ExtensionTabHelper>(source).ptr(); |
| 614 if (extension_tab_helper->extension_app()) { | 615 if (extension_tab_helper->extension_app()) { |
| 615 RestoreTabHelper* helper = | 616 RestoreTabHelper* helper = |
| 616 extension_tab_helper->tab_contents_wrapper()->restore_tab_helper(); | 617 extension_tab_helper->tab_contents_wrapper()->restore_tab_helper(); |
| 617 SetTabExtensionAppID(helper->window_id(), | 618 SetTabExtensionAppID(helper->window_id(), |
| 618 helper->session_id(), | 619 helper->session_id(), |
| 619 extension_tab_helper->extension_app()->id()); | 620 extension_tab_helper->extension_app()->id()); |
| 620 } | 621 } |
| 621 break; | 622 break; |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 base::TimeTicks* last_updated_time) { | 1356 base::TimeTicks* last_updated_time) { |
| 1356 if (!last_updated_time->is_null()) { | 1357 if (!last_updated_time->is_null()) { |
| 1357 base::TimeDelta delta = base::TimeTicks::Now() - *last_updated_time; | 1358 base::TimeDelta delta = base::TimeTicks::Now() - *last_updated_time; |
| 1358 // We're interested in frequent updates periods longer than | 1359 // We're interested in frequent updates periods longer than |
| 1359 // 10 minutes. | 1360 // 10 minutes. |
| 1360 bool use_long_period = false; | 1361 bool use_long_period = false; |
| 1361 if (delta >= save_delay_in_mins_) { | 1362 if (delta >= save_delay_in_mins_) { |
| 1362 use_long_period = true; | 1363 use_long_period = true; |
| 1363 } | 1364 } |
| 1364 switch (type.value) { | 1365 switch (type.value) { |
| 1365 case NotificationType::SESSION_SERVICE_SAVED : | 1366 case chrome::SESSION_SERVICE_SAVED : |
| 1366 RecordUpdatedSaveTime(delta, use_long_period); | 1367 RecordUpdatedSaveTime(delta, use_long_period); |
| 1367 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); | 1368 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); |
| 1368 break; | 1369 break; |
| 1369 case NotificationType::TAB_CLOSED: | 1370 case NotificationType::TAB_CLOSED: |
| 1370 RecordUpdatedTabClosed(delta, use_long_period); | 1371 RecordUpdatedTabClosed(delta, use_long_period); |
| 1371 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); | 1372 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); |
| 1372 break; | 1373 break; |
| 1373 case NotificationType::NAV_LIST_PRUNED: | 1374 case NotificationType::NAV_LIST_PRUNED: |
| 1374 RecordUpdatedNavListPruned(delta, use_long_period); | 1375 RecordUpdatedNavListPruned(delta, use_long_period); |
| 1375 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); | 1376 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1473 50); | 1474 50); |
| 1474 if (use_long_period) { | 1475 if (use_long_period) { |
| 1475 std::string long_name_("SessionRestore.SaveLongPeriod"); | 1476 std::string long_name_("SessionRestore.SaveLongPeriod"); |
| 1476 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | 1477 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, |
| 1477 delta, | 1478 delta, |
| 1478 save_delay_in_mins_, | 1479 save_delay_in_mins_, |
| 1479 save_delay_in_hrs_, | 1480 save_delay_in_hrs_, |
| 1480 50); | 1481 50); |
| 1481 } | 1482 } |
| 1482 } | 1483 } |
| OLD | NEW |