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/tab_restore_service.h" | 5 #include "chrome/browser/sessions/tab_restore_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 25 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
27 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
28 #include "chrome/common/extensions/extension_constants.h" | 28 #include "chrome/common/extensions/extension_constants.h" |
29 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
30 #include "content/browser/tab_contents/navigation_controller.h" | 30 #include "content/browser/tab_contents/navigation_controller.h" |
31 #include "content/browser/tab_contents/tab_contents.h" | 31 #include "content/browser/tab_contents/tab_contents.h" |
32 #include "content/public/browser/navigation_entry.h" | 32 #include "content/public/browser/navigation_entry.h" |
33 | 33 |
34 using base::Time; | 34 using base::Time; |
| 35 using content::NavigationEntry; |
35 | 36 |
36 // TimeFactory----------------------------------------------------------------- | 37 // TimeFactory----------------------------------------------------------------- |
37 | 38 |
38 TabRestoreService::TimeFactory::~TimeFactory() {} | 39 TabRestoreService::TimeFactory::~TimeFactory() {} |
39 | 40 |
40 // Entry ---------------------------------------------------------------------- | 41 // Entry ---------------------------------------------------------------------- |
41 | 42 |
42 // ID of the next Entry. | 43 // ID of the next Entry. |
43 static SessionID::id_type next_entry_id = 1; | 44 static SessionID::id_type next_entry_id = 1; |
44 | 45 |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 void TabRestoreService::PopulateTab(Tab* tab, | 485 void TabRestoreService::PopulateTab(Tab* tab, |
485 int index, | 486 int index, |
486 TabRestoreServiceDelegate* delegate, | 487 TabRestoreServiceDelegate* delegate, |
487 NavigationController* controller) { | 488 NavigationController* controller) { |
488 const int pending_index = controller->pending_entry_index(); | 489 const int pending_index = controller->pending_entry_index(); |
489 int entry_count = controller->entry_count(); | 490 int entry_count = controller->entry_count(); |
490 if (entry_count == 0 && pending_index == 0) | 491 if (entry_count == 0 && pending_index == 0) |
491 entry_count++; | 492 entry_count++; |
492 tab->navigations.resize(static_cast<int>(entry_count)); | 493 tab->navigations.resize(static_cast<int>(entry_count)); |
493 for (int i = 0; i < entry_count; ++i) { | 494 for (int i = 0; i < entry_count; ++i) { |
494 content::NavigationEntry* entry = (i == pending_index) ? | 495 NavigationEntry* entry = (i == pending_index) ? |
495 controller->GetPendingEntry() : controller->GetEntryAtIndex(i); | 496 controller->GetPendingEntry() : controller->GetEntryAtIndex(i); |
496 tab->navigations[i].SetFromNavigationEntry(*entry); | 497 tab->navigations[i].SetFromNavigationEntry(*entry); |
497 } | 498 } |
498 tab->timestamp = TimeNow(); | 499 tab->timestamp = TimeNow(); |
499 tab->current_navigation_index = controller->GetCurrentEntryIndex(); | 500 tab->current_navigation_index = controller->GetCurrentEntryIndex(); |
500 if (tab->current_navigation_index == -1 && entry_count > 0) | 501 if (tab->current_navigation_index == -1 && entry_count > 0) |
501 tab->current_navigation_index = 0; | 502 tab->current_navigation_index = 0; |
502 tab->tabstrip_index = index; | 503 tab->tabstrip_index = index; |
503 | 504 |
504 TabContentsWrapper* wrapper = | 505 TabContentsWrapper* wrapper = |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 tab.extension_app_id)); | 651 tab.extension_app_id)); |
651 } | 652 } |
652 | 653 |
653 // Then write the navigations. | 654 // Then write the navigations. |
654 for (int i = first_index_to_persist, wrote_count = 0; | 655 for (int i = first_index_to_persist, wrote_count = 0; |
655 i < max_index && wrote_count < 2 * max_persist_navigation_count; ++i) { | 656 i < max_index && wrote_count < 2 * max_persist_navigation_count; ++i) { |
656 if (ShouldTrackEntry(navigations[i].virtual_url())) { | 657 if (ShouldTrackEntry(navigations[i].virtual_url())) { |
657 // Creating a NavigationEntry isn't the most efficient way to go about | 658 // Creating a NavigationEntry isn't the most efficient way to go about |
658 // this, but it simplifies the code and makes it less error prone as we | 659 // this, but it simplifies the code and makes it less error prone as we |
659 // add new data to NavigationEntry. | 660 // add new data to NavigationEntry. |
660 scoped_ptr<content::NavigationEntry> entry( | 661 scoped_ptr<NavigationEntry> entry( |
661 navigations[i].ToNavigationEntry(wrote_count, profile())); | 662 navigations[i].ToNavigationEntry(wrote_count, profile())); |
662 ScheduleCommand( | 663 ScheduleCommand( |
663 CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, tab.id, | 664 CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, tab.id, |
664 wrote_count++, *entry)); | 665 wrote_count++, *entry)); |
665 } | 666 } |
666 } | 667 } |
667 } | 668 } |
668 | 669 |
669 SessionCommand* TabRestoreService::CreateWindowCommand(SessionID::id_type id, | 670 SessionCommand* TabRestoreService::CreateWindowCommand(SessionID::id_type id, |
670 int selected_tab_index, | 671 int selected_tab_index, |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 // the front, not the end and we just added the entries to the end). | 1165 // the front, not the end and we just added the entries to the end). |
1165 entries_to_write_ = staging_entries_.size(); | 1166 entries_to_write_ = staging_entries_.size(); |
1166 | 1167 |
1167 PruneEntries(); | 1168 PruneEntries(); |
1168 NotifyTabsChanged(); | 1169 NotifyTabsChanged(); |
1169 } | 1170 } |
1170 | 1171 |
1171 Time TabRestoreService::TimeNow() const { | 1172 Time TabRestoreService::TimeNow() const { |
1172 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); | 1173 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); |
1173 } | 1174 } |
OLD | NEW |