File: sync_sessions_metrics.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (62 lines) | stat: -rw-r--r-- 2,311 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/sync_sessions/sync_sessions_metrics.h"

#include <algorithm>
#include <utility>

#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/time/time.h"
#include "components/sessions/core/session_types.h"
#include "components/sync_sessions/sessions_sync_manager.h"
#include "components/sync_sessions/synced_session.h"

namespace sync_sessions {

// static
void SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP(
    SessionsSyncManager* sessions_sync_manager) {
  if (sessions_sync_manager != nullptr) {
    std::vector<const SyncedSession*> foreign_sessions;
    sessions_sync_manager->GetAllForeignSessions(&foreign_sessions);
    base::Time best(MaxTabTimestamp(foreign_sessions));
    base::Time now(base::Time::Now());
    // Don't emit metrics if the foreign tab is timestamped in the future. While
    // the timestamp is set on a different machine, and we may lose some
    // fraction of metrics to clock skew, we don't want the potential to have
    // bad machines with clocks many hours off causing lots of seemingly 0
    // second entries.
    if (base::Time::UnixEpoch() < best && best <= now) {
      UMA_HISTOGRAM_CUSTOM_COUNTS(
          "Sync.YoungestForeignTabAgeOnNTP", (now - best).InSeconds(), 1,
          base::TimeDelta::FromDays(14).InSeconds(), 100);
    }
  }
}

// static
base::Time SyncSessionsMetrics::MaxTabTimestamp(
    const std::vector<const SyncedSession*>& sessions) {
  // While Sessions are ordered by recency, windows and tabs are not. Because
  // the timestamp of sessions are updated when windows/tabs are removed, we
  // only need to search until all the remaining sessions are older than the
  // most recent tab we've found so far.
  base::Time best(base::Time::UnixEpoch());
  for (const SyncedSession* session : sessions) {
    if (session->modified_time < best) {
      break;
    }
    for (const auto& key_value : session->windows) {
      for (const auto& tab : key_value.second->tabs) {
        best = std::max(best, tab->timestamp);
      }
    }
  }
  return best;
}

}  // namespace sync_sessions