OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sync/sessions2/sessions_sync_manager.h" | 5 #include "chrome/browser/sync/sessions2/sessions_sync_manager.h" |
6 | 6 |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #if !defined(OS_ANDROID) | 8 #if !defined(OS_ANDROID) |
9 #include "chrome/browser/network_time/navigation_time_helper.h" | 9 #include "chrome/browser/network_time/navigation_time_helper.h" |
10 #endif | 10 #endif |
(...skipping 23 matching lines...) Expand all Loading... |
34 // TODO(zea): pull this from the server. | 34 // TODO(zea): pull this from the server. |
35 static const int kMaxSyncFavicons = 200; | 35 static const int kMaxSyncFavicons = 200; |
36 | 36 |
37 // The maximum number of navigations in each direction we care to sync. | 37 // The maximum number of navigations in each direction we care to sync. |
38 static const int kMaxSyncNavigationCount = 6; | 38 static const int kMaxSyncNavigationCount = 6; |
39 | 39 |
40 // The URL at which the set of synced tabs is displayed. We treat it differently | 40 // The URL at which the set of synced tabs is displayed. We treat it differently |
41 // from all other URL's as accessing it triggers a sync refresh of Sessions. | 41 // from all other URL's as accessing it triggers a sync refresh of Sessions. |
42 static const char kNTPOpenTabSyncURL[] = "chrome://newtab/#open_tabs"; | 42 static const char kNTPOpenTabSyncURL[] = "chrome://newtab/#open_tabs"; |
43 | 43 |
| 44 // Default number of days without activity after which a session is considered |
| 45 // stale and becomes a candidate for garbage collection. |
| 46 static const size_t kDefaultStaleSessionThresholdDays = 14; // 2 weeks. |
| 47 |
44 SessionsSyncManager::SessionsSyncManager( | 48 SessionsSyncManager::SessionsSyncManager( |
45 Profile* profile, | 49 Profile* profile, |
46 SyncInternalApiDelegate* delegate, | 50 SyncInternalApiDelegate* delegate, |
47 scoped_ptr<LocalSessionEventRouter> router) | 51 scoped_ptr<LocalSessionEventRouter> router) |
48 : favicon_cache_(profile, kMaxSyncFavicons), | 52 : favicon_cache_(profile, kMaxSyncFavicons), |
49 sync_prefs_(profile->GetPrefs()), | 53 sync_prefs_(profile->GetPrefs()), |
50 profile_(profile), | 54 profile_(profile), |
51 delegate_(delegate), | 55 delegate_(delegate), |
52 local_session_header_node_id_(TabNodePool2::kInvalidTabNodeID), | 56 local_session_header_node_id_(TabNodePool2::kInvalidTabNodeID), |
| 57 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), |
53 local_event_router_(router.Pass()) { | 58 local_event_router_(router.Pass()) { |
54 } | 59 } |
55 | 60 |
56 LocalSessionEventRouter::~LocalSessionEventRouter() {} | 61 LocalSessionEventRouter::~LocalSessionEventRouter() {} |
57 | 62 |
58 SessionsSyncManager::~SessionsSyncManager() { | 63 SessionsSyncManager::~SessionsSyncManager() { |
59 } | 64 } |
60 | 65 |
61 // Returns the GUID-based string that should be used for | 66 // Returns the GUID-based string that should be used for |
62 // |SessionsSyncManager::current_machine_tag_|. | 67 // |SessionsSyncManager::current_machine_tag_|. |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 // TODO(bauerb): Add categories | 897 // TODO(bauerb): Add categories |
893 } | 898 } |
894 } | 899 } |
895 session_tab->session_storage_persistent_id.clear(); | 900 session_tab->session_storage_persistent_id.clear(); |
896 } | 901 } |
897 | 902 |
898 FaviconCache* SessionsSyncManager::GetFaviconCache() { | 903 FaviconCache* SessionsSyncManager::GetFaviconCache() { |
899 return &favicon_cache_; | 904 return &favicon_cache_; |
900 } | 905 } |
901 | 906 |
| 907 void SessionsSyncManager::DoGarbageCollection() { |
| 908 std::vector<const SyncedSession*> sessions; |
| 909 if (!GetAllForeignSessions(&sessions)) |
| 910 return; // No foreign sessions. |
| 911 |
| 912 // Iterate through all the sessions and delete any with age older than |
| 913 // |stale_session_threshold_days_|. |
| 914 syncer::SyncChangeList changes; |
| 915 for (std::vector<const SyncedSession*>::const_iterator iter = |
| 916 sessions.begin(); iter != sessions.end(); ++iter) { |
| 917 const SyncedSession* session = *iter; |
| 918 int session_age_in_days = |
| 919 (base::Time::Now() - session->modified_time).InDays(); |
| 920 std::string session_tag = session->session_tag; |
| 921 if (session_age_in_days > 0 && // If false, local clock is not trustworty. |
| 922 static_cast<size_t>(session_age_in_days) > |
| 923 stale_session_threshold_days_) { |
| 924 DVLOG(1) << "Found stale session " << session_tag |
| 925 << " with age " << session_age_in_days << ", deleting."; |
| 926 DeleteForeignSessionInternal(session_tag, &changes); |
| 927 } |
| 928 } |
| 929 |
| 930 if (!changes.empty()) |
| 931 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 932 } |
| 933 |
902 }; // namespace browser_sync | 934 }; // namespace browser_sync |
OLD | NEW |