Commit 26fa7eb6 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Log UMA for session restoration time.

Bug: 877671
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I1ab57a336a1cccd169f311c1d64db813cd4a1250
Reviewed-on: https://chromium-review.googlesource.com/1232615
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592994}
parent 0c0a2f90
......@@ -20,12 +20,20 @@
@class WKBackForwardListItem;
namespace base {
class ElapsedTimer;
}
namespace web {
class BrowserState;
class NavigationItem;
struct Referrer;
class SessionStorageBuilder;
// Name of UMA histogram to log the time spent on asynchronous session
// restoration.
extern const char kRestoreNavigationTime[];
// WKBackForwardList based implementation of NavigationManagerImpl.
// This class relies on the following WKWebView APIs, defined by the
// CRWWebViewNavigationProxy protocol:
......@@ -243,6 +251,11 @@ class WKBasedNavigationManagerImpl : public NavigationManagerImpl {
// OnNavigationItemCommitted() callback.
bool is_restore_session_in_progress_ = false;
// Non null during the session restoration. Created when session restoration
// is started and reset when the restoration is finished. Used to log UMA
// histogram that measures session restoration time.
std::unique_ptr<base::ElapsedTimer> restoration_timer_;
// The active navigation entry in the restored session. GetVisibleItem()
// returns this item when |is_restore_session_in_progress_| is true so that
// clients of this navigation manager gets sane values for visible title and
......
......@@ -10,8 +10,10 @@
#include "base/logging.h"
#include "base/mac/bundle_locations.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/timer/elapsed_timer.h"
#import "ios/web/navigation/crw_navigation_item_holder.h"
#import "ios/web/navigation/navigation_item_impl.h"
#include "ios/web/navigation/navigation_item_impl_list.h"
......@@ -57,6 +59,8 @@ bool IsSameOrPlaceholderOf(const GURL& url1, const GURL& url2) {
namespace web {
const char kRestoreNavigationTime[] = "IOS.RestoreNavigationTime";
WKBasedNavigationManagerImpl::WKBasedNavigationManagerImpl()
: pending_item_index_(-1),
previous_item_index_(-1),
......@@ -88,9 +92,13 @@ void WKBasedNavigationManagerImpl::OnNavigationItemCommitted() {
details.item = GetLastCommittedItem();
DCHECK(details.item);
if (!wk_navigation_util::IsRestoreSessionUrl(details.item->GetURL())) {
if (!wk_navigation_util::IsRestoreSessionUrl(details.item->GetURL()) &&
is_restore_session_in_progress_) {
is_restore_session_in_progress_ = false;
restored_visible_item_.reset();
UMA_HISTOGRAM_TIMES(kRestoreNavigationTime, restoration_timer_->Elapsed());
restoration_timer_.reset();
}
details.previous_item_index = GetPreviousItemIndex();
......@@ -445,6 +453,7 @@ bool WKBasedNavigationManagerImpl::CanPruneAllButLastCommittedItem() const {
void WKBasedNavigationManagerImpl::Restore(
int last_committed_item_index,
std::vector<std::unique_ptr<NavigationItem>> items) {
DCHECK(!is_restore_session_in_progress_);
WillRestore(items.size());
DCHECK_LT(last_committed_item_index, static_cast<int>(items.size()));
......@@ -490,6 +499,7 @@ void WKBasedNavigationManagerImpl::Restore(
// committed item, because a restored session has no pending or transient
// item.
is_restore_session_in_progress_ = true;
restoration_timer_ = std::make_unique<base::ElapsedTimer>();
if (last_committed_item_index > -1)
restored_visible_item_ = std::move(items[last_committed_item_index]);
......
......@@ -14,6 +14,7 @@
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#import "ios/web/navigation/navigation_manager_impl.h"
#import "ios/web/navigation/wk_based_navigation_manager_impl.h"
#import "ios/web/navigation/wk_navigation_util.h"
#import "ios/web/public/crw_navigation_item_storage.h"
#import "ios/web/public/crw_session_storage.h"
......@@ -391,6 +392,9 @@ TEST_P(WebStateTest, RestoreLargeSession) {
histogram_tester_.ExpectTotalCount(kRestoreNavigationItemCount, 1);
histogram_tester_.ExpectBucketCount(kRestoreNavigationItemCount, 100, 1);
if (web::GetWebClient()->IsSlimNavigationManagerEnabled()) {
histogram_tester_.ExpectTotalCount(kRestoreNavigationTime, 1);
}
}
// Tests that if a saved session is provided when creating a new WebState, it is
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment