| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/sessions/core/tab_restore_service_helper.h" | 5 #include "components/sessions/core/tab_restore_service_helper.h" |
| 6 | 6 |
| 7 #include <inttypes.h> |
| 7 #include <stddef.h> | 8 #include <stddef.h> |
| 8 | 9 |
| 9 #include <algorithm> | 10 #include <algorithm> |
| 10 #include <iterator> | 11 #include <iterator> |
| 11 | 12 |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/trace_event/estimate_memory_usage.h" |
| 19 #include "base/trace_event/memory_dump_manager.h" |
| 20 #include "base/trace_event/process_memory_dump.h" |
| 16 #include "components/sessions/core/live_tab.h" | 21 #include "components/sessions/core/live_tab.h" |
| 17 #include "components/sessions/core/live_tab_context.h" | 22 #include "components/sessions/core/live_tab_context.h" |
| 18 #include "components/sessions/core/serialized_navigation_entry.h" | 23 #include "components/sessions/core/serialized_navigation_entry.h" |
| 19 #include "components/sessions/core/session_types.h" | 24 #include "components/sessions/core/session_types.h" |
| 20 #include "components/sessions/core/tab_restore_service_client.h" | 25 #include "components/sessions/core/tab_restore_service_client.h" |
| 21 #include "components/sessions/core/tab_restore_service_observer.h" | 26 #include "components/sessions/core/tab_restore_service_observer.h" |
| 22 | 27 |
| 23 namespace sessions { | 28 namespace sessions { |
| 24 | 29 |
| 25 // TabRestoreServiceHelper::Observer ------------------------------------------- | 30 // TabRestoreServiceHelper::Observer ------------------------------------------- |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 for (const auto& tab : window.tabs) { | 325 for (const auto& tab : window.tabs) { |
| 321 if (tab->id == id) { | 326 if (tab->id == id) { |
| 322 return i; | 327 return i; |
| 323 } | 328 } |
| 324 } | 329 } |
| 325 } | 330 } |
| 326 } | 331 } |
| 327 return entries_.end(); | 332 return entries_.end(); |
| 328 } | 333 } |
| 329 | 334 |
| 335 bool TabRestoreServiceHelper::OnMemoryDump( |
| 336 const base::trace_event::MemoryDumpArgs& args, |
| 337 base::trace_event::ProcessMemoryDump* pmd) { |
| 338 using base::trace_event::EstimateMemoryUsage; |
| 339 size_t memory_usage = EstimateMemoryUsage(entries_); |
| 340 |
| 341 std::string dump_name = base::StringPrintf( |
| 342 "tab_restore/0x%" PRIXPTR, reinterpret_cast<uintptr_t>(this)); |
| 343 auto* dump = pmd->CreateAllocatorDump(dump_name); |
| 344 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 345 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 346 memory_usage); |
| 347 const char* system_allocator_name = |
| 348 base::trace_event::MemoryDumpManager::GetInstance() |
| 349 ->system_allocator_pool_name(); |
| 350 if (system_allocator_name) { |
| 351 pmd->AddSuballocation(dump->guid(), system_allocator_name); |
| 352 } |
| 353 |
| 354 return true; |
| 355 } |
| 356 |
| 330 // static | 357 // static |
| 331 bool TabRestoreServiceHelper::ValidateEntry(const Entry& entry) { | 358 bool TabRestoreServiceHelper::ValidateEntry(const Entry& entry) { |
| 332 switch (entry.type) { | 359 switch (entry.type) { |
| 333 case TabRestoreService::TAB: | 360 case TabRestoreService::TAB: |
| 334 return ValidateTab(static_cast<const Tab&>(entry)); | 361 return ValidateTab(static_cast<const Tab&>(entry)); |
| 335 case TabRestoreService::WINDOW: | 362 case TabRestoreService::WINDOW: |
| 336 return ValidateWindow(static_cast<const Window&>(entry)); | 363 return ValidateWindow(static_cast<const Window&>(entry)); |
| 337 } | 364 } |
| 338 NOTREACHED(); | 365 NOTREACHED(); |
| 339 return false; | 366 return false; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 tab.browser_id = new_id; | 515 tab.browser_id = new_id; |
| 489 } | 516 } |
| 490 } | 517 } |
| 491 } | 518 } |
| 492 | 519 |
| 493 base::Time TabRestoreServiceHelper::TimeNow() const { | 520 base::Time TabRestoreServiceHelper::TimeNow() const { |
| 494 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now(); | 521 return time_factory_ ? time_factory_->TimeNow() : base::Time::Now(); |
| 495 } | 522 } |
| 496 | 523 |
| 497 } // namespace sessions | 524 } // namespace sessions |
| OLD | NEW |