| 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 "components/sync_sessions/sessions_sync_manager.h" | 5 #include "components/sync_sessions/sessions_sync_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "components/sync/base/hash_util.h" | 17 #include "components/sync/base/hash_util.h" |
| 18 #include "components/sync/device_info/local_device_info_provider.h" | 18 #include "components/sync/device_info/local_device_info_provider.h" |
| 19 #include "components/sync/model/sync_error.h" | 19 #include "components/sync/model/sync_error.h" |
| 20 #include "components/sync/model/sync_error_factory.h" | 20 #include "components/sync/model/sync_error_factory.h" |
| 21 #include "components/sync/model/sync_merge_result.h" | 21 #include "components/sync/model/sync_merge_result.h" |
| 22 #include "components/sync/model/time.h" | 22 #include "components/sync/model/time.h" |
| 23 #include "components/sync_sessions/sync_sessions_client.h" | 23 #include "components/sync_sessions/sync_sessions_client.h" |
| 24 #include "components/sync_sessions/synced_tab_delegate.h" | 24 #include "components/sync_sessions/synced_tab_delegate.h" |
| 25 #include "components/sync_sessions/synced_window_delegate.h" | 25 #include "components/sync_sessions/synced_window_delegate.h" |
| 26 #include "components/sync_sessions/synced_window_delegates_getter.h" | 26 #include "components/sync_sessions/synced_window_delegates_getter.h" |
| 27 #include "components/sync_sessions/tab_node_pool.h" | 27 #include "components/sync_sessions/tab_node_pool.h" |
| 28 #include "components/variations/variations_associated_data.h" | |
| 29 | 28 |
| 30 using sessions::SerializedNavigationEntry; | 29 using sessions::SerializedNavigationEntry; |
| 31 using syncer::DeviceInfo; | 30 using syncer::DeviceInfo; |
| 32 using syncer::LocalDeviceInfoProvider; | 31 using syncer::LocalDeviceInfoProvider; |
| 33 using syncer::SyncChange; | 32 using syncer::SyncChange; |
| 34 using syncer::SyncData; | 33 using syncer::SyncData; |
| 35 | 34 |
| 36 namespace sync_sessions { | 35 namespace sync_sessions { |
| 37 | 36 |
| 38 namespace { | 37 namespace { |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 session_tracker_.GetTab(current_machine_tag(), tab_id); | 383 session_tracker_.GetTab(current_machine_tag(), tab_id); |
| 385 | 384 |
| 386 // Get the previously synced url. | 385 // Get the previously synced url. |
| 387 int old_index = session_tab->normalized_navigation_index(); | 386 int old_index = session_tab->normalized_navigation_index(); |
| 388 GURL old_url; | 387 GURL old_url; |
| 389 if (session_tab->navigations.size() > static_cast<size_t>(old_index)) | 388 if (session_tab->navigations.size() > static_cast<size_t>(old_index)) |
| 390 old_url = session_tab->navigations[old_index].virtual_url(); | 389 old_url = session_tab->navigations[old_index].virtual_url(); |
| 391 | 390 |
| 392 // Update the tracker's session representation. | 391 // Update the tracker's session representation. |
| 393 SetSessionTabFromDelegate(*tab_delegate, base::Time::Now(), session_tab); | 392 SetSessionTabFromDelegate(*tab_delegate, base::Time::Now(), session_tab); |
| 394 SetVariationIds(session_tab); | |
| 395 session_tracker_.GetSession(current_machine_tag())->modified_time = | 393 session_tracker_.GetSession(current_machine_tag())->modified_time = |
| 396 base::Time::Now(); | 394 base::Time::Now(); |
| 397 | 395 |
| 398 // Write to the sync model itself. | 396 // Write to the sync model itself. |
| 399 sync_pb::EntitySpecifics specifics; | 397 sync_pb::EntitySpecifics specifics; |
| 400 specifics.mutable_session()->CopyFrom( | 398 specifics.mutable_session()->CopyFrom( |
| 401 SessionTabToSpecifics(*session_tab, current_machine_tag(), tab_node_id)); | 399 SessionTabToSpecifics(*session_tab, current_machine_tag(), tab_node_id)); |
| 402 syncer::SyncData data = syncer::SyncData::CreateLocalData( | 400 syncer::SyncData data = syncer::SyncData::CreateLocalData( |
| 403 TabNodeIdToTag(current_machine_tag(), tab_node_id), current_session_name_, | 401 TabNodeIdToTag(current_machine_tag(), tab_node_id), current_session_name_, |
| 404 specifics); | 402 specifics); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 syncer::SyncDataList list; | 503 syncer::SyncDataList list; |
| 506 const SyncedSession* session = nullptr; | 504 const SyncedSession* session = nullptr; |
| 507 if (!session_tracker_.LookupLocalSession(&session)) | 505 if (!session_tracker_.LookupLocalSession(&session)) |
| 508 return syncer::SyncDataList(); | 506 return syncer::SyncDataList(); |
| 509 | 507 |
| 510 // First construct the header node. | 508 // First construct the header node. |
| 511 sync_pb::EntitySpecifics header_entity; | 509 sync_pb::EntitySpecifics header_entity; |
| 512 header_entity.mutable_session()->set_session_tag(current_machine_tag()); | 510 header_entity.mutable_session()->set_session_tag(current_machine_tag()); |
| 513 sync_pb::SessionHeader* header_specifics = | 511 sync_pb::SessionHeader* header_specifics = |
| 514 header_entity.mutable_session()->mutable_header(); | 512 header_entity.mutable_session()->mutable_header(); |
| 515 header_specifics->MergeFrom(session->ToSessionHeader()); | 513 header_specifics->MergeFrom(session->ToSyncSessionHeaderPB()); |
| 516 syncer::SyncData data = syncer::SyncData::CreateLocalData( | 514 syncer::SyncData data = syncer::SyncData::CreateLocalData( |
| 517 current_machine_tag(), current_session_name_, header_entity); | 515 current_machine_tag(), current_session_name_, header_entity); |
| 518 list.push_back(data); | 516 list.push_back(data); |
| 519 | 517 |
| 520 for (auto& win_iter : session->windows) { | 518 for (auto& win_iter : session->windows) { |
| 521 for (auto& tab : win_iter.second->tabs) { | 519 for (auto& tab : win_iter.second->wrapped_window.tabs) { |
| 522 // TODO(zea): replace with with the correct tab node id once there's a | 520 // TODO(zea): replace with with the correct tab node id once there's a |
| 523 // sync specific wrapper for SessionTab. This method is only used in | 521 // sync specific wrapper for SessionTab. This method is only used in |
| 524 // tests though, so it's fine for now. crbug.com/662597 | 522 // tests though, so it's fine for now. crbug.com/662597 |
| 525 int tab_node_id = 0; | 523 int tab_node_id = 0; |
| 526 sync_pb::EntitySpecifics entity; | 524 sync_pb::EntitySpecifics entity; |
| 527 entity.mutable_session()->CopyFrom( | 525 entity.mutable_session()->CopyFrom( |
| 528 SessionTabToSpecifics(*tab, current_machine_tag(), tab_node_id)); | 526 SessionTabToSpecifics(*tab, current_machine_tag(), tab_node_id)); |
| 529 syncer::SyncData data = syncer::SyncData::CreateLocalData( | 527 syncer::SyncData data = syncer::SyncData::CreateLocalData( |
| 530 TabNodeIdToTag(current_machine_tag(), tab_node_id), | 528 TabNodeIdToTag(current_machine_tag(), tab_node_id), |
| 531 current_session_name_, entity); | 529 current_session_name_, entity); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 } | 858 } |
| 861 session_header->modified_time = | 859 session_header->modified_time = |
| 862 std::max(mtime, session_header->modified_time); | 860 std::max(mtime, session_header->modified_time); |
| 863 } | 861 } |
| 864 | 862 |
| 865 // static | 863 // static |
| 866 void SessionsSyncManager::BuildSyncedSessionFromSpecifics( | 864 void SessionsSyncManager::BuildSyncedSessionFromSpecifics( |
| 867 const std::string& session_tag, | 865 const std::string& session_tag, |
| 868 const sync_pb::SessionWindow& specifics, | 866 const sync_pb::SessionWindow& specifics, |
| 869 base::Time mtime, | 867 base::Time mtime, |
| 870 sessions::SessionWindow* session_window) { | 868 SyncedSessionWindow* synced_session_window) { |
| 869 sessions::SessionWindow* session_window = |
| 870 &synced_session_window->wrapped_window; |
| 871 if (specifics.has_window_id()) | 871 if (specifics.has_window_id()) |
| 872 session_window->window_id.set_id(specifics.window_id()); | 872 session_window->window_id.set_id(specifics.window_id()); |
| 873 if (specifics.has_selected_tab_index()) | 873 if (specifics.has_selected_tab_index()) |
| 874 session_window->selected_tab_index = specifics.selected_tab_index(); | 874 session_window->selected_tab_index = specifics.selected_tab_index(); |
| 875 synced_session_window->window_type = specifics.browser_type(); |
| 875 if (specifics.has_browser_type()) { | 876 if (specifics.has_browser_type()) { |
| 876 // TODO(skuhne): Sync data writes |BrowserType| not | |
| 877 // |SessionWindow::WindowType|. This should get changed. | |
| 878 if (specifics.browser_type() == | 877 if (specifics.browser_type() == |
| 879 sync_pb::SessionWindow_BrowserType_TYPE_TABBED) { | 878 sync_pb::SessionWindow_BrowserType_TYPE_TABBED) { |
| 880 session_window->type = sessions::SessionWindow::TYPE_TABBED; | 879 session_window->type = sessions::SessionWindow::TYPE_TABBED; |
| 881 } else { | 880 } else { |
| 882 // Note: custom tabs are treated like popup windows on restore, as you can | 881 // Note: custom tabs are treated like popup windows on restore, as you can |
| 883 // restore a custom tab on a platform that doesn't support them. | 882 // restore a custom tab on a platform that doesn't support them. |
| 884 session_window->type = sessions::SessionWindow::TYPE_POPUP; | 883 session_window->type = sessions::SessionWindow::TYPE_POPUP; |
| 885 } | 884 } |
| 886 } | 885 } |
| 887 session_window->timestamp = mtime; | 886 session_window->timestamp = mtime; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 session_tab->navigations.push_back(*blocked_navigations[i]); | 1085 session_tab->navigations.push_back(*blocked_navigations[i]); |
| 1087 session_tab->navigations.back().set_index(offset + i); | 1086 session_tab->navigations.back().set_index(offset + i); |
| 1088 session_tab->navigations.back().set_blocked_state( | 1087 session_tab->navigations.back().set_blocked_state( |
| 1089 SerializedNavigationEntry::STATE_BLOCKED); | 1088 SerializedNavigationEntry::STATE_BLOCKED); |
| 1090 // TODO(bauerb): Add categories | 1089 // TODO(bauerb): Add categories |
| 1091 } | 1090 } |
| 1092 } | 1091 } |
| 1093 session_tab->session_storage_persistent_id.clear(); | 1092 session_tab->session_storage_persistent_id.clear(); |
| 1094 } | 1093 } |
| 1095 | 1094 |
| 1096 // static | |
| 1097 void SessionsSyncManager::SetVariationIds(sessions::SessionTab* session_tab) { | |
| 1098 base::FieldTrial::ActiveGroups active_groups; | |
| 1099 base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups); | |
| 1100 for (const base::FieldTrial::ActiveGroup& group : active_groups) { | |
| 1101 const variations::VariationID id = variations::GetGoogleVariationID( | |
| 1102 variations::CHROME_SYNC_SERVICE, group.trial_name, group.group_name); | |
| 1103 if (id != variations::EMPTY_ID) | |
| 1104 session_tab->variation_ids.push_back(id); | |
| 1105 } | |
| 1106 } | |
| 1107 | |
| 1108 FaviconCache* SessionsSyncManager::GetFaviconCache() { | 1095 FaviconCache* SessionsSyncManager::GetFaviconCache() { |
| 1109 return &favicon_cache_; | 1096 return &favicon_cache_; |
| 1110 } | 1097 } |
| 1111 | 1098 |
| 1112 SyncedWindowDelegatesGetter* | 1099 SyncedWindowDelegatesGetter* |
| 1113 SessionsSyncManager::synced_window_delegates_getter() const { | 1100 SessionsSyncManager::synced_window_delegates_getter() const { |
| 1114 return sessions_client_->GetSyncedWindowDelegatesGetter(); | 1101 return sessions_client_->GetSyncedWindowDelegatesGetter(); |
| 1115 } | 1102 } |
| 1116 | 1103 |
| 1117 void SessionsSyncManager::DoGarbageCollection() { | 1104 void SessionsSyncManager::DoGarbageCollection() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1139 } | 1126 } |
| 1140 | 1127 |
| 1141 // static | 1128 // static |
| 1142 std::string SessionsSyncManager::TagHashFromSpecifics( | 1129 std::string SessionsSyncManager::TagHashFromSpecifics( |
| 1143 const sync_pb::SessionSpecifics& specifics) { | 1130 const sync_pb::SessionSpecifics& specifics) { |
| 1144 return syncer::GenerateSyncableHash(syncer::SESSIONS, | 1131 return syncer::GenerateSyncableHash(syncer::SESSIONS, |
| 1145 TagFromSpecifics(specifics)); | 1132 TagFromSpecifics(specifics)); |
| 1146 } | 1133 } |
| 1147 | 1134 |
| 1148 }; // namespace sync_sessions | 1135 }; // namespace sync_sessions |
| OLD | NEW |