| OLD | NEW |
| 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 <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // calls in here are safe because the session/window objects are going to | 63 // calls in here are safe because the session/window objects are going to |
| 64 // delete all their children when their destructors are invoked. | 64 // delete all their children when their destructors are invoked. |
| 65 void PushTab(size_t tabIndex, int windowIndex, Time timestamp) { | 65 void PushTab(size_t tabIndex, int windowIndex, Time timestamp) { |
| 66 // First add sessions/windows as necessary. | 66 // First add sessions/windows as necessary. |
| 67 while (tabIndex >= sessions_.size()) { | 67 while (tabIndex >= sessions_.size()) { |
| 68 sessions_.push_back(base::MakeUnique<SyncedSession>()); | 68 sessions_.push_back(base::MakeUnique<SyncedSession>()); |
| 69 } | 69 } |
| 70 if (sessions_[tabIndex]->windows.find(windowIndex) == | 70 if (sessions_[tabIndex]->windows.find(windowIndex) == |
| 71 sessions_[tabIndex]->windows.end()) { | 71 sessions_[tabIndex]->windows.end()) { |
| 72 sessions_[tabIndex]->windows[windowIndex] = | 72 sessions_[tabIndex]->windows[windowIndex] = |
| 73 base::MakeUnique<SessionWindow>(); | 73 base::MakeUnique<SyncedSessionWindow>(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 sessions_[tabIndex]->modified_time = | 76 sessions_[tabIndex]->modified_time = |
| 77 std::max(sessions_[tabIndex]->modified_time, timestamp); | 77 std::max(sessions_[tabIndex]->modified_time, timestamp); |
| 78 sessions_[tabIndex]->windows[windowIndex]->timestamp = std::max( | 78 sessions_[tabIndex]->windows[windowIndex]->wrapped_window.timestamp = |
| 79 sessions_[tabIndex]->windows[windowIndex]->timestamp, timestamp); | 79 std::max( |
| 80 sessions_[tabIndex]->windows[windowIndex]->tabs.push_back( | 80 sessions_[tabIndex]->windows[windowIndex]->wrapped_window.timestamp, |
| 81 timestamp); |
| 82 sessions_[tabIndex]->windows[windowIndex]->wrapped_window.tabs.push_back( |
| 81 base::MakeUnique<SessionTab>()); | 83 base::MakeUnique<SessionTab>()); |
| 82 sessions_[tabIndex]->windows[windowIndex]->tabs.back()->timestamp = | 84 sessions_[tabIndex] |
| 83 timestamp; | 85 ->windows[windowIndex] |
| 86 ->wrapped_window.tabs.back() |
| 87 ->timestamp = timestamp; |
| 84 } | 88 } |
| 85 | 89 |
| 86 // Removes the last tab at the given indexes. The idexes provided should be | 90 // Removes the last tab at the given indexes. The idexes provided should be |
| 87 // valid for existing data, this method does not check their validity. Windows | 91 // valid for existing data, this method does not check their validity. Windows |
| 88 // are not cleaned up/removed if they're left with 0 tabs. | 92 // are not cleaned up/removed if they're left with 0 tabs. |
| 89 void PopTab(size_t tabIndex, int windowIndex, Time timestamp) { | 93 void PopTab(size_t tabIndex, int windowIndex, Time timestamp) { |
| 90 sessions_[tabIndex]->modified_time = | 94 sessions_[tabIndex]->modified_time = |
| 91 std::max(sessions_[tabIndex]->modified_time, timestamp); | 95 std::max(sessions_[tabIndex]->modified_time, timestamp); |
| 92 sessions_[tabIndex]->windows[windowIndex]->timestamp = std::max( | 96 sessions_[tabIndex]->windows[windowIndex]->wrapped_window.timestamp = |
| 93 sessions_[tabIndex]->windows[windowIndex]->timestamp, timestamp); | 97 std::max( |
| 94 sessions_[tabIndex]->windows[windowIndex]->tabs.pop_back(); | 98 sessions_[tabIndex]->windows[windowIndex]->wrapped_window.timestamp, |
| 99 timestamp); |
| 100 sessions_[tabIndex]->windows[windowIndex]->wrapped_window.tabs.pop_back(); |
| 95 } | 101 } |
| 96 | 102 |
| 97 // Runs MaxTabTimestamp on the current sessions data. | 103 // Runs MaxTabTimestamp on the current sessions data. |
| 98 Time MaxTabTimestamp() { | 104 Time MaxTabTimestamp() { |
| 99 std::vector<const SyncedSession*> typed_sessions; | 105 std::vector<const SyncedSession*> typed_sessions; |
| 100 for (auto& session : sessions_) { | 106 for (auto& session : sessions_) { |
| 101 typed_sessions.push_back(session.get()); | 107 typed_sessions.push_back(session.get()); |
| 102 } | 108 } |
| 103 return SyncSessionsMetrics::MaxTabTimestamp(typed_sessions); | 109 return SyncSessionsMetrics::MaxTabTimestamp(typed_sessions); |
| 104 } | 110 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 201 |
| 196 TEST_F(SyncSessionsMetricsTest, EmitNormalCase) { | 202 TEST_F(SyncSessionsMetricsTest, EmitNormalCase) { |
| 197 base::HistogramTester histogram_tester; | 203 base::HistogramTester histogram_tester; |
| 198 PushTab(0, 0, Time::Now() - TimeDelta::FromHours(1)); | 204 PushTab(0, 0, Time::Now() - TimeDelta::FromHours(1)); |
| 199 SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( | 205 SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( |
| 200 get_sessions_sync_manager()); | 206 get_sessions_sync_manager()); |
| 201 histogram_tester.ExpectTotalCount("Sync.YoungestForeignTabAgeOnNTP", 1); | 207 histogram_tester.ExpectTotalCount("Sync.YoungestForeignTabAgeOnNTP", 1); |
| 202 } | 208 } |
| 203 | 209 |
| 204 } // namespace sync_sessions | 210 } // namespace sync_sessions |
| OLD | NEW |