OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/webui/foreign_session_handler.h" | 5 #include "chrome/browser/ui/webui/foreign_session_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/i18n/time_formatting.h" | 13 #include "base/i18n/time_formatting.h" |
14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/metrics/histogram_macros.h" |
15 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
16 #include "base/prefs/scoped_user_pref_update.h" | 17 #include "base/prefs/scoped_user_pref_update.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/time/time.h" |
19 #include "base/values.h" | 21 #include "base/values.h" |
20 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
21 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/sessions/session_restore.h" | 24 #include "chrome/browser/sessions/session_restore.h" |
23 #include "chrome/browser/sync/profile_sync_service.h" | 25 #include "chrome/browser/sync/profile_sync_service.h" |
24 #include "chrome/browser/sync/profile_sync_service_factory.h" | 26 #include "chrome/browser/sync/profile_sync_service_factory.h" |
25 #include "chrome/browser/ui/host_desktop.h" | 27 #include "chrome/browser/ui/host_desktop.h" |
26 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 28 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
27 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
(...skipping 17 matching lines...) Expand all Loading... |
46 | 48 |
47 // Comparator function for use with std::sort that will sort sessions by | 49 // Comparator function for use with std::sort that will sort sessions by |
48 // descending modified_time (i.e., most recent first). | 50 // descending modified_time (i.e., most recent first). |
49 bool SortSessionsByRecency(const SyncedSession* s1, const SyncedSession* s2) { | 51 bool SortSessionsByRecency(const SyncedSession* s1, const SyncedSession* s2) { |
50 return s1->modified_time > s2->modified_time; | 52 return s1->modified_time > s2->modified_time; |
51 } | 53 } |
52 | 54 |
53 } // namepace | 55 } // namepace |
54 | 56 |
55 ForeignSessionHandler::ForeignSessionHandler() { | 57 ForeignSessionHandler::ForeignSessionHandler() { |
| 58 load_attempt_time_ = base::TimeTicks::Now(); |
56 } | 59 } |
57 | 60 |
58 // static | 61 // static |
59 void ForeignSessionHandler::RegisterProfilePrefs( | 62 void ForeignSessionHandler::RegisterProfilePrefs( |
60 user_prefs::PrefRegistrySyncable* registry) { | 63 user_prefs::PrefRegistrySyncable* registry) { |
61 registry->RegisterDictionaryPref(prefs::kNtpCollapsedForeignSessions); | 64 registry->RegisterDictionaryPref(prefs::kNtpCollapsedForeignSessions); |
62 } | 65 } |
63 | 66 |
64 // static | 67 // static |
65 void ForeignSessionHandler::OpenForeignSessionTab( | 68 void ForeignSessionHandler::OpenForeignSessionTab( |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 now < time ? base::TimeDelta() : now - time); | 221 now < time ? base::TimeDelta() : now - time); |
219 } | 222 } |
220 | 223 |
221 void ForeignSessionHandler::HandleGetForeignSessions( | 224 void ForeignSessionHandler::HandleGetForeignSessions( |
222 const base::ListValue* /*args*/) { | 225 const base::ListValue* /*args*/) { |
223 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(web_ui()); | 226 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(web_ui()); |
224 std::vector<const SyncedSession*> sessions; | 227 std::vector<const SyncedSession*> sessions; |
225 | 228 |
226 base::ListValue session_list; | 229 base::ListValue session_list; |
227 if (open_tabs && open_tabs->GetAllForeignSessions(&sessions)) { | 230 if (open_tabs && open_tabs->GetAllForeignSessions(&sessions)) { |
| 231 if (!load_attempt_time_.is_null()) { |
| 232 UMA_HISTOGRAM_TIMES("Sync.SessionsRefreshDelay", |
| 233 base::TimeTicks::Now() - load_attempt_time_); |
| 234 load_attempt_time_ = base::TimeTicks(); |
| 235 } |
| 236 |
228 // Sort sessions from most recent to least recent. | 237 // Sort sessions from most recent to least recent. |
229 std::sort(sessions.begin(), sessions.end(), SortSessionsByRecency); | 238 std::sort(sessions.begin(), sessions.end(), SortSessionsByRecency); |
230 | 239 |
231 // Use a pref to keep track of sessions that were collapsed by the user. | 240 // Use a pref to keep track of sessions that were collapsed by the user. |
232 // To prevent the pref from accumulating stale sessions, clear it each time | 241 // To prevent the pref from accumulating stale sessions, clear it each time |
233 // and only add back sessions that are still current. | 242 // and only add back sessions that are still current. |
234 DictionaryPrefUpdate pref_update(Profile::FromWebUI(web_ui())->GetPrefs(), | 243 DictionaryPrefUpdate pref_update(Profile::FromWebUI(web_ui())->GetPrefs(), |
235 prefs::kNtpCollapsedForeignSessions); | 244 prefs::kNtpCollapsedForeignSessions); |
236 base::DictionaryValue* current_collapsed_sessions = pref_update.Get(); | 245 base::DictionaryValue* current_collapsed_sessions = pref_update.Get(); |
237 scoped_ptr<base::DictionaryValue> collapsed_sessions( | 246 scoped_ptr<base::DictionaryValue> collapsed_sessions( |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 last_synced < base::TimeDelta::FromMinutes(1) ? | 416 last_synced < base::TimeDelta::FromMinutes(1) ? |
408 l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW) : | 417 l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW) : |
409 ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED, | 418 ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED, |
410 ui::TimeFormat::LENGTH_SHORT, last_synced)); | 419 ui::TimeFormat::LENGTH_SHORT, last_synced)); |
411 dictionary->SetInteger("sessionId", window.window_id.id()); | 420 dictionary->SetInteger("sessionId", window.window_id.id()); |
412 dictionary->Set("tabs", tab_values.release()); | 421 dictionary->Set("tabs", tab_values.release()); |
413 return true; | 422 return true; |
414 } | 423 } |
415 | 424 |
416 } // namespace browser_sync | 425 } // namespace browser_sync |
OLD | NEW |