From 041ef9c96d9a5b6f206a24385b0e6e4b3dbf9f20 Mon Sep 17 00:00:00 2001 From: georgesak Date: Thu, 14 May 2015 20:01:50 -0700 Subject: Change WebContents::last_active_time_ to Time instead of Timeticks. For context, last_active_time_ is going to be used by session restore to order the loading of background tabs using MRU. In order for this to be robust, last_active_time_ must be saved and restore between sessions. Timeticks cannot be reliably restored as it's dependent on the current OS session. MRU code for session restore is being implemented in https://codereview.chromium.org/1131373003 Notes: - In dev tools, replaced "activity" with "active" for consistency - In OomPriorityManagerTest.Comparator, initialized last_active_time for all tabs, as this is necessary with Time (a default TimeTicks can go back in time, not the case with Time). BUG=472772 Review URL: https://codereview.chromium.org/1140083004 Cr-Commit-Position: refs/heads/master@{#330029} --- chrome/browser/android/dev_tools_discovery_provider_android.cc | 9 +++------ chrome/browser/chromeos/memory/oom_priority_manager.h | 2 +- chrome/browser/chromeos/memory/oom_priority_manager_unittest.cc | 7 ++++++- components/devtools_discovery/basic_target_descriptor.cc | 6 +++--- components/devtools_discovery/basic_target_descriptor.h | 4 ++-- components/devtools_discovery/devtools_target_descriptor.h | 2 +- components/devtools_http_handler/devtools_http_handler.cc | 2 +- content/browser/web_contents/web_contents_impl.cc | 6 +++--- content/browser/web_contents/web_contents_impl.h | 4 ++-- content/browser/web_contents/web_contents_impl_unittest.cc | 2 +- content/public/browser/web_contents.h | 4 ++-- 11 files changed, 25 insertions(+), 23 deletions(-) diff --git a/chrome/browser/android/dev_tools_discovery_provider_android.cc b/chrome/browser/android/dev_tools_discovery_provider_android.cc index 08d3e55..5a2eb32 100644 --- a/chrome/browser/android/dev_tools_discovery_provider_android.cc +++ b/chrome/browser/android/dev_tools_discovery_provider_android.cc @@ -65,9 +65,7 @@ class TabDescriptor : public devtools_discovery::DevToolsTargetDescriptor { return favicon_url_; } - base::TimeTicks GetLastActivityTime() const override { - return last_activity_time_; - } + base::Time GetLastActiveTime() const override { return last_active_time_; } std::string GetId() const override { return base::IntToString(tab_id_); @@ -134,8 +132,7 @@ class TabDescriptor : public devtools_discovery::DevToolsTargetDescriptor { title_(base::UTF16ToUTF8(web_contents->GetTitle())), url_(web_contents->GetURL()), favicon_url_(CalculateFaviconURL()), - last_activity_time_(web_contents->GetLastActiveTime()) { - } + last_active_time_(web_contents->GetLastActiveTime()) {} TabDescriptor(int tab_id, const base::string16& title, const GURL& url) : tab_id_(tab_id), @@ -191,7 +188,7 @@ class TabDescriptor : public devtools_discovery::DevToolsTargetDescriptor { const std::string title_; const GURL url_; const GURL favicon_url_; - const base::TimeTicks last_activity_time_; + const base::Time last_active_time_; DISALLOW_COPY_AND_ASSIGN(TabDescriptor); }; diff --git a/chrome/browser/chromeos/memory/oom_priority_manager.h b/chrome/browser/chromeos/memory/oom_priority_manager.h index b0165f4..6be408b 100644 --- a/chrome/browser/chromeos/memory/oom_priority_manager.h +++ b/chrome/browser/chromeos/memory/oom_priority_manager.h @@ -79,7 +79,7 @@ class OomPriorityManager : public content::NotificationObserver { bool is_pinned; bool is_selected; // selected in the currently active browser window bool is_discarded; - base::TimeTicks last_active; + base::Time last_active; base::ProcessHandle renderer_handle; int child_process_host_id; base::string16 title; diff --git a/chrome/browser/chromeos/memory/oom_priority_manager_unittest.cc b/chrome/browser/chromeos/memory/oom_priority_manager_unittest.cc index 9280b9f..6c2e672 100644 --- a/chrome/browser/chromeos/memory/oom_priority_manager_unittest.cc +++ b/chrome/browser/chromeos/memory/oom_priority_manager_unittest.cc @@ -35,12 +35,13 @@ enum TestIndicies { // desired order. TEST_F(OomPriorityManagerTest, Comparator) { chromeos::OomPriorityManager::TabStatsList test_list; - const base::TimeTicks now = base::TimeTicks::Now(); + const base::Time now = base::Time::Now(); // Add kSelected last to verify we are sorting the array. { OomPriorityManager::TabStats stats; + stats.last_active = now; stats.is_pinned = true; stats.renderer_handle = kPinned; stats.child_process_host_id = kPinned; @@ -49,6 +50,7 @@ TEST_F(OomPriorityManagerTest, Comparator) { { OomPriorityManager::TabStats stats; + stats.last_active = now; stats.is_app = true; stats.renderer_handle = kApp; stats.child_process_host_id = kApp; @@ -57,6 +59,7 @@ TEST_F(OomPriorityManagerTest, Comparator) { { OomPriorityManager::TabStats stats; + stats.last_active = now; stats.is_playing_audio = true; stats.renderer_handle = kPlayingAudio; stats.child_process_host_id = kPlayingAudio; @@ -98,6 +101,7 @@ TEST_F(OomPriorityManagerTest, Comparator) { { OomPriorityManager::TabStats stats; + stats.last_active = now; stats.is_reloadable_ui = true; stats.renderer_handle = kReloadableUI; stats.child_process_host_id = kReloadableUI; @@ -108,6 +112,7 @@ TEST_F(OomPriorityManagerTest, Comparator) { // we are actually sorting the array. { OomPriorityManager::TabStats stats; + stats.last_active = now; stats.is_selected = true; stats.renderer_handle = kSelected; stats.child_process_host_id = kSelected; diff --git a/components/devtools_discovery/basic_target_descriptor.cc b/components/devtools_discovery/basic_target_descriptor.cc index d8d2f83..e425b8b 100644 --- a/components/devtools_discovery/basic_target_descriptor.cc +++ b/components/devtools_discovery/basic_target_descriptor.cc @@ -47,7 +47,7 @@ BasicTargetDescriptor::BasicTargetDescriptor( content::NavigationEntry* entry = controller.GetActiveEntry(); if (entry != NULL && entry->GetURL().is_valid()) favicon_url_ = entry->GetFavicon().url; - last_activity_time_ = web_contents->GetLastActiveTime(); + last_active_time_ = web_contents->GetLastActiveTime(); } } @@ -82,8 +82,8 @@ GURL BasicTargetDescriptor::GetFaviconURL() const { return favicon_url_; } -base::TimeTicks BasicTargetDescriptor::GetLastActivityTime() const { - return last_activity_time_; +base::Time BasicTargetDescriptor::GetLastActiveTime() const { + return last_active_time_; } bool BasicTargetDescriptor::IsAttached() const { diff --git a/components/devtools_discovery/basic_target_descriptor.h b/components/devtools_discovery/basic_target_descriptor.h index a3b834a..6161839 100644 --- a/components/devtools_discovery/basic_target_descriptor.h +++ b/components/devtools_discovery/basic_target_descriptor.h @@ -28,7 +28,7 @@ class BasicTargetDescriptor : public DevToolsTargetDescriptor { std::string GetDescription() const override; GURL GetURL() const override; GURL GetFaviconURL() const override; - base::TimeTicks GetLastActivityTime() const override; + base::Time GetLastActiveTime() const override; bool IsAttached() const override; scoped_refptr GetAgentHost() const override; bool Activate() const override; @@ -50,7 +50,7 @@ class BasicTargetDescriptor : public DevToolsTargetDescriptor { std::string description_; GURL url_; GURL favicon_url_; - base::TimeTicks last_activity_time_; + base::Time last_active_time_; }; } // namespace devtools_discovery diff --git a/components/devtools_discovery/devtools_target_descriptor.h b/components/devtools_discovery/devtools_target_descriptor.h index 9b3200d..995453e 100644 --- a/components/devtools_discovery/devtools_target_descriptor.h +++ b/components/devtools_discovery/devtools_target_descriptor.h @@ -50,7 +50,7 @@ class DevToolsTargetDescriptor { virtual GURL GetFaviconURL() const = 0; // Returns the time when the target was last active. - virtual base::TimeTicks GetLastActivityTime() const = 0; + virtual base::Time GetLastActiveTime() const = 0; // Returns true if the debugger is attached to the target. virtual bool IsAttached() const = 0; diff --git a/components/devtools_http_handler/devtools_http_handler.cc b/components/devtools_http_handler/devtools_http_handler.cc index 2a72d06..3c9a8e7 100644 --- a/components/devtools_http_handler/devtools_http_handler.cc +++ b/components/devtools_http_handler/devtools_http_handler.cc @@ -320,7 +320,7 @@ class DevToolsAgentHostClientImpl : public DevToolsAgentHostClient { static bool TimeComparator(const DevToolsTargetDescriptor* desc1, const DevToolsTargetDescriptor* desc2) { - return desc1->GetLastActivityTime() > desc2->GetLastActivityTime(); + return desc1->GetLastActiveTime() > desc2->GetLastActiveTime(); } // DevToolsHttpHandler::ServerSocketFactory ---------------------------------- diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index abf7e4b..269b471 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -321,7 +321,7 @@ WebContentsImpl::WebContentsImpl(BrowserContext* browser_context, notify_disconnection_(false), dialog_manager_(NULL), is_showing_before_unload_dialog_(false), - last_active_time_(base::TimeTicks::Now()), + last_active_time_(base::Time::Now()), closed_by_user_gesture_(false), minimum_zoom_percent_(static_cast(kMinimumZoomFactor * 100)), maximum_zoom_percent_(static_cast(kMaximumZoomFactor * 100)), @@ -1053,7 +1053,7 @@ void WebContentsImpl::NotifyNavigationStateChanged( delegate_->NavigationStateChanged(this, changed_flags); } -base::TimeTicks WebContentsImpl::GetLastActiveTime() const { +base::Time WebContentsImpl::GetLastActiveTime() const { return last_active_time_; } @@ -1069,7 +1069,7 @@ void WebContentsImpl::WasShown() { } } - last_active_time_ = base::TimeTicks::Now(); + last_active_time_ = base::Time::Now(); // The resize rect might have changed while this was inactive -- send the new // one to make sure it's up to date. diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index e5e473e..0004d0b 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -275,7 +275,7 @@ class CONTENT_EXPORT WebContentsImpl base::TerminationStatus GetCrashedStatus() const override; bool IsBeingDestroyed() const override; void NotifyNavigationStateChanged(InvalidateTypes changed_flags) override; - base::TimeTicks GetLastActiveTime() const override; + base::Time GetLastActiveTime() const override; void WasShown() override; void WasHidden() override; bool NeedToFireBeforeUnload() override; @@ -1149,7 +1149,7 @@ class CONTENT_EXPORT WebContentsImpl // The time that this WebContents was last made active. The initial value is // the WebContents creation time. - base::TimeTicks last_active_time_; + base::Time last_active_time_; // See description above setter. bool closed_by_user_gesture_; diff --git a/content/browser/web_contents/web_contents_impl_unittest.cc b/content/browser/web_contents/web_contents_impl_unittest.cc index 6a3f6e0..0557e94 100644 --- a/content/browser/web_contents/web_contents_impl_unittest.cc +++ b/content/browser/web_contents/web_contents_impl_unittest.cc @@ -2570,7 +2570,7 @@ TEST_F(WebContentsImplTest, GetLastActiveTime) { EXPECT_FALSE(contents()->GetLastActiveTime().is_null()); // Reset the last active time to a known-bad value. - contents()->last_active_time_ = base::TimeTicks(); + contents()->last_active_time_ = base::Time(); ASSERT_TRUE(contents()->GetLastActiveTime().is_null()); // Simulate activating the WebContents. The active time should update. diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index 62f09a8..d5ed42f 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -32,7 +32,7 @@ namespace base { class DictionaryValue; -class TimeTicks; +class Time; } namespace blink { @@ -353,7 +353,7 @@ class WebContents : public PageNavigator, // Get the last time that the WebContents was made active (either when it was // created or shown with WasShown()). - virtual base::TimeTicks GetLastActiveTime() const = 0; + virtual base::Time GetLastActiveTime() const = 0; // Invoked when the WebContents becomes shown/hidden. virtual void WasShown() = 0; -- cgit v1.1