| OLD | NEW |
| 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/extension_tab_helper.h" | 18 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/sessions/session_service.h" | 20 #include "chrome/browser/sessions/session_service.h" |
| 21 #include "chrome/browser/sessions/session_service_factory.h" | 21 #include "chrome/browser/sessions/session_service_factory.h" |
| 22 #include "chrome/browser/sessions/session_command.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_wrapper.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" |
| 33 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 34 | 34 |
| 35 using base::Time; | 35 using base::Time; |
| 36 using content::NavigationController; | 36 using content::NavigationController; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 (*tab_j).browser_id = delegate->GetSessionID().id(); | 415 (*tab_j).browser_id = delegate->GetSessionID().id(); |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 break; | 418 break; |
| 419 } | 419 } |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 delegate->ShowBrowserWindow(); | 422 delegate->ShowBrowserWindow(); |
| 423 | 423 |
| 424 if (disposition == CURRENT_TAB && current_delegate && | 424 if (disposition == CURRENT_TAB && current_delegate && |
| 425 current_delegate->GetSelectedWebContents()) { | 425 current_delegate->GetActiveWebContents()) { |
| 426 current_delegate->CloseTab(); | 426 current_delegate->CloseTab(); |
| 427 } | 427 } |
| 428 } else { | 428 } else { |
| 429 NOTREACHED(); | 429 NOTREACHED(); |
| 430 } | 430 } |
| 431 | 431 |
| 432 if (!restoring_tab_in_window) { | 432 if (!restoring_tab_in_window) { |
| 433 delete entry; | 433 delete entry; |
| 434 } | 434 } |
| 435 | 435 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 NavigationEntry* entry = (i == pending_index) ? | 529 NavigationEntry* entry = (i == pending_index) ? |
| 530 controller->GetPendingEntry() : controller->GetEntryAtIndex(i); | 530 controller->GetPendingEntry() : controller->GetEntryAtIndex(i); |
| 531 tab->navigations[i].SetFromNavigationEntry(*entry); | 531 tab->navigations[i].SetFromNavigationEntry(*entry); |
| 532 } | 532 } |
| 533 tab->timestamp = TimeNow(); | 533 tab->timestamp = TimeNow(); |
| 534 tab->current_navigation_index = controller->GetCurrentEntryIndex(); | 534 tab->current_navigation_index = controller->GetCurrentEntryIndex(); |
| 535 if (tab->current_navigation_index == -1 && entry_count > 0) | 535 if (tab->current_navigation_index == -1 && entry_count > 0) |
| 536 tab->current_navigation_index = 0; | 536 tab->current_navigation_index = 0; |
| 537 tab->tabstrip_index = index; | 537 tab->tabstrip_index = index; |
| 538 | 538 |
| 539 TabContentsWrapper* wrapper = | 539 TabContents* tab_contents = |
| 540 TabContentsWrapper::GetCurrentWrapperForContents( | 540 TabContents::FromWebContents(controller->GetWebContents()); |
| 541 controller->GetWebContents()); | 541 // tab_contents is NULL in some browser tests. |
| 542 // wrapper is NULL in some browser tests. | 542 if (tab_contents) { |
| 543 if (wrapper) { | |
| 544 const extensions::Extension* extension = | 543 const extensions::Extension* extension = |
| 545 wrapper->extension_tab_helper()->extension_app(); | 544 tab_contents->extension_tab_helper()->extension_app(); |
| 546 if (extension) | 545 if (extension) |
| 547 tab->extension_app_id = extension->id(); | 546 tab->extension_app_id = extension->id(); |
| 548 } | 547 } |
| 549 | 548 |
| 550 tab->session_storage_namespace = controller->GetSessionStorageNamespace(); | 549 tab->session_storage_namespace = controller->GetSessionStorageNamespace(); |
| 551 | 550 |
| 552 // Delegate may be NULL during unit tests. | 551 // Delegate may be NULL during unit tests. |
| 553 if (delegate) { | 552 if (delegate) { |
| 554 tab->browser_id = delegate->GetSessionID().id(); | 553 tab->browser_id = delegate->GetSessionID().id(); |
| 555 tab->pinned = delegate->IsTabPinned(tab->tabstrip_index); | 554 tab->pinned = delegate->IsTabPinned(tab->tabstrip_index); |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 // the front, not the end and we just added the entries to the end). | 1244 // the front, not the end and we just added the entries to the end). |
| 1246 entries_to_write_ = staging_entries_.size(); | 1245 entries_to_write_ = staging_entries_.size(); |
| 1247 | 1246 |
| 1248 PruneEntries(); | 1247 PruneEntries(); |
| 1249 NotifyTabsChanged(); | 1248 NotifyTabsChanged(); |
| 1250 } | 1249 } |
| 1251 | 1250 |
| 1252 Time TabRestoreService::TimeNow() const { | 1251 Time TabRestoreService::TimeNow() const { |
| 1253 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); | 1252 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); |
| 1254 } | 1253 } |
| OLD | NEW |