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<LocalEventRouter> router) | 51 scoped_ptr<LocalEventRouter> 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 SessionsSyncManager::~SessionsSyncManager() { | 61 SessionsSyncManager::~SessionsSyncManager() { |
57 } | 62 } |
58 | 63 |
59 // Returns the GUID-based string that should be used for | 64 // Returns the GUID-based string that should be used for |
60 // |SessionsSyncManager::current_machine_tag_|. | 65 // |SessionsSyncManager::current_machine_tag_|. |
61 static std::string BuildMachineTag(const std::string& cache_guid) { | 66 static std::string BuildMachineTag(const std::string& cache_guid) { |
62 std::string machine_tag = "session_sync"; | 67 std::string machine_tag = "session_sync"; |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 // TODO(bauerb): Add categories | 913 // TODO(bauerb): Add categories |
909 } | 914 } |
910 } | 915 } |
911 session_tab->session_storage_persistent_id.clear(); | 916 session_tab->session_storage_persistent_id.clear(); |
912 } | 917 } |
913 | 918 |
914 FaviconCache* SessionsSyncManager::GetFaviconCache() { | 919 FaviconCache* SessionsSyncManager::GetFaviconCache() { |
915 return &favicon_cache_; | 920 return &favicon_cache_; |
916 } | 921 } |
917 | 922 |
| 923 void SessionsSyncManager::DoGarbageCollection() { |
| 924 std::vector<const SyncedSession*> sessions; |
| 925 if (!GetAllForeignSessions(&sessions)) |
| 926 return; // No foreign sessions. |
| 927 |
| 928 // Iterate through all the sessions and delete any with age older than |
| 929 // |stale_session_threshold_days_|. |
| 930 syncer::SyncChangeList changes; |
| 931 for (std::vector<const SyncedSession*>::const_iterator iter = |
| 932 sessions.begin(); iter != sessions.end(); ++iter) { |
| 933 const SyncedSession* session = *iter; |
| 934 int session_age_in_days = |
| 935 (base::Time::Now() - session->modified_time).InDays(); |
| 936 std::string session_tag = session->session_tag; |
| 937 if (session_age_in_days > 0 && // If false, local clock is not trustworty. |
| 938 static_cast<size_t>(session_age_in_days) > |
| 939 stale_session_threshold_days_) { |
| 940 DVLOG(1) << "Found stale session " << session_tag |
| 941 << " with age " << session_age_in_days << ", deleting."; |
| 942 DeleteForeignSessionInternal(session_tag, &changes); |
| 943 } |
| 944 } |
| 945 |
| 946 if (!changes.empty()) |
| 947 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 948 } |
| 949 |
918 }; // namespace browser_sync | 950 }; // namespace browser_sync |
OLD | NEW |