Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: components/sync_sessions/sync_sessions_metrics.cc

Issue 2343463003: [Sync] Fix namespaces for the sync_sessions component. (Closed)
Patch Set: Fix gn. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/sync_sessions/sync_sessions_metrics.h" 5 #include "components/sync_sessions/sync_sessions_metrics.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/metrics/user_metrics.h" 12 #include "base/metrics/user_metrics.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "components/sessions/core/session_types.h" 14 #include "components/sessions/core/session_types.h"
15 #include "components/sync_sessions/sessions_sync_manager.h" 15 #include "components/sync_sessions/sessions_sync_manager.h"
16 #include "components/sync_sessions/synced_session.h" 16 #include "components/sync_sessions/synced_session.h"
17 17
18 namespace sync_sessions { 18 namespace sync_sessions {
19 19
20 // static 20 // static
21 void SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( 21 void SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP(
22 browser_sync::SessionsSyncManager* sessions_sync_manager) { 22 SessionsSyncManager* sessions_sync_manager) {
23 if (sessions_sync_manager != NULL) { 23 if (sessions_sync_manager != NULL) {
24 std::vector<const sync_driver::SyncedSession*> foreign_sessions; 24 std::vector<const SyncedSession*> foreign_sessions;
25 sessions_sync_manager->GetAllForeignSessions(&foreign_sessions); 25 sessions_sync_manager->GetAllForeignSessions(&foreign_sessions);
26 base::Time best(MaxTabTimestamp(foreign_sessions)); 26 base::Time best(MaxTabTimestamp(foreign_sessions));
27 base::Time now(base::Time::Now()); 27 base::Time now(base::Time::Now());
28 // Don't emit metrics if the foreign tab is timestamped in the future. While 28 // Don't emit metrics if the foreign tab is timestamped in the future. While
29 // the timestamp is set on a different machine, and we may lose some 29 // the timestamp is set on a different machine, and we may lose some
30 // fraction of metrics to clock skew, we don't want the potential to have 30 // fraction of metrics to clock skew, we don't want the potential to have
31 // bad machines with clocks many hours off causing lots of seemingly 0 31 // bad machines with clocks many hours off causing lots of seemingly 0
32 // second entries. 32 // second entries.
33 if (base::Time::UnixEpoch() < best && best <= now) { 33 if (base::Time::UnixEpoch() < best && best <= now) {
34 UMA_HISTOGRAM_CUSTOM_COUNTS( 34 UMA_HISTOGRAM_CUSTOM_COUNTS(
35 "Sync.YoungestForeignTabAgeOnNTP", (now - best).InSeconds(), 1, 35 "Sync.YoungestForeignTabAgeOnNTP", (now - best).InSeconds(), 1,
36 base::TimeDelta::FromDays(14).InSeconds(), 100); 36 base::TimeDelta::FromDays(14).InSeconds(), 100);
37 } 37 }
38 } 38 }
39 } 39 }
40 40
41 // static 41 // static
42 base::Time SyncSessionsMetrics::MaxTabTimestamp( 42 base::Time SyncSessionsMetrics::MaxTabTimestamp(
43 const std::vector<const sync_driver::SyncedSession*>& sessions) { 43 const std::vector<const SyncedSession*>& sessions) {
44 // While Sessions are ordered by recency, windows and tabs are not. Because 44 // While Sessions are ordered by recency, windows and tabs are not. Because
45 // the timestamp of sessions are updated when windows/tabs are removed, we 45 // the timestamp of sessions are updated when windows/tabs are removed, we
46 // only need to search until all the remaining sessions are older than the 46 // only need to search until all the remaining sessions are older than the
47 // most recent tab we've found so far. 47 // most recent tab we've found so far.
48 base::Time best(base::Time::UnixEpoch()); 48 base::Time best(base::Time::UnixEpoch());
49 for (const sync_driver::SyncedSession* session : sessions) { 49 for (const SyncedSession* session : sessions) {
50 if (session->modified_time < best) { 50 if (session->modified_time < best) {
51 break; 51 break;
52 } 52 }
53 for (const std::pair<const SessionID::id_type, sessions::SessionWindow*>& 53 for (const std::pair<const SessionID::id_type, sessions::SessionWindow*>&
54 key_value : session->windows) { 54 key_value : session->windows) {
55 for (const sessions::SessionTab* tab : key_value.second->tabs) { 55 for (const sessions::SessionTab* tab : key_value.second->tabs) {
56 best = std::max(best, tab->timestamp); 56 best = std::max(best, tab->timestamp);
57 } 57 }
58 } 58 }
59 } 59 }
60 return best; 60 return best;
61 } 61 }
62 62
63 } // namespace sync_sessions 63 } // namespace sync_sessions
OLDNEW
« no previous file with comments | « components/sync_sessions/sync_sessions_metrics.h ('k') | components/sync_sessions/sync_sessions_metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698