OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/glue/session_model_associator.h" | 5 #include "chrome/browser/sync/glue/session_model_associator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
32 #include "content/public/browser/navigation_entry.h" | 32 #include "content/public/browser/navigation_entry.h" |
33 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
34 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.h" |
35 #if defined(OS_LINUX) | 35 #if defined(OS_LINUX) |
36 #include "base/linux_util.h" | 36 #include "base/linux_util.h" |
37 #elif defined(OS_WIN) | 37 #elif defined(OS_WIN) |
38 #include <windows.h> | 38 #include <windows.h> |
39 #endif | 39 #endif |
40 | 40 |
| 41 using content::BrowserThread; |
| 42 using content::NavigationEntry; |
| 43 using syncable::SESSIONS; |
| 44 |
41 namespace browser_sync { | 45 namespace browser_sync { |
42 | 46 |
43 using content::BrowserThread; | |
44 using syncable::SESSIONS; | |
45 | |
46 namespace { | 47 namespace { |
47 static const char kNoSessionsFolderError[] = | 48 static const char kNoSessionsFolderError[] = |
48 "Server did not create the top-level sessions node. We " | 49 "Server did not create the top-level sessions node. We " |
49 "might be running against an out-of-date server."; | 50 "might be running against an out-of-date server."; |
50 | 51 |
51 // The maximum number of navigations in each direction we care to sync. | 52 // The maximum number of navigations in each direction we care to sync. |
52 static const int kMaxSyncNavigationCount = 6; | 53 static const int kMaxSyncNavigationCount = 6; |
53 | 54 |
54 // Default number of days without activity after which a session is considered | 55 // Default number of days without activity after which a session is considered |
55 // stale and becomes a candidate for garbage collection. | 56 // stale and becomes a candidate for garbage collection. |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 const int min_index = std::max(0, | 330 const int min_index = std::max(0, |
330 current_index - kMaxSyncNavigationCount); | 331 current_index - kMaxSyncNavigationCount); |
331 const int max_index = std::min(current_index + kMaxSyncNavigationCount, | 332 const int max_index = std::min(current_index + kMaxSyncNavigationCount, |
332 tab.GetEntryCount()); | 333 tab.GetEntryCount()); |
333 const int pending_index = tab.GetPendingEntryIndex(); | 334 const int pending_index = tab.GetPendingEntryIndex(); |
334 tab_s->set_pinned(window.IsTabPinned(&tab)); | 335 tab_s->set_pinned(window.IsTabPinned(&tab)); |
335 if (tab.HasExtensionAppId()) { | 336 if (tab.HasExtensionAppId()) { |
336 tab_s->set_extension_app_id(tab.GetExtensionAppId()); | 337 tab_s->set_extension_app_id(tab.GetExtensionAppId()); |
337 } | 338 } |
338 for (int i = min_index; i < max_index; ++i) { | 339 for (int i = min_index; i < max_index; ++i) { |
339 const content::NavigationEntry* entry = (i == pending_index) ? | 340 const NavigationEntry* entry = (i == pending_index) ? |
340 tab.GetPendingEntry() : tab.GetEntryAtIndex(i); | 341 tab.GetPendingEntry() : tab.GetEntryAtIndex(i); |
341 DCHECK(entry); | 342 DCHECK(entry); |
342 if (entry->GetVirtualURL().is_valid()) { | 343 if (entry->GetVirtualURL().is_valid()) { |
343 if (i == max_index - 1) { | 344 if (i == max_index - 1) { |
344 DVLOG(1) << "Associating tab " << tab_id << " with sync id " << sync_id | 345 DVLOG(1) << "Associating tab " << tab_id << " with sync id " << sync_id |
345 << ", url " << entry->GetVirtualURL().possibly_invalid_spec() | 346 << ", url " << entry->GetVirtualURL().possibly_invalid_spec() |
346 << " and title " << entry->GetTitle(); | 347 << " and title " << entry->GetTitle(); |
347 } | 348 } |
348 TabNavigation tab_nav; | 349 TabNavigation tab_nav; |
349 tab_nav.SetFromNavigationEntry(*entry); | 350 tab_nav.SetFromNavigationEntry(*entry); |
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 // Valid local tab? | 1058 // Valid local tab? |
1058 bool SessionModelAssociator::IsValidTab(const SyncedTabDelegate& tab) const { | 1059 bool SessionModelAssociator::IsValidTab(const SyncedTabDelegate& tab) const { |
1059 DCHECK(CalledOnValidThread()); | 1060 DCHECK(CalledOnValidThread()); |
1060 if ((tab.profile() == sync_service_->profile() || | 1061 if ((tab.profile() == sync_service_->profile() || |
1061 sync_service_->profile() == NULL)) { // For tests. | 1062 sync_service_->profile() == NULL)) { // For tests. |
1062 const SyncedWindowDelegate* window = | 1063 const SyncedWindowDelegate* window = |
1063 SyncedWindowDelegate::FindSyncedWindowDelegateWithId( | 1064 SyncedWindowDelegate::FindSyncedWindowDelegateWithId( |
1064 tab.GetWindowId()); | 1065 tab.GetWindowId()); |
1065 if (!window) | 1066 if (!window) |
1066 return false; | 1067 return false; |
1067 const content::NavigationEntry* entry = tab.GetActiveEntry(); | 1068 const NavigationEntry* entry = tab.GetActiveEntry(); |
1068 if (!entry) | 1069 if (!entry) |
1069 return false; | 1070 return false; |
1070 if (entry->GetVirtualURL().is_valid() && | 1071 if (entry->GetVirtualURL().is_valid() && |
1071 (entry->GetVirtualURL().GetOrigin() != | 1072 (entry->GetVirtualURL().GetOrigin() != |
1072 GURL(chrome::kChromeUINewTabURL) || | 1073 GURL(chrome::kChromeUINewTabURL) || |
1073 tab.GetEntryCount() > 1)) { | 1074 tab.GetEntryCount() > 1)) { |
1074 return true; | 1075 return true; |
1075 } | 1076 } |
1076 } | 1077 } |
1077 return false; | 1078 return false; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1253 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
1253 // We only access the cryptographer while holding a transaction. | 1254 // We only access the cryptographer while holding a transaction. |
1254 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1255 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
1255 const syncable::ModelTypeSet encrypted_types = | 1256 const syncable::ModelTypeSet encrypted_types = |
1256 sync_api::GetEncryptedTypes(&trans); | 1257 sync_api::GetEncryptedTypes(&trans); |
1257 return !encrypted_types.Has(SESSIONS) || | 1258 return !encrypted_types.Has(SESSIONS) || |
1258 sync_service_->IsCryptographerReady(&trans); | 1259 sync_service_->IsCryptographerReady(&trans); |
1259 } | 1260 } |
1260 | 1261 |
1261 } // namespace browser_sync | 1262 } // namespace browser_sync |
OLD | NEW |