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

Side by Side Diff: chrome/browser/sessions/tab_restore_service.cc

Issue 10917231: Revamp TabNavigation class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Mac Created 8 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/tab_helper.h" 18 #include "chrome/browser/extensions/tab_helper.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/sessions/session_command.h"
20 #include "chrome/browser/sessions/session_service.h" 21 #include "chrome/browser/sessions/session_service.h"
21 #include "chrome/browser/sessions/session_service_factory.h" 22 #include "chrome/browser/sessions/session_service_factory.h"
22 #include "chrome/browser/sessions/session_command.h"
23 #include "chrome/browser/sessions/session_types.h" 23 #include "chrome/browser/sessions/session_types.h"
24 #include "chrome/browser/sessions/tab_restore_service_delegate.h" 24 #include "chrome/browser/sessions/tab_restore_service_delegate.h"
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.h" 26 #include "chrome/browser/ui/tab_contents/tab_contents.h"
27 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 27 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
28 #include "chrome/common/extensions/extension.h" 28 #include "chrome/common/extensions/extension.h"
29 #include "chrome/common/extensions/extension_constants.h" 29 #include "chrome/common/extensions/extension_constants.h"
30 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
31 #include "content/public/browser/navigation_controller.h" 31 #include "content/public/browser/navigation_controller.h"
32 #include "content/public/browser/navigation_entry.h" 32 #include "content/public/browser/navigation_entry.h"
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 TabRestoreServiceDelegate* delegate, 522 TabRestoreServiceDelegate* delegate,
523 NavigationController* controller) { 523 NavigationController* controller) {
524 const int pending_index = controller->GetPendingEntryIndex(); 524 const int pending_index = controller->GetPendingEntryIndex();
525 int entry_count = controller->GetEntryCount(); 525 int entry_count = controller->GetEntryCount();
526 if (entry_count == 0 && pending_index == 0) 526 if (entry_count == 0 && pending_index == 0)
527 entry_count++; 527 entry_count++;
528 tab->navigations.resize(static_cast<int>(entry_count)); 528 tab->navigations.resize(static_cast<int>(entry_count));
529 for (int i = 0; i < entry_count; ++i) { 529 for (int i = 0; i < entry_count; ++i) {
530 NavigationEntry* entry = (i == pending_index) ? 530 NavigationEntry* entry = (i == pending_index) ?
531 controller->GetPendingEntry() : controller->GetEntryAtIndex(i); 531 controller->GetPendingEntry() : controller->GetEntryAtIndex(i);
532 tab->navigations[i].SetFromNavigationEntry(*entry); 532 tab->navigations[i] =
533 TabNavigation::FromNavigationEntry(i, *entry, base::Time::Now());
533 } 534 }
534 tab->timestamp = TimeNow(); 535 tab->timestamp = TimeNow();
535 tab->current_navigation_index = controller->GetCurrentEntryIndex(); 536 tab->current_navigation_index = controller->GetCurrentEntryIndex();
536 if (tab->current_navigation_index == -1 && entry_count > 0) 537 if (tab->current_navigation_index == -1 && entry_count > 0)
537 tab->current_navigation_index = 0; 538 tab->current_navigation_index = 0;
538 tab->tabstrip_index = index; 539 tab->tabstrip_index = index;
539 540
540 TabContents* tab_contents = 541 TabContents* tab_contents =
541 TabContents::FromWebContents(controller->GetWebContents()); 542 TabContents::FromWebContents(controller->GetWebContents());
542 // tab_contents is NULL in some browser tests. 543 // tab_contents is NULL in some browser tests.
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 if (!tab.user_agent_override.empty()) { 702 if (!tab.user_agent_override.empty()) {
702 ScheduleCommand( 703 ScheduleCommand(
703 CreateSetTabUserAgentOverrideCommand(kCommandSetTabUserAgentOverride, 704 CreateSetTabUserAgentOverrideCommand(kCommandSetTabUserAgentOverride,
704 tab.id, tab.user_agent_override)); 705 tab.id, tab.user_agent_override));
705 } 706 }
706 707
707 // Then write the navigations. 708 // Then write the navigations.
708 for (int i = first_index_to_persist, wrote_count = 0; 709 for (int i = first_index_to_persist, wrote_count = 0;
709 i < max_index && wrote_count < 2 * max_persist_navigation_count; ++i) { 710 i < max_index && wrote_count < 2 * max_persist_navigation_count; ++i) {
710 if (ShouldTrackEntry(navigations[i].virtual_url())) { 711 if (ShouldTrackEntry(navigations[i].virtual_url())) {
711 // Creating a NavigationEntry isn't the most efficient way to go about
712 // this, but it simplifies the code and makes it less error prone as we
713 // add new data to NavigationEntry.
714 scoped_ptr<NavigationEntry> entry(
715 navigations[i].ToNavigationEntry(wrote_count, profile()));
716 ScheduleCommand( 712 ScheduleCommand(
717 CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, tab.id, 713 CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, tab.id,
718 wrote_count++, *entry)); 714 navigations[i]));
719 } 715 }
720 } 716 }
721 } 717 }
722 718
723 SessionCommand* TabRestoreService::CreateWindowCommand(SessionID::id_type id, 719 SessionCommand* TabRestoreService::CreateWindowCommand(SessionID::id_type id,
724 int selected_tab_index, 720 int selected_tab_index,
725 int num_tabs, 721 int num_tabs,
726 Time timestamp) { 722 Time timestamp) {
727 WindowPayload2 payload; 723 WindowPayload2 payload;
728 // |timestamp| is aligned on a 16 byte boundary, leaving 4 bytes of 724 // |timestamp| is aligned on a 16 byte boundary, leaving 4 bytes of
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 // the front, not the end and we just added the entries to the end). 1249 // the front, not the end and we just added the entries to the end).
1254 entries_to_write_ = staging_entries_.size(); 1250 entries_to_write_ = staging_entries_.size();
1255 1251
1256 PruneEntries(); 1252 PruneEntries();
1257 NotifyTabsChanged(); 1253 NotifyTabsChanged();
1258 } 1254 }
1259 1255
1260 Time TabRestoreService::TimeNow() const { 1256 Time TabRestoreService::TimeNow() const {
1261 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); 1257 return time_factory_ ? time_factory_->TimeNow() : Time::Now();
1262 } 1258 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_types_unittest.cc ('k') | chrome/browser/sessions/tab_restore_service_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698