diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-04-05 17:15:33 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-04-11 07:47:18 +0000 |
commit | 7324afb043a0b1e623d8e8eb906cdc53bdeb4685 (patch) | |
tree | a3fe2d74ea9c9e142c390dac4ca0e219382ace46 /chromium/components/sessions | |
parent | 6a4cabb866f66d4128a97cdc6d9d08ce074f1247 (diff) | |
download | qtwebengine-chromium-7324afb043a0b1e623d8e8eb906cdc53bdeb4685.tar.gz |
BASELINE: Update Chromium to 58.0.3029.54
Change-Id: I67f57065a7afdc8e4614adb5c0230281428df4d1
Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'chromium/components/sessions')
9 files changed, 157 insertions, 31 deletions
diff --git a/chromium/components/sessions/content/content_serialized_navigation_driver.cc b/chromium/components/sessions/content/content_serialized_navigation_driver.cc index 7aa7de842ae..d9e4b1c7b21 100644 --- a/chromium/components/sessions/content/content_serialized_navigation_driver.cc +++ b/chromium/components/sessions/content/content_serialized_navigation_driver.cc @@ -7,6 +7,7 @@ #include "base/memory/singleton.h" #include "build/build_config.h" #include "components/sessions/core/serialized_navigation_entry.h" +#include "content/public/common/content_features.h" #include "content/public/common/page_state.h" #include "content/public/common/referrer.h" #include "content/public/common/url_constants.h" @@ -138,6 +139,27 @@ void ContentSerializedNavigationDriver::Sanitize( navigation->encoded_page_state_ = content::PageState::CreateFromURL( navigation->virtual_url_).ToEncodedData(); } + + if (base::FeatureList::IsEnabled(features::kNativeAndroidHistoryManager) && + navigation->virtual_url_.SchemeIs(content::kChromeUIScheme) && + (navigation->virtual_url_.host_piece() == content::kChromeUIHistoryHost || + navigation->virtual_url_.host_piece() == + content::kChromeUIHistoryFrameHost)) { + // Rewrite the old history Web UI to the new android native history. + navigation->virtual_url_ = GURL(content::kChromeUINativeHistoryURL); + navigation->original_request_url_ = navigation->virtual_url_; + navigation->encoded_page_state_ = content::PageState::CreateFromURL( + navigation->virtual_url_).ToEncodedData(); + } else if ( + !base::FeatureList::IsEnabled(features::kNativeAndroidHistoryManager) && + navigation->virtual_url_.SchemeIs(content::kChromeNativeUIScheme) && + navigation->virtual_url_.host_piece() == content::kChromeUIHistoryHost) { + // If the android native history UI has been disabled, redirect + // chrome-native://history to the old web UI. + navigation->virtual_url_ = GURL(content::kChromeUIHistoryURL); + navigation->original_request_url_ = navigation->virtual_url_; + navigation->encoded_page_state_ = std::string(); + } #endif // defined(OS_ANDROID) } diff --git a/chromium/components/sessions/core/base_session_service.h b/chromium/components/sessions/core/base_session_service.h index 473b75d6685..385948b8898 100644 --- a/chromium/components/sessions/core/base_session_service.h +++ b/chromium/components/sessions/core/base_session_service.h @@ -12,6 +12,7 @@ #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/task/cancelable_task_tracker.h" +#include "base/threading/sequenced_worker_pool.h" #include "components/sessions/core/sessions_export.h" #include "url/gurl.h" diff --git a/chromium/components/sessions/core/serialized_navigation_entry.cc b/chromium/components/sessions/core/serialized_navigation_entry.cc index 08685eb3602..ca686b0add4 100644 --- a/chromium/components/sessions/core/serialized_navigation_entry.cc +++ b/chromium/components/sessions/core/serialized_navigation_entry.cc @@ -8,6 +8,7 @@ #include "base/pickle.h" #include "base/strings/utf_string_conversions.h" +#include "base/trace_event/memory_usage_estimator.h" #include "components/sessions/core/serialized_navigation_driver.h" #include "components/sync/base/time.h" #include "components/sync/protocol/session_specifics.pb.h" @@ -500,4 +501,19 @@ sync_pb::TabNavigation SerializedNavigationEntry::ToSyncData() const { return sync_data; } +size_t SerializedNavigationEntry::EstimateMemoryUsage() const { + using base::trace_event::EstimateMemoryUsage; + return + EstimateMemoryUsage(referrer_url_) + + EstimateMemoryUsage(virtual_url_) + + EstimateMemoryUsage(title_) + + EstimateMemoryUsage(encoded_page_state_) + + EstimateMemoryUsage(original_request_url_) + + EstimateMemoryUsage(search_terms_) + + EstimateMemoryUsage(favicon_url_) + + EstimateMemoryUsage(redirect_chain_) + + EstimateMemoryUsage(content_pack_categories_) + + EstimateMemoryUsage(extended_info_map_); +} + } // namespace sessions diff --git a/chromium/components/sessions/core/serialized_navigation_entry.h b/chromium/components/sessions/core/serialized_navigation_entry.h index 8601c972027..3a8e665ff02 100644 --- a/chromium/components/sessions/core/serialized_navigation_entry.h +++ b/chromium/components/sessions/core/serialized_navigation_entry.h @@ -128,6 +128,8 @@ class SESSIONS_EXPORT SerializedNavigationEntry { return extended_info_map_; } + size_t EstimateMemoryUsage() const; + private: friend class ContentSerializedNavigationBuilder; friend class ContentSerializedNavigationDriver; @@ -139,6 +141,8 @@ class SESSIONS_EXPORT SerializedNavigationEntry { int index_; // Member variables corresponding to NavigationEntry fields. + // If you add a new field that can allocate memory, please also add + // it to the EstimatedMemoryUsage() implementation. int unique_id_; GURL referrer_url_; int referrer_policy_; diff --git a/chromium/components/sessions/core/session_backend.cc b/chromium/components/sessions/core/session_backend.cc index 43db0ae5c9c..be991f6e6b9 100644 --- a/chromium/components/sessions/core/session_backend.cc +++ b/chromium/components/sessions/core/session_backend.cc @@ -56,8 +56,7 @@ class SessionFileReader { } // Reads the contents of the file specified in the constructor, returning // true on success, and filling up |commands| with commands. - bool Read(sessions::BaseSessionService::SessionType type, - std::vector<std::unique_ptr<sessions::SessionCommand>>* commands); + bool Read(std::vector<std::unique_ptr<sessions::SessionCommand>>* commands); private: // Reads a single command, returning it. A return value of NULL indicates @@ -91,13 +90,11 @@ class SessionFileReader { }; bool SessionFileReader::Read( - sessions::BaseSessionService::SessionType type, std::vector<std::unique_ptr<sessions::SessionCommand>>* commands) { if (!file_->IsValid()) return false; FileHeader header; int read_count; - TimeTicks start_time = TimeTicks::Now(); read_count = file_->ReadAtCurrentPos(reinterpret_cast<char*>(&header), sizeof(header)); if (read_count != sizeof(header) || header.signature != kFileSignature || @@ -110,13 +107,6 @@ bool SessionFileReader::Read( read_commands.push_back(std::move(command)); if (!errored_) read_commands.swap(*commands); - if (type == sessions::BaseSessionService::TAB_RESTORE) { - UMA_HISTOGRAM_TIMES("TabRestore.read_session_file_time", - TimeTicks::Now() - start_time); - } else { - UMA_HISTOGRAM_TIMES("SessionRestore.read_session_file_time", - TimeTicks::Now() - start_time); - } return !errored_; } @@ -262,7 +252,7 @@ bool SessionBackend::ReadLastSessionCommandsImpl( std::vector<std::unique_ptr<sessions::SessionCommand>>* commands) { Init(); SessionFileReader file_reader(GetLastSessionPath()); - return file_reader.Read(type_, commands); + return file_reader.Read(commands); } void SessionBackend::DeleteLastSession() { @@ -278,19 +268,8 @@ void SessionBackend::MoveCurrentSessionToLastSession() { const base::FilePath last_session_path = GetLastSessionPath(); if (base::PathExists(last_session_path)) base::DeleteFile(last_session_path, false); - if (base::PathExists(current_session_path)) { - int64_t file_size; - if (base::GetFileSize(current_session_path, &file_size)) { - if (type_ == sessions::BaseSessionService::TAB_RESTORE) { - UMA_HISTOGRAM_COUNTS("TabRestore.last_session_file_size", - static_cast<int>(file_size / 1024)); - } else { - UMA_HISTOGRAM_COUNTS("SessionRestore.last_session_file_size", - static_cast<int>(file_size / 1024)); - } - } + if (base::PathExists(current_session_path)) last_session_valid_ = base::Move(current_session_path, last_session_path); - } if (base::PathExists(current_session_path)) base::DeleteFile(current_session_path, false); @@ -303,7 +282,7 @@ bool SessionBackend::ReadCurrentSessionCommandsImpl( std::vector<std::unique_ptr<sessions::SessionCommand>>* commands) { Init(); SessionFileReader file_reader(GetCurrentSessionPath()); - return file_reader.Read(type_, commands); + return file_reader.Read(commands); } bool SessionBackend::AppendCommandsToFile( @@ -313,10 +292,6 @@ bool SessionBackend::AppendCommandsToFile( int wrote; const size_type content_size = static_cast<size_type>((*i)->size()); const size_type total_size = content_size + sizeof(id_type); - if (type_ == sessions::BaseSessionService::TAB_RESTORE) - UMA_HISTOGRAM_COUNTS("TabRestore.command_size", total_size); - else - UMA_HISTOGRAM_COUNTS("SessionRestore.command_size", total_size); wrote = file->WriteAtCurrentPos(reinterpret_cast<const char*>(&total_size), sizeof(total_size)); if (wrote != sizeof(total_size)) { diff --git a/chromium/components/sessions/core/tab_restore_service.cc b/chromium/components/sessions/core/tab_restore_service.cc index 8bf31952e70..bd3183f447b 100644 --- a/chromium/components/sessions/core/tab_restore_service.cc +++ b/chromium/components/sessions/core/tab_restore_service.cc @@ -4,6 +4,8 @@ #include "components/sessions/core/tab_restore_service.h" +#include "base/trace_event/memory_usage_estimator.h" + namespace sessions { // TimeFactory----------------------------------------------------------------- @@ -18,12 +20,31 @@ static SessionID::id_type next_entry_id = 1; TabRestoreService::Entry::~Entry() = default; TabRestoreService::Entry::Entry(Type type) : id(next_entry_id++), type(type) {} +size_t TabRestoreService::Entry::EstimateMemoryUsage() const { + return 0; +} + TabRestoreService::Tab::Tab() : Entry(TAB) {} TabRestoreService::Tab::~Tab() = default; +size_t TabRestoreService::Tab::EstimateMemoryUsage() const { + using base::trace_event::EstimateMemoryUsage; + return + EstimateMemoryUsage(navigations) + + EstimateMemoryUsage(extension_app_id) + + EstimateMemoryUsage(user_agent_override); +} + TabRestoreService::Window::Window() : Entry(WINDOW) {} TabRestoreService::Window::~Window() = default; +size_t TabRestoreService::Window::EstimateMemoryUsage() const { + using base::trace_event::EstimateMemoryUsage; + return + EstimateMemoryUsage(tabs) + + EstimateMemoryUsage(app_name); +} + // TabRestoreService ---------------------------------------------------------- TabRestoreService::~TabRestoreService() { diff --git a/chromium/components/sessions/core/tab_restore_service.h b/chromium/components/sessions/core/tab_restore_service.h index a851f813e57..2746da2e6e8 100644 --- a/chromium/components/sessions/core/tab_restore_service.h +++ b/chromium/components/sessions/core/tab_restore_service.h @@ -69,6 +69,9 @@ class SESSIONS_EXPORT TabRestoreService : public KeyedService { // closed during this session. bool from_last_session = false; + // Estimates memory usage. By default returns 0. + virtual size_t EstimateMemoryUsage() const; + protected: explicit Entry(Type type); @@ -77,10 +80,15 @@ class SESSIONS_EXPORT TabRestoreService : public KeyedService { }; // Represents a previously open tab. + // If you add a new field that can allocate memory, please also add + // it to the EstimatedMemoryUsage() implementation. struct SESSIONS_EXPORT Tab : public Entry { Tab(); ~Tab() override; + // Entry: + size_t EstimateMemoryUsage() const override; + // The navigations. std::vector<SerializedNavigationEntry> navigations; @@ -108,10 +116,15 @@ class SESSIONS_EXPORT TabRestoreService : public KeyedService { }; // Represents a previously open window. + // If you add a new field that can allocate memory, please also add + // it to the EstimatedMemoryUsage() implementation. struct SESSIONS_EXPORT Window : public Entry { Window(); ~Window() override; + // Entry: + size_t EstimateMemoryUsage() const override; + // The tabs that comprised the window, in order. std::vector<std::unique_ptr<Tab>> tabs; diff --git a/chromium/components/sessions/core/tab_restore_service_helper.cc b/chromium/components/sessions/core/tab_restore_service_helper.cc index 841f07594df..c140cda055a 100644 --- a/chromium/components/sessions/core/tab_restore_service_helper.cc +++ b/chromium/components/sessions/core/tab_restore_service_helper.cc @@ -4,6 +4,7 @@ #include "components/sessions/core/tab_restore_service_helper.h" +#include <inttypes.h> #include <stddef.h> #include <algorithm> @@ -13,6 +14,11 @@ #include "base/memory/ptr_util.h" #include "base/metrics/histogram.h" #include "base/stl_util.h" +#include "base/strings/stringprintf.h" +#include "base/threading/thread_task_runner_handle.h" +#include "base/trace_event/memory_dump_manager.h" +#include "base/trace_event/memory_usage_estimator.h" +#include "base/trace_event/process_memory_dump.h" #include "components/sessions/core/live_tab.h" #include "components/sessions/core/live_tab_context.h" #include "components/sessions/core/serialized_navigation_entry.h" @@ -48,11 +54,17 @@ TabRestoreServiceHelper::TabRestoreServiceHelper( restoring_(false), time_factory_(time_factory) { DCHECK(tab_restore_service_); + base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( + this, + "TabRestoreServiceHelper", + base::ThreadTaskRunnerHandle::Get()); } TabRestoreServiceHelper::~TabRestoreServiceHelper() { for (auto& observer : observer_list_) observer.TabRestoreServiceDestroyed(tab_restore_service_); + base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( + this); } void TabRestoreServiceHelper::AddObserver( @@ -327,6 +339,62 @@ TabRestoreServiceHelper::GetEntryIteratorById(SessionID::id_type id) { return entries_.end(); } +bool TabRestoreServiceHelper::OnMemoryDump( + const base::trace_event::MemoryDumpArgs& args, + base::trace_event::ProcessMemoryDump* pmd) { + using base::trace_event::MemoryAllocatorDump; + + const char* system_allocator_name = + base::trace_event::MemoryDumpManager::GetInstance() + ->system_allocator_pool_name(); + + if (entries_.empty()) { + // Nothing to report + return true; + } + + std::string entries_dump_name = base::StringPrintf( + "tab_restore/service_helper_0x%" PRIXPTR "/entries", + reinterpret_cast<uintptr_t>(this)); + pmd->CreateAllocatorDump(entries_dump_name) + ->AddScalar(MemoryAllocatorDump::kNameObjectCount, + MemoryAllocatorDump::kUnitsObjects, + entries_.size()); + + for (const auto& entry : entries_) { + const char* type_string = ""; + switch (entry->type) { + case TabRestoreService::WINDOW: + type_string = "window"; + break; + case TabRestoreService::TAB: + type_string = "tab"; + break; + } + + std::string entry_dump_name = base::StringPrintf( + "%s/%s_0x%" PRIXPTR, + entries_dump_name.c_str(), + type_string, + reinterpret_cast<uintptr_t>(entry.get())); + auto* entry_dump = pmd->CreateAllocatorDump(entry_dump_name); + + entry_dump->AddScalar(MemoryAllocatorDump::kNameSize, + MemoryAllocatorDump::kUnitsBytes, + entry->EstimateMemoryUsage()); + + auto age = base::Time::Now() - entry->timestamp; + entry_dump->AddScalar("age", + MemoryAllocatorDump::kUnitsObjects, + age.InSeconds()); + + if (system_allocator_name) + pmd->AddSuballocation(entry_dump->guid(), system_allocator_name); + } + + return true; +} + // static bool TabRestoreServiceHelper::ValidateEntry(const Entry& entry) { switch (entry.type) { diff --git a/chromium/components/sessions/core/tab_restore_service_helper.h b/chromium/components/sessions/core/tab_restore_service_helper.h index 3568e559654..1d503b08cfe 100644 --- a/chromium/components/sessions/core/tab_restore_service_helper.h +++ b/chromium/components/sessions/core/tab_restore_service_helper.h @@ -11,6 +11,7 @@ #include "base/macros.h" #include "base/observer_list.h" #include "base/time/time.h" +#include "base/trace_event/memory_dump_provider.h" #include "components/sessions/core/session_id.h" #include "components/sessions/core/session_types.h" #include "components/sessions/core/sessions_export.h" @@ -27,7 +28,8 @@ class TimeFactory; // Helper class used to implement InMemoryTabRestoreService and // PersistentTabRestoreService. See tab_restore_service.h for method-level // comments. -class SESSIONS_EXPORT TabRestoreServiceHelper { +class SESSIONS_EXPORT TabRestoreServiceHelper + : public base::trace_event::MemoryDumpProvider { public: typedef TabRestoreService::Entries Entries; typedef TabRestoreService::Entry Entry; @@ -67,7 +69,7 @@ class SESSIONS_EXPORT TabRestoreServiceHelper { TabRestoreServiceClient* client, TimeFactory* time_factory); - ~TabRestoreServiceHelper(); + ~TabRestoreServiceHelper() override; // Helper methods used to implement TabRestoreService. void AddObserver(TabRestoreServiceObserver* observer); @@ -106,6 +108,10 @@ class SESSIONS_EXPORT TabRestoreServiceHelper { // resides is returned. Entries::iterator GetEntryIteratorById(SessionID::id_type id); + // From base::trace_event::MemoryDumpProvider + bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, + base::trace_event::ProcessMemoryDump* pmd) override; + // Calls either ValidateTab or ValidateWindow as appropriate. static bool ValidateEntry(const Entry& entry); |