| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sessions/sessions_sync_manager.h" | 5 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/sync/glue/local_device_info_provider.h" | 9 #include "chrome/browser/sync/glue/local_device_info_provider.h" |
| 10 #include "chrome/browser/sync/glue/synced_tab_delegate.h" | 10 #include "chrome/browser/sync/glue/synced_tab_delegate.h" |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 syncer::SyncDataList data( | 331 syncer::SyncDataList data( |
| 332 sync_processor_->GetAllSyncData(syncer::SESSIONS)); | 332 sync_processor_->GetAllSyncData(syncer::SESSIONS)); |
| 333 scoped_ptr<syncer::SyncErrorFactory> error_handler(error_handler_.Pass()); | 333 scoped_ptr<syncer::SyncErrorFactory> error_handler(error_handler_.Pass()); |
| 334 scoped_ptr<syncer::SyncChangeProcessor> processor(sync_processor_.Pass()); | 334 scoped_ptr<syncer::SyncChangeProcessor> processor(sync_processor_.Pass()); |
| 335 | 335 |
| 336 StopSyncing(syncer::SESSIONS); | 336 StopSyncing(syncer::SESSIONS); |
| 337 MergeDataAndStartSyncing( | 337 MergeDataAndStartSyncing( |
| 338 syncer::SESSIONS, data, processor.Pass(), error_handler.Pass()); | 338 syncer::SESSIONS, data, processor.Pass(), error_handler.Pass()); |
| 339 } | 339 } |
| 340 | 340 |
| 341 bool SessionsSyncManager::IsValidSessionHeader( |
| 342 const sync_pb::SessionHeader& header) { |
| 343 // Verify that tab IDs appear only once within a session. |
| 344 // Intended to prevent http://crbug.com/360822. |
| 345 std::set<int> session_tab_ids; |
| 346 for (int i = 0; i < header.window_size(); ++i) { |
| 347 const sync_pb::SessionWindow& window = header.window(i); |
| 348 for (int j = 0; j < window.tab_size(); ++j) { |
| 349 const int tab_id = window.tab(j); |
| 350 bool success = session_tab_ids.insert(tab_id).second; |
| 351 if (!success) |
| 352 return false; |
| 353 } |
| 354 } |
| 355 |
| 356 return true; |
| 357 } |
| 358 |
| 341 void SessionsSyncManager::OnLocalTabModified(SyncedTabDelegate* modified_tab) { | 359 void SessionsSyncManager::OnLocalTabModified(SyncedTabDelegate* modified_tab) { |
| 342 const content::NavigationEntry* entry = modified_tab->GetActiveEntry(); | 360 const content::NavigationEntry* entry = modified_tab->GetActiveEntry(); |
| 343 if (!modified_tab->IsBeingDestroyed() && | 361 if (!modified_tab->IsBeingDestroyed() && |
| 344 entry && | 362 entry && |
| 345 entry->GetVirtualURL().is_valid() && | 363 entry->GetVirtualURL().is_valid() && |
| 346 entry->GetVirtualURL().spec() == kNTPOpenTabSyncURL) { | 364 entry->GetVirtualURL().spec() == kNTPOpenTabSyncURL) { |
| 347 DVLOG(1) << "Triggering sync refresh for sessions datatype."; | 365 DVLOG(1) << "Triggering sync refresh for sessions datatype."; |
| 348 const syncer::ModelTypeSet types(syncer::SESSIONS); | 366 const syncer::ModelTypeSet types(syncer::SESSIONS); |
| 349 content::NotificationService::current()->Notify( | 367 content::NotificationService::current()->Notify( |
| 350 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 368 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 std::string foreign_session_tag = specifics.session_tag(); | 600 std::string foreign_session_tag = specifics.session_tag(); |
| 583 DCHECK_NE(foreign_session_tag, current_machine_tag()); | 601 DCHECK_NE(foreign_session_tag, current_machine_tag()); |
| 584 | 602 |
| 585 SyncedSession* foreign_session = | 603 SyncedSession* foreign_session = |
| 586 session_tracker_.GetSession(foreign_session_tag); | 604 session_tracker_.GetSession(foreign_session_tag); |
| 587 if (specifics.has_header()) { | 605 if (specifics.has_header()) { |
| 588 // Read in the header data for this foreign session. | 606 // Read in the header data for this foreign session. |
| 589 // Header data contains window information and ordered tab id's for each | 607 // Header data contains window information and ordered tab id's for each |
| 590 // window. | 608 // window. |
| 591 | 609 |
| 610 if (!IsValidSessionHeader(specifics.header())) { |
| 611 LOG(WARNING) << "Ignoring foreign session node with invalid header " |
| 612 << "and tag " << foreign_session_tag << "."; |
| 613 return; |
| 614 } |
| 615 |
| 592 // Load (or create) the SyncedSession object for this client. | 616 // Load (or create) the SyncedSession object for this client. |
| 593 const sync_pb::SessionHeader& header = specifics.header(); | 617 const sync_pb::SessionHeader& header = specifics.header(); |
| 594 PopulateSessionHeaderFromSpecifics(header, | 618 PopulateSessionHeaderFromSpecifics(header, |
| 595 modification_time, | 619 modification_time, |
| 596 foreign_session); | 620 foreign_session); |
| 597 | 621 |
| 598 // Reset the tab/window tracking for this session (must do this before | 622 // Reset the tab/window tracking for this session (must do this before |
| 599 // we start calling PutWindowInSession and PutTabInWindow so that all | 623 // we start calling PutWindowInSession and PutTabInWindow so that all |
| 600 // unused tabs/windows get cleared by the CleanupSession(...) call). | 624 // unused tabs/windows get cleared by the CleanupSession(...) call). |
| 601 session_tracker_.ResetSessionTracking(foreign_session_tag); | 625 session_tracker_.ResetSessionTracking(foreign_session_tag); |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 << " with age " << session_age_in_days << ", deleting."; | 1029 << " with age " << session_age_in_days << ", deleting."; |
| 1006 DeleteForeignSessionInternal(session_tag, &changes); | 1030 DeleteForeignSessionInternal(session_tag, &changes); |
| 1007 } | 1031 } |
| 1008 } | 1032 } |
| 1009 | 1033 |
| 1010 if (!changes.empty()) | 1034 if (!changes.empty()) |
| 1011 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 1035 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 1012 } | 1036 } |
| 1013 | 1037 |
| 1014 }; // namespace browser_sync | 1038 }; // namespace browser_sync |
| OLD | NEW |