| 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/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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "base/linux_util.h" | 45 #include "base/linux_util.h" |
| 46 #elif defined(OS_WIN) | 46 #elif defined(OS_WIN) |
| 47 #include <windows.h> | 47 #include <windows.h> |
| 48 #elif defined(OS_ANDROID) | 48 #elif defined(OS_ANDROID) |
| 49 #include "sync/util/session_utils_android.h" | 49 #include "sync/util/session_utils_android.h" |
| 50 #endif | 50 #endif |
| 51 | 51 |
| 52 using content::BrowserThread; | 52 using content::BrowserThread; |
| 53 using content::NavigationEntry; | 53 using content::NavigationEntry; |
| 54 using prefs::kSyncSessionsGUID; | 54 using prefs::kSyncSessionsGUID; |
| 55 using syncable::SESSIONS; | 55 using syncer::SESSIONS; |
| 56 | 56 |
| 57 namespace browser_sync { | 57 namespace browser_sync { |
| 58 | 58 |
| 59 namespace { | 59 namespace { |
| 60 static const char kNoSessionsFolderError[] = | 60 static const char kNoSessionsFolderError[] = |
| 61 "Server did not create the top-level sessions node. We " | 61 "Server did not create the top-level sessions node. We " |
| 62 "might be running against an out-of-date server."; | 62 "might be running against an out-of-date server."; |
| 63 | 63 |
| 64 // The maximum number of navigations in each direction we care to sync. | 64 // The maximum number of navigations in each direction we care to sync. |
| 65 static const int kMaxSyncNavigationCount = 6; | 65 static const int kMaxSyncNavigationCount = 6; |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 DCHECK_EQ(0U, tab_pool_.capacity()); | 738 DCHECK_EQ(0U, tab_pool_.capacity()); |
| 739 | 739 |
| 740 local_session_syncid_ = syncer::kInvalidId; | 740 local_session_syncid_ = syncer::kInvalidId; |
| 741 | 741 |
| 742 // Read any available foreign sessions and load any session data we may have. | 742 // Read any available foreign sessions and load any session data we may have. |
| 743 // If we don't have any local session data in the db, create a header node. | 743 // If we don't have any local session data in the db, create a header node. |
| 744 { | 744 { |
| 745 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 745 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 746 | 746 |
| 747 syncer::ReadNode root(&trans); | 747 syncer::ReadNode root(&trans); |
| 748 if (root.InitByTagLookup(syncable::ModelTypeToRootTag(model_type())) != | 748 if (root.InitByTagLookup(syncer::ModelTypeToRootTag(model_type())) != |
| 749 syncer::BaseNode::INIT_OK) { | 749 syncer::BaseNode::INIT_OK) { |
| 750 return error_handler_->CreateAndUploadError( | 750 return error_handler_->CreateAndUploadError( |
| 751 FROM_HERE, | 751 FROM_HERE, |
| 752 kNoSessionsFolderError, | 752 kNoSessionsFolderError, |
| 753 model_type()); | 753 model_type()); |
| 754 } | 754 } |
| 755 | 755 |
| 756 // Make sure we have a machine tag. | 756 // Make sure we have a machine tag. |
| 757 if (current_machine_tag_.empty()) { | 757 if (current_machine_tag_.empty()) { |
| 758 InitializeCurrentMachineTag(&trans); | 758 InitializeCurrentMachineTag(&trans); |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1390 } | 1390 } |
| 1391 | 1391 |
| 1392 void SessionModelAssociator::TabNodePool::FreeTabNode(int64 sync_id) { | 1392 void SessionModelAssociator::TabNodePool::FreeTabNode(int64 sync_id) { |
| 1393 // Pool size should always match # of free tab nodes. | 1393 // Pool size should always match # of free tab nodes. |
| 1394 DCHECK_LT(tab_pool_fp_, static_cast<int64>(tab_syncid_pool_.size())); | 1394 DCHECK_LT(tab_pool_fp_, static_cast<int64>(tab_syncid_pool_.size())); |
| 1395 tab_syncid_pool_[static_cast<size_t>(++tab_pool_fp_)] = sync_id; | 1395 tab_syncid_pool_[static_cast<size_t>(++tab_pool_fp_)] = sync_id; |
| 1396 } | 1396 } |
| 1397 | 1397 |
| 1398 void SessionModelAssociator::AttemptSessionsDataRefresh() const { | 1398 void SessionModelAssociator::AttemptSessionsDataRefresh() const { |
| 1399 DVLOG(1) << "Triggering sync refresh for sessions datatype."; | 1399 DVLOG(1) << "Triggering sync refresh for sessions datatype."; |
| 1400 const syncable::ModelType type = syncable::SESSIONS; | 1400 const syncer::ModelType type = syncer::SESSIONS; |
| 1401 syncable::ModelTypePayloadMap payload_map; | 1401 syncer::ModelTypePayloadMap payload_map; |
| 1402 payload_map[type] = ""; | 1402 payload_map[type] = ""; |
| 1403 content::NotificationService::current()->Notify( | 1403 content::NotificationService::current()->Notify( |
| 1404 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 1404 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
| 1405 content::Source<Profile>(profile_), | 1405 content::Source<Profile>(profile_), |
| 1406 content::Details<const syncable::ModelTypePayloadMap>(&payload_map)); | 1406 content::Details<const syncer::ModelTypePayloadMap>(&payload_map)); |
| 1407 } | 1407 } |
| 1408 | 1408 |
| 1409 bool SessionModelAssociator::GetLocalSession( | 1409 bool SessionModelAssociator::GetLocalSession( |
| 1410 const SyncedSession* * local_session) { | 1410 const SyncedSession* * local_session) { |
| 1411 DCHECK(CalledOnValidThread()); | 1411 DCHECK(CalledOnValidThread()); |
| 1412 if (current_machine_tag_.empty()) | 1412 if (current_machine_tag_.empty()) |
| 1413 return false; | 1413 return false; |
| 1414 *local_session = synced_session_tracker_.GetSession(GetCurrentMachineTag()); | 1414 *local_session = synced_session_tracker_.GetSession(GetCurrentMachineTag()); |
| 1415 return true; | 1415 return true; |
| 1416 } | 1416 } |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 MessageLoop::current()->PostDelayedTask( | 1574 MessageLoop::current()->PostDelayedTask( |
| 1575 FROM_HERE, | 1575 FROM_HERE, |
| 1576 base::Bind(&SessionModelAssociator::QuitLoopForSubtleTesting, | 1576 base::Bind(&SessionModelAssociator::QuitLoopForSubtleTesting, |
| 1577 test_weak_factory_.GetWeakPtr()), | 1577 test_weak_factory_.GetWeakPtr()), |
| 1578 base::TimeDelta::FromMilliseconds(timeout_milliseconds)); | 1578 base::TimeDelta::FromMilliseconds(timeout_milliseconds)); |
| 1579 } | 1579 } |
| 1580 | 1580 |
| 1581 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1581 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
| 1582 // We only access the cryptographer while holding a transaction. | 1582 // We only access the cryptographer while holding a transaction. |
| 1583 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1583 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1584 const syncable::ModelTypeSet encrypted_types = | 1584 const syncer::ModelTypeSet encrypted_types = |
| 1585 syncer::GetEncryptedTypes(&trans); | 1585 syncer::GetEncryptedTypes(&trans); |
| 1586 return !encrypted_types.Has(SESSIONS) || | 1586 return !encrypted_types.Has(SESSIONS) || |
| 1587 sync_service_->IsCryptographerReady(&trans); | 1587 sync_service_->IsCryptographerReady(&trans); |
| 1588 } | 1588 } |
| 1589 | 1589 |
| 1590 } // namespace browser_sync | 1590 } // namespace browser_sync |
| OLD | NEW |