Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/sessions/session_service.h" | 7 #include "chrome/browser/sessions/session_service.h" |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 bool pinned_state; | 123 bool pinned_state; |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 } // namespace | 126 } // namespace |
| 127 | 127 |
| 128 // SessionService ------------------------------------------------------------- | 128 // SessionService ------------------------------------------------------------- |
| 129 | 129 |
| 130 SessionService::SessionService(Profile* profile) | 130 SessionService::SessionService(Profile* profile) |
| 131 : BaseSessionService(SESSION_RESTORE, profile, FilePath()), | 131 : BaseSessionService(SESSION_RESTORE, profile, FilePath()), |
| 132 has_open_trackable_browsers_(false), | 132 has_open_trackable_browsers_(false), |
| 133 move_on_new_browser_(false) { | 133 move_on_new_browser_(false), |
| 134 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), | |
| 135 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), | |
| 136 save_delay_in_hrs_(base::TimeDelta::FromHours(8)) { | |
| 134 Init(); | 137 Init(); |
| 135 } | 138 } |
| 136 | 139 |
| 137 SessionService::SessionService(const FilePath& save_path) | 140 SessionService::SessionService(const FilePath& save_path) |
| 138 : BaseSessionService(SESSION_RESTORE, NULL, save_path), | 141 : BaseSessionService(SESSION_RESTORE, NULL, save_path), |
| 139 has_open_trackable_browsers_(false), | 142 has_open_trackable_browsers_(false), |
| 140 move_on_new_browser_(false) { | 143 move_on_new_browser_(false), |
| 144 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), | |
| 145 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), | |
| 146 save_delay_in_hrs_(base::TimeDelta::FromHours(8)) { | |
| 141 Init(); | 147 Init(); |
| 142 } | 148 } |
| 143 | 149 |
| 144 SessionService::~SessionService() { | 150 SessionService::~SessionService() { |
| 145 Save(); | 151 Save(); |
| 146 } | 152 } |
| 147 | 153 |
| 148 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open) { | 154 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open) { |
| 149 return RestoreIfNecessary(urls_to_open, NULL); | 155 return RestoreIfNecessary(urls_to_open, NULL); |
| 150 } | 156 } |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 new InternalSessionRequest( | 431 new InternalSessionRequest( |
| 426 NewCallback(this, &SessionService::OnGotSessionCommands), | 432 NewCallback(this, &SessionService::OnGotSessionCommands), |
| 427 callback), consumer); | 433 callback), consumer); |
| 428 } | 434 } |
| 429 } | 435 } |
| 430 | 436 |
| 431 void SessionService::Save() { | 437 void SessionService::Save() { |
| 432 bool had_commands = !pending_commands().empty(); | 438 bool had_commands = !pending_commands().empty(); |
| 433 BaseSessionService::Save(); | 439 BaseSessionService::Save(); |
| 434 if (had_commands) { | 440 if (had_commands) { |
| 435 RecordSaveHistogramData(); | 441 RecordSessionUpdateHistogramData(NotificationType::SESSION_SERVICE_SAVED, |
| 442 &last_updated_save_time_); | |
| 436 NotificationService::current()->Notify( | 443 NotificationService::current()->Notify( |
| 437 NotificationType::SESSION_SERVICE_SAVED, | 444 NotificationType::SESSION_SERVICE_SAVED, |
| 438 NotificationService::AllSources(), | 445 NotificationService::AllSources(), |
| 439 NotificationService::NoDetails()); | 446 NotificationService::NoDetails()); |
| 440 } | 447 } |
| 441 } | 448 } |
| 442 | 449 |
| 443 | |
| 444 void SessionService::Init() { | 450 void SessionService::Init() { |
| 445 // Register for the notifications we're interested in. | 451 // Register for the notifications we're interested in. |
| 446 registrar_.Add(this, NotificationType::TAB_PARENTED, | 452 registrar_.Add(this, NotificationType::TAB_PARENTED, |
| 447 NotificationService::AllSources()); | 453 NotificationService::AllSources()); |
| 448 registrar_.Add(this, NotificationType::TAB_CLOSED, | 454 registrar_.Add(this, NotificationType::TAB_CLOSED, |
| 449 NotificationService::AllSources()); | 455 NotificationService::AllSources()); |
| 450 registrar_.Add(this, NotificationType::NAV_LIST_PRUNED, | 456 registrar_.Add(this, NotificationType::NAV_LIST_PRUNED, |
| 451 NotificationService::AllSources()); | 457 NotificationService::AllSources()); |
| 452 registrar_.Add(this, NotificationType::NAV_ENTRY_CHANGED, | 458 registrar_.Add(this, NotificationType::NAV_ENTRY_CHANGED, |
| 453 NotificationService::AllSources()); | 459 NotificationService::AllSources()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 controller->tab_contents()->extension_app()->id()); | 522 controller->tab_contents()->extension_app()->id()); |
| 517 } | 523 } |
| 518 break; | 524 break; |
| 519 } | 525 } |
| 520 | 526 |
| 521 case NotificationType::TAB_CLOSED: { | 527 case NotificationType::TAB_CLOSED: { |
| 522 NavigationController* controller = | 528 NavigationController* controller = |
| 523 Source<NavigationController>(source).ptr(); | 529 Source<NavigationController>(source).ptr(); |
| 524 TabClosed(controller->window_id(), controller->session_id(), | 530 TabClosed(controller->window_id(), controller->session_id(), |
| 525 controller->tab_contents()->closed_by_user_gesture()); | 531 controller->tab_contents()->closed_by_user_gesture()); |
| 532 RecordSessionUpdateHistogramData(NotificationType::TAB_CLOSED, | |
| 533 &last_updated_tab_closed_time_); | |
|
tim (not reviewing)
2010/07/13 16:33:53
indent two more spaces
| |
| 526 break; | 534 break; |
| 527 } | 535 } |
| 528 | 536 |
| 529 case NotificationType::NAV_LIST_PRUNED: { | 537 case NotificationType::NAV_LIST_PRUNED: { |
| 530 NavigationController* controller = | 538 NavigationController* controller = |
| 531 Source<NavigationController>(source).ptr(); | 539 Source<NavigationController>(source).ptr(); |
| 532 Details<NavigationController::PrunedDetails> pruned_details(details); | 540 Details<NavigationController::PrunedDetails> pruned_details(details); |
| 533 if (pruned_details->from_front) { | 541 if (pruned_details->from_front) { |
| 534 TabNavigationPathPrunedFromFront(controller->window_id(), | 542 TabNavigationPathPrunedFromFront(controller->window_id(), |
| 535 controller->session_id(), | 543 controller->session_id(), |
| 536 pruned_details->count); | 544 pruned_details->count); |
| 537 } else { | 545 } else { |
| 538 TabNavigationPathPrunedFromBack(controller->window_id(), | 546 TabNavigationPathPrunedFromBack(controller->window_id(), |
| 539 controller->session_id(), | 547 controller->session_id(), |
| 540 controller->entry_count()); | 548 controller->entry_count()); |
| 541 } | 549 } |
| 550 RecordSessionUpdateHistogramData(NotificationType::NAV_LIST_PRUNED, | |
| 551 &last_updated_nav_list_pruned_time_); | |
|
tim (not reviewing)
2010/07/13 16:33:53
indent two more spaces
| |
| 542 break; | 552 break; |
| 543 } | 553 } |
| 544 | 554 |
| 545 case NotificationType::NAV_ENTRY_CHANGED: { | 555 case NotificationType::NAV_ENTRY_CHANGED: { |
| 546 NavigationController* controller = | 556 NavigationController* controller = |
| 547 Source<NavigationController>(source).ptr(); | 557 Source<NavigationController>(source).ptr(); |
| 548 Details<NavigationController::EntryChangedDetails> changed(details); | 558 Details<NavigationController::EntryChangedDetails> changed(details); |
| 549 UpdateTabNavigation(controller->window_id(), controller->session_id(), | 559 UpdateTabNavigation(controller->window_id(), controller->session_id(), |
| 550 changed->index, *changed->changed_entry); | 560 changed->index, *changed->changed_entry); |
| 551 break; | 561 break; |
| 552 } | 562 } |
| 553 | 563 |
| 554 case NotificationType::NAV_ENTRY_COMMITTED: { | 564 case NotificationType::NAV_ENTRY_COMMITTED: { |
| 555 NavigationController* controller = | 565 NavigationController* controller = |
| 556 Source<NavigationController>(source).ptr(); | 566 Source<NavigationController>(source).ptr(); |
| 557 int current_entry_index = controller->GetCurrentEntryIndex(); | 567 int current_entry_index = controller->GetCurrentEntryIndex(); |
| 558 SetSelectedNavigationIndex(controller->window_id(), | 568 SetSelectedNavigationIndex(controller->window_id(), |
| 559 controller->session_id(), | 569 controller->session_id(), |
| 560 current_entry_index); | 570 current_entry_index); |
| 561 UpdateTabNavigation(controller->window_id(), controller->session_id(), | 571 UpdateTabNavigation(controller->window_id(), controller->session_id(), |
| 562 current_entry_index, | 572 current_entry_index, |
| 563 *controller->GetEntryAtIndex(current_entry_index)); | 573 *controller->GetEntryAtIndex(current_entry_index)); |
| 574 Details<NavigationController::LoadCommittedDetails> changed(details); | |
| 575 if (changed->type == NavigationType::NEW_PAGE || | |
| 576 changed->type == NavigationType::EXISTING_PAGE) | |
| 577 RecordSessionUpdateHistogramData(NotificationType::NAV_ENTRY_COMMITTED, | |
| 578 &last_updated_nav_entry_commit_time_); | |
|
tim (not reviewing)
2010/07/13 16:33:53
if an 'if' statement is more than one line, it nee
| |
| 564 break; | 579 break; |
| 565 } | 580 } |
| 566 | 581 |
| 567 case NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: { | 582 case NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED: { |
| 568 TabContents* tab_contents = Source<TabContents>(source).ptr(); | 583 TabContents* tab_contents = Source<TabContents>(source).ptr(); |
| 569 DCHECK(tab_contents); | 584 DCHECK(tab_contents); |
| 570 if (tab_contents->extension_app()) { | 585 if (tab_contents->extension_app()) { |
| 571 SetTabExtensionAppID(tab_contents->controller().window_id(), | 586 SetTabExtensionAppID(tab_contents->controller().window_id(), |
| 572 tab_contents->controller().session_id(), | 587 tab_contents->controller().session_id(), |
| 573 tab_contents->extension_app()->id()); | 588 tab_contents->extension_app()->id()); |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1316 case TYPE_DEVTOOLS: | 1331 case TYPE_DEVTOOLS: |
| 1317 return Browser::TYPE_DEVTOOLS; | 1332 return Browser::TYPE_DEVTOOLS; |
| 1318 case TYPE_APP_PANEL: | 1333 case TYPE_APP_PANEL: |
| 1319 return Browser::TYPE_APP_PANEL; | 1334 return Browser::TYPE_APP_PANEL; |
| 1320 case TYPE_NORMAL: | 1335 case TYPE_NORMAL: |
| 1321 default: | 1336 default: |
| 1322 return Browser::TYPE_NORMAL; | 1337 return Browser::TYPE_NORMAL; |
| 1323 } | 1338 } |
| 1324 } | 1339 } |
| 1325 | 1340 |
| 1326 void SessionService::RecordSaveHistogramData() { | 1341 void SessionService::RecordSessionUpdateHistogramData(NotificationType type, |
| 1327 if (!last_save_time_.is_null()) { | 1342 base::TimeTicks* last_updated_time) { |
| 1328 base::TimeDelta delta = base::TimeTicks::Now() - last_save_time_; | 1343 if (!(*last_updated_time).is_null()) { |
|
tim (not reviewing)
2010/07/13 16:33:53
nit "if (!last_updated_time->is_null())"
| |
| 1329 // We're interested in frequent updates, and group all periods longer than | 1344 base::TimeDelta delta = base::TimeTicks::Now() - *last_updated_time; |
| 1330 // 10 minutes together. | 1345 // We're interested in frequent updates periods longer than |
| 1331 UMA_HISTOGRAM_CUSTOM_TIMES("SessionRestore.SavePeriod", | 1346 // 10 minutes. |
| 1332 delta, | 1347 bool use_long_period = false; |
| 1333 // 2500ms is the default save delay for coaelescing. This parameter | 1348 if (delta >= save_delay_in_mins_) { |
| 1334 // only impacts histogram creation, and not steady-state sampling. | 1349 use_long_period = true; |
| 1335 base::TimeDelta::FromMilliseconds(2500), | 1350 } |
| 1336 base::TimeDelta::FromMinutes(10), | 1351 switch (type.value) { |
| 1337 50); | 1352 case NotificationType::SESSION_SERVICE_SAVED : |
| 1338 | 1353 RecordUpdatedSaveTime(delta, use_long_period); |
| 1339 if (delta >= base::TimeDelta::FromMinutes(10)) { | 1354 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); |
| 1340 UMA_HISTOGRAM_CUSTOM_TIMES("SessionRestore.LongSavePeriod", | 1355 break; |
| 1341 delta, | 1356 case NotificationType::TAB_CLOSED: |
| 1342 base::TimeDelta::FromMinutes(10), | 1357 RecordUpdatedTabClosed(delta, use_long_period); |
| 1343 base::TimeDelta::FromHours(8), | 1358 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); |
| 1344 50); | 1359 break; |
| 1360 case NotificationType::NAV_LIST_PRUNED: | |
| 1361 RecordUpdatedNavListPruned(delta, use_long_period); | |
| 1362 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); | |
| 1363 break; | |
| 1364 case NotificationType::NAV_ENTRY_COMMITTED: | |
| 1365 RecordUpdatedNavEntryCommit(delta, use_long_period); | |
| 1366 RecordUpdatedSessionNavigationOrTab(delta, use_long_period); | |
| 1367 break; | |
| 1368 default: | |
| 1369 NOTREACHED() << "Bad type sent to RecordSessionUpdateHistogramData"; | |
|
tim (not reviewing)
2010/07/13 16:33:53
nit - indent one more space
| |
| 1370 break; | |
| 1345 } | 1371 } |
| 1346 } | 1372 } |
| 1373 (*last_updated_time) = base::TimeTicks::Now(); | |
| 1374 } | |
| 1347 | 1375 |
| 1348 last_save_time_ = base::TimeTicks::Now(); | 1376 void SessionService::RecordUpdatedTabClosed(base::TimeDelta delta, |
| 1377 bool use_long_period) { | |
| 1378 std::string name("SessionRestore.TabClosedPeriod"); | |
| 1379 UMA_HISTOGRAM_CUSTOM_TIMES(name, | |
| 1380 delta, | |
| 1381 // 2500ms is the default save delay. | |
| 1382 save_delay_in_millis_, | |
| 1383 save_delay_in_mins_, | |
| 1384 50); | |
| 1385 if (use_long_period) { | |
| 1386 std::string long_name_("SessionRestore.TabClosedLongPeriod"); | |
| 1387 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | |
| 1388 delta, | |
| 1389 save_delay_in_mins_, | |
| 1390 save_delay_in_hrs_, | |
| 1391 50); | |
| 1392 } | |
| 1349 } | 1393 } |
| 1394 | |
| 1395 void SessionService::RecordUpdatedNavListPruned(base::TimeDelta delta, | |
| 1396 bool use_long_period) { | |
| 1397 std::string name("SessionRestore.NavigationListPrunedPeriod"); | |
| 1398 UMA_HISTOGRAM_CUSTOM_TIMES(name, | |
| 1399 delta, | |
| 1400 // 2500ms is the default save delay. | |
| 1401 save_delay_in_millis_, | |
| 1402 save_delay_in_mins_, | |
| 1403 50); | |
| 1404 if (use_long_period) { | |
| 1405 std::string long_name_("SessionRestore.NavigationListPrunedLongPeriod"); | |
| 1406 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | |
| 1407 delta, | |
| 1408 save_delay_in_mins_, | |
| 1409 save_delay_in_hrs_, | |
| 1410 50); | |
| 1411 } | |
| 1412 } | |
| 1413 | |
| 1414 void SessionService::RecordUpdatedNavEntryCommit(base::TimeDelta delta, | |
| 1415 bool use_long_period) { | |
| 1416 std::string name("SessionRestore.NavEntryCommittedPeriod"); | |
| 1417 UMA_HISTOGRAM_CUSTOM_TIMES(name, | |
| 1418 delta, | |
| 1419 // 2500ms is the default save delay. | |
| 1420 save_delay_in_millis_, | |
| 1421 save_delay_in_mins_, | |
| 1422 50); | |
| 1423 if (use_long_period) { | |
| 1424 std::string long_name_("SessionRestore.NavEntryCommittedLongPeriod"); | |
| 1425 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | |
| 1426 delta, | |
| 1427 save_delay_in_mins_, | |
| 1428 save_delay_in_hrs_, | |
| 1429 50); | |
| 1430 } | |
| 1431 } | |
| 1432 | |
| 1433 void SessionService::RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta, | |
| 1434 bool use_long_period) { | |
| 1435 std::string name("SessionRestore.NavOrTabUpdatePeriod"); | |
| 1436 UMA_HISTOGRAM_CUSTOM_TIMES(name, | |
| 1437 delta, | |
| 1438 // 2500ms is the default save delay. | |
| 1439 save_delay_in_millis_, | |
| 1440 save_delay_in_mins_, | |
| 1441 50); | |
| 1442 if (use_long_period) { | |
| 1443 std::string long_name_("SessionRestore.NavOrTabUpdateLongPeriod"); | |
| 1444 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | |
| 1445 delta, | |
| 1446 save_delay_in_mins_, | |
| 1447 save_delay_in_hrs_, | |
| 1448 50); | |
| 1449 } | |
| 1450 } | |
| 1451 | |
| 1452 void SessionService::RecordUpdatedSaveTime(base::TimeDelta delta, | |
| 1453 bool use_long_period) { | |
| 1454 std::string name("SessionRestore.SavePeriod"); | |
| 1455 UMA_HISTOGRAM_CUSTOM_TIMES(name, | |
| 1456 delta, | |
| 1457 // 2500ms is the default save delay. | |
| 1458 save_delay_in_millis_, | |
| 1459 save_delay_in_mins_, | |
| 1460 50); | |
| 1461 if (use_long_period) { | |
| 1462 std::string long_name_("SessionRestore.SaveLongPeriod"); | |
| 1463 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | |
| 1464 delta, | |
| 1465 save_delay_in_mins_, | |
| 1466 save_delay_in_hrs_, | |
| 1467 50); | |
| 1468 } | |
| 1469 } | |
| 1470 | |
| OLD | NEW |