| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // sync_manager.cc[1060] | 73 // sync_manager.cc[1060] |
| 74 #if defined(OS_CHROMEOS) | 74 #if defined(OS_CHROMEOS) |
| 75 return sync_pb::SessionHeader_DeviceType_TYPE_CROS; | 75 return sync_pb::SessionHeader_DeviceType_TYPE_CROS; |
| 76 #elif defined(OS_LINUX) | 76 #elif defined(OS_LINUX) |
| 77 return sync_pb::SessionHeader_DeviceType_TYPE_LINUX; | 77 return sync_pb::SessionHeader_DeviceType_TYPE_LINUX; |
| 78 #elif defined(OS_MACOSX) | 78 #elif defined(OS_MACOSX) |
| 79 return sync_pb::SessionHeader_DeviceType_TYPE_MAC; | 79 return sync_pb::SessionHeader_DeviceType_TYPE_MAC; |
| 80 #elif defined(OS_WIN) | 80 #elif defined(OS_WIN) |
| 81 return sync_pb::SessionHeader_DeviceType_TYPE_WIN; | 81 return sync_pb::SessionHeader_DeviceType_TYPE_WIN; |
| 82 #elif defined(OS_ANDROID) | 82 #elif defined(OS_ANDROID) |
| 83 return csync::internal::IsTabletUi() ? | 83 return syncer::internal::IsTabletUi() ? |
| 84 sync_pb::SessionHeader_DeviceType_TYPE_TABLET : | 84 sync_pb::SessionHeader_DeviceType_TYPE_TABLET : |
| 85 sync_pb::SessionHeader_DeviceType_TYPE_PHONE; | 85 sync_pb::SessionHeader_DeviceType_TYPE_PHONE; |
| 86 #else | 86 #else |
| 87 return sync_pb::SessionHeader_DeviceType_TYPE_OTHER; | 87 return sync_pb::SessionHeader_DeviceType_TYPE_OTHER; |
| 88 #endif | 88 #endif |
| 89 } | 89 } |
| 90 | 90 |
| 91 } // namespace | 91 } // namespace |
| 92 | 92 |
| 93 SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service, | 93 SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service, |
| 94 DataTypeErrorHandler* error_handler) | 94 DataTypeErrorHandler* error_handler) |
| 95 : tab_pool_(sync_service), | 95 : tab_pool_(sync_service), |
| 96 local_session_syncid_(csync::kInvalidId), | 96 local_session_syncid_(syncer::kInvalidId), |
| 97 sync_service_(sync_service), | 97 sync_service_(sync_service), |
| 98 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), | 98 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), |
| 99 setup_for_test_(false), | 99 setup_for_test_(false), |
| 100 waiting_for_change_(false), | 100 waiting_for_change_(false), |
| 101 ALLOW_THIS_IN_INITIALIZER_LIST(test_weak_factory_(this)), | 101 ALLOW_THIS_IN_INITIALIZER_LIST(test_weak_factory_(this)), |
| 102 profile_(sync_service->profile()), | 102 profile_(sync_service->profile()), |
| 103 pref_service_(profile_->GetPrefs()), | 103 pref_service_(profile_->GetPrefs()), |
| 104 error_handler_(error_handler) { | 104 error_handler_(error_handler) { |
| 105 DCHECK(CalledOnValidThread()); | 105 DCHECK(CalledOnValidThread()); |
| 106 DCHECK(sync_service_); | 106 DCHECK(sync_service_); |
| 107 DCHECK(profile_); | 107 DCHECK(profile_); |
| 108 if (pref_service_->FindPreference(kSyncSessionsGUID) == NULL) { | 108 if (pref_service_->FindPreference(kSyncSessionsGUID) == NULL) { |
| 109 pref_service_->RegisterStringPref(kSyncSessionsGUID, | 109 pref_service_->RegisterStringPref(kSyncSessionsGUID, |
| 110 std::string(), | 110 std::string(), |
| 111 PrefService::UNSYNCABLE_PREF); | 111 PrefService::UNSYNCABLE_PREF); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service, | 115 SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service, |
| 116 bool setup_for_test) | 116 bool setup_for_test) |
| 117 : tab_pool_(sync_service), | 117 : tab_pool_(sync_service), |
| 118 local_session_syncid_(csync::kInvalidId), | 118 local_session_syncid_(syncer::kInvalidId), |
| 119 sync_service_(sync_service), | 119 sync_service_(sync_service), |
| 120 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), | 120 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), |
| 121 setup_for_test_(setup_for_test), | 121 setup_for_test_(setup_for_test), |
| 122 waiting_for_change_(false), | 122 waiting_for_change_(false), |
| 123 ALLOW_THIS_IN_INITIALIZER_LIST(test_weak_factory_(this)), | 123 ALLOW_THIS_IN_INITIALIZER_LIST(test_weak_factory_(this)), |
| 124 profile_(sync_service->profile()), | 124 profile_(sync_service->profile()), |
| 125 pref_service_(NULL), | 125 pref_service_(NULL), |
| 126 error_handler_(NULL) { | 126 error_handler_(NULL) { |
| 127 DCHECK(CalledOnValidThread()); | 127 DCHECK(CalledOnValidThread()); |
| 128 DCHECK(sync_service_); | 128 DCHECK(sync_service_); |
| 129 DCHECK(profile_); | 129 DCHECK(profile_); |
| 130 DCHECK(setup_for_test); | 130 DCHECK(setup_for_test); |
| 131 } | 131 } |
| 132 | 132 |
| 133 SessionModelAssociator::~SessionModelAssociator() { | 133 SessionModelAssociator::~SessionModelAssociator() { |
| 134 DCHECK(CalledOnValidThread()); | 134 DCHECK(CalledOnValidThread()); |
| 135 } | 135 } |
| 136 | 136 |
| 137 bool SessionModelAssociator::InitSyncNodeFromChromeId( | 137 bool SessionModelAssociator::InitSyncNodeFromChromeId( |
| 138 const std::string& id, | 138 const std::string& id, |
| 139 csync::BaseNode* sync_node) { | 139 syncer::BaseNode* sync_node) { |
| 140 NOTREACHED(); | 140 NOTREACHED(); |
| 141 return false; | 141 return false; |
| 142 } | 142 } |
| 143 | 143 |
| 144 bool SessionModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { | 144 bool SessionModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { |
| 145 DCHECK(CalledOnValidThread()); | 145 DCHECK(CalledOnValidThread()); |
| 146 CHECK(has_nodes); | 146 CHECK(has_nodes); |
| 147 *has_nodes = false; | 147 *has_nodes = false; |
| 148 csync::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 148 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 149 csync::ReadNode root(&trans); | 149 syncer::ReadNode root(&trans); |
| 150 if (root.InitByTagLookup(kSessionsTag) != csync::BaseNode::INIT_OK) { | 150 if (root.InitByTagLookup(kSessionsTag) != syncer::BaseNode::INIT_OK) { |
| 151 LOG(ERROR) << kNoSessionsFolderError; | 151 LOG(ERROR) << kNoSessionsFolderError; |
| 152 return false; | 152 return false; |
| 153 } | 153 } |
| 154 // The sync model has user created nodes iff the sessions folder has | 154 // The sync model has user created nodes iff the sessions folder has |
| 155 // any children. | 155 // any children. |
| 156 *has_nodes = root.HasChildren(); | 156 *has_nodes = root.HasChildren(); |
| 157 return true; | 157 return true; |
| 158 } | 158 } |
| 159 | 159 |
| 160 int64 SessionModelAssociator::GetSyncIdFromChromeId(const size_t& id) { | 160 int64 SessionModelAssociator::GetSyncIdFromChromeId(const size_t& id) { |
| 161 DCHECK(CalledOnValidThread()); | 161 DCHECK(CalledOnValidThread()); |
| 162 return GetSyncIdFromSessionTag(TabIdToTag(GetCurrentMachineTag(), id)); | 162 return GetSyncIdFromSessionTag(TabIdToTag(GetCurrentMachineTag(), id)); |
| 163 } | 163 } |
| 164 | 164 |
| 165 int64 SessionModelAssociator::GetSyncIdFromSessionTag(const std::string& tag) { | 165 int64 SessionModelAssociator::GetSyncIdFromSessionTag(const std::string& tag) { |
| 166 DCHECK(CalledOnValidThread()); | 166 DCHECK(CalledOnValidThread()); |
| 167 csync::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 167 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 168 csync::ReadNode node(&trans); | 168 syncer::ReadNode node(&trans); |
| 169 if (node.InitByClientTagLookup(SESSIONS, tag) != csync::BaseNode::INIT_OK) | 169 if (node.InitByClientTagLookup(SESSIONS, tag) != syncer::BaseNode::INIT_OK) |
| 170 return csync::kInvalidId; | 170 return syncer::kInvalidId; |
| 171 return node.GetId(); | 171 return node.GetId(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 const SyncedTabDelegate* | 174 const SyncedTabDelegate* |
| 175 SessionModelAssociator::GetChromeNodeFromSyncId(int64 sync_id) { | 175 SessionModelAssociator::GetChromeNodeFromSyncId(int64 sync_id) { |
| 176 NOTREACHED(); | 176 NOTREACHED(); |
| 177 return NULL; | 177 return NULL; |
| 178 } | 178 } |
| 179 | 179 |
| 180 bool SessionModelAssociator::InitSyncNodeFromChromeId( | 180 bool SessionModelAssociator::InitSyncNodeFromChromeId( |
| 181 const size_t& id, | 181 const size_t& id, |
| 182 csync::BaseNode* sync_node) { | 182 syncer::BaseNode* sync_node) { |
| 183 NOTREACHED(); | 183 NOTREACHED(); |
| 184 return false; | 184 return false; |
| 185 } | 185 } |
| 186 | 186 |
| 187 bool SessionModelAssociator::AssociateWindows(bool reload_tabs, | 187 bool SessionModelAssociator::AssociateWindows(bool reload_tabs, |
| 188 csync::SyncError* error) { | 188 syncer::SyncError* error) { |
| 189 DCHECK(CalledOnValidThread()); | 189 DCHECK(CalledOnValidThread()); |
| 190 std::string local_tag = GetCurrentMachineTag(); | 190 std::string local_tag = GetCurrentMachineTag(); |
| 191 sync_pb::SessionSpecifics specifics; | 191 sync_pb::SessionSpecifics specifics; |
| 192 specifics.set_session_tag(local_tag); | 192 specifics.set_session_tag(local_tag); |
| 193 sync_pb::SessionHeader* header_s = specifics.mutable_header(); | 193 sync_pb::SessionHeader* header_s = specifics.mutable_header(); |
| 194 SyncedSession* current_session = | 194 SyncedSession* current_session = |
| 195 synced_session_tracker_.GetSession(local_tag); | 195 synced_session_tracker_.GetSession(local_tag); |
| 196 current_session->modified_time = base::Time::Now(); | 196 current_session->modified_time = base::Time::Now(); |
| 197 header_s->set_client_name(current_session_name_); | 197 header_s->set_client_name(current_session_name_); |
| 198 header_s->set_device_type(GetLocalDeviceType()); | 198 header_s->set_device_type(GetLocalDeviceType()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 window_s, | 266 window_s, |
| 267 base::Time::Now(), | 267 base::Time::Now(), |
| 268 current_session->windows[window_id], | 268 current_session->windows[window_id], |
| 269 &synced_session_tracker_); | 269 &synced_session_tracker_); |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 } | 272 } |
| 273 // Free memory for closed windows and tabs. | 273 // Free memory for closed windows and tabs. |
| 274 synced_session_tracker_.CleanupSession(local_tag); | 274 synced_session_tracker_.CleanupSession(local_tag); |
| 275 | 275 |
| 276 csync::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 276 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 277 csync::WriteNode header_node(&trans); | 277 syncer::WriteNode header_node(&trans); |
| 278 if (header_node.InitByIdLookup(local_session_syncid_) != | 278 if (header_node.InitByIdLookup(local_session_syncid_) != |
| 279 csync::BaseNode::INIT_OK) { | 279 syncer::BaseNode::INIT_OK) { |
| 280 if (error) { | 280 if (error) { |
| 281 *error = error_handler_->CreateAndUploadError( | 281 *error = error_handler_->CreateAndUploadError( |
| 282 FROM_HERE, | 282 FROM_HERE, |
| 283 "Failed to load local session header node.", | 283 "Failed to load local session header node.", |
| 284 model_type()); | 284 model_type()); |
| 285 } | 285 } |
| 286 return false; | 286 return false; |
| 287 } | 287 } |
| 288 header_node.SetSessionSpecifics(specifics); | 288 header_node.SetSessionSpecifics(specifics); |
| 289 if (waiting_for_change_) QuitLoopForSubtleTesting(); | 289 if (waiting_for_change_) QuitLoopForSubtleTesting(); |
| 290 return true; | 290 return true; |
| 291 } | 291 } |
| 292 | 292 |
| 293 // Static. | 293 // Static. |
| 294 bool SessionModelAssociator::ShouldSyncWindow( | 294 bool SessionModelAssociator::ShouldSyncWindow( |
| 295 const SyncedWindowDelegate* window) { | 295 const SyncedWindowDelegate* window) { |
| 296 if (window->IsApp()) | 296 if (window->IsApp()) |
| 297 return false; | 297 return false; |
| 298 return window->IsTypeTabbed() || window->IsTypePopup(); | 298 return window->IsTypeTabbed() || window->IsTypePopup(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 bool SessionModelAssociator::AssociateTabs( | 301 bool SessionModelAssociator::AssociateTabs( |
| 302 const std::vector<SyncedTabDelegate*>& tabs, | 302 const std::vector<SyncedTabDelegate*>& tabs, |
| 303 csync::SyncError* error) { | 303 syncer::SyncError* error) { |
| 304 DCHECK(CalledOnValidThread()); | 304 DCHECK(CalledOnValidThread()); |
| 305 for (std::vector<SyncedTabDelegate*>::const_iterator i = tabs.begin(); | 305 for (std::vector<SyncedTabDelegate*>::const_iterator i = tabs.begin(); |
| 306 i != tabs.end(); | 306 i != tabs.end(); |
| 307 ++i) { | 307 ++i) { |
| 308 if (!AssociateTab(**i, error)) | 308 if (!AssociateTab(**i, error)) |
| 309 return false; | 309 return false; |
| 310 } | 310 } |
| 311 if (waiting_for_change_) QuitLoopForSubtleTesting(); | 311 if (waiting_for_change_) QuitLoopForSubtleTesting(); |
| 312 return true; | 312 return true; |
| 313 } | 313 } |
| 314 | 314 |
| 315 bool SessionModelAssociator::AssociateTab(const SyncedTabDelegate& tab, | 315 bool SessionModelAssociator::AssociateTab(const SyncedTabDelegate& tab, |
| 316 csync::SyncError* error) { | 316 syncer::SyncError* error) { |
| 317 DCHECK(CalledOnValidThread()); | 317 DCHECK(CalledOnValidThread()); |
| 318 int64 sync_id; | 318 int64 sync_id; |
| 319 SessionID::id_type tab_id = tab.GetSessionId(); | 319 SessionID::id_type tab_id = tab.GetSessionId(); |
| 320 if (tab.IsBeingDestroyed()) { | 320 if (tab.IsBeingDestroyed()) { |
| 321 // This tab is closing. | 321 // This tab is closing. |
| 322 TabLinksMap::iterator tab_iter = tab_map_.find(tab_id); | 322 TabLinksMap::iterator tab_iter = tab_map_.find(tab_id); |
| 323 if (tab_iter == tab_map_.end()) { | 323 if (tab_iter == tab_map_.end()) { |
| 324 // We aren't tracking this tab (for example, sync setting page). | 324 // We aren't tracking this tab (for example, sync setting page). |
| 325 return true; | 325 return true; |
| 326 } | 326 } |
| 327 tab_pool_.FreeTabNode(tab_iter->second->sync_id()); | 327 tab_pool_.FreeTabNode(tab_iter->second->sync_id()); |
| 328 load_consumer_.CancelAllRequestsForClientData(tab_id); | 328 load_consumer_.CancelAllRequestsForClientData(tab_id); |
| 329 tab_map_.erase(tab_iter); | 329 tab_map_.erase(tab_iter); |
| 330 return true; | 330 return true; |
| 331 } | 331 } |
| 332 | 332 |
| 333 if (!ShouldSyncTab(tab)) | 333 if (!ShouldSyncTab(tab)) |
| 334 return true; | 334 return true; |
| 335 | 335 |
| 336 TabLinksMap::iterator tab_map_iter = tab_map_.find(tab_id); | 336 TabLinksMap::iterator tab_map_iter = tab_map_.find(tab_id); |
| 337 TabLink* tab_link = NULL; | 337 TabLink* tab_link = NULL; |
| 338 if (tab_map_iter == tab_map_.end()) { | 338 if (tab_map_iter == tab_map_.end()) { |
| 339 // This is a new tab, get a sync node for it. | 339 // This is a new tab, get a sync node for it. |
| 340 sync_id = tab_pool_.GetFreeTabNode(); | 340 sync_id = tab_pool_.GetFreeTabNode(); |
| 341 if (sync_id == csync::kInvalidId) { | 341 if (sync_id == syncer::kInvalidId) { |
| 342 if (error) { | 342 if (error) { |
| 343 *error = error_handler_->CreateAndUploadError( | 343 *error = error_handler_->CreateAndUploadError( |
| 344 FROM_HERE, | 344 FROM_HERE, |
| 345 "Received invalid tab node from tab pool.", | 345 "Received invalid tab node from tab pool.", |
| 346 model_type()); | 346 model_type()); |
| 347 } | 347 } |
| 348 return false; | 348 return false; |
| 349 } | 349 } |
| 350 tab_link = new TabLink(sync_id, &tab); | 350 tab_link = new TabLink(sync_id, &tab); |
| 351 tab_map_[tab_id] = make_linked_ptr<TabLink>(tab_link); | 351 tab_map_[tab_id] = make_linked_ptr<TabLink>(tab_link); |
| 352 } else { | 352 } else { |
| 353 // This tab is already associated with a sync node, reuse it. | 353 // This tab is already associated with a sync node, reuse it. |
| 354 // Note: on some platforms the tab object may have changed, so we ensure | 354 // Note: on some platforms the tab object may have changed, so we ensure |
| 355 // the tab link is up to date. | 355 // the tab link is up to date. |
| 356 tab_link = tab_map_iter->second.get(); | 356 tab_link = tab_map_iter->second.get(); |
| 357 tab_map_iter->second->set_tab(&tab); | 357 tab_map_iter->second->set_tab(&tab); |
| 358 } | 358 } |
| 359 DCHECK(tab_link); | 359 DCHECK(tab_link); |
| 360 DCHECK_NE(tab_link->sync_id(), csync::kInvalidId); | 360 DCHECK_NE(tab_link->sync_id(), syncer::kInvalidId); |
| 361 | 361 |
| 362 DVLOG(1) << "Reloading tab " << tab_id << " from window " | 362 DVLOG(1) << "Reloading tab " << tab_id << " from window " |
| 363 << tab.GetWindowId(); | 363 << tab.GetWindowId(); |
| 364 return WriteTabContentsToSyncModel(tab_link, error); | 364 return WriteTabContentsToSyncModel(tab_link, error); |
| 365 } | 365 } |
| 366 | 366 |
| 367 bool SessionModelAssociator::WriteTabContentsToSyncModel( | 367 bool SessionModelAssociator::WriteTabContentsToSyncModel( |
| 368 TabLink* tab_link, | 368 TabLink* tab_link, |
| 369 csync::SyncError* error) { | 369 syncer::SyncError* error) { |
| 370 DCHECK(CalledOnValidThread()); | 370 DCHECK(CalledOnValidThread()); |
| 371 const SyncedTabDelegate& tab = *(tab_link->tab()); | 371 const SyncedTabDelegate& tab = *(tab_link->tab()); |
| 372 const SyncedWindowDelegate& window = | 372 const SyncedWindowDelegate& window = |
| 373 *SyncedWindowDelegate::FindSyncedWindowDelegateWithId( | 373 *SyncedWindowDelegate::FindSyncedWindowDelegateWithId( |
| 374 tab.GetWindowId()); | 374 tab.GetWindowId()); |
| 375 int64 sync_id = tab_link->sync_id(); | 375 int64 sync_id = tab_link->sync_id(); |
| 376 GURL old_tab_url = tab_link->url(); | 376 GURL old_tab_url = tab_link->url(); |
| 377 | 377 |
| 378 // Load the last stored version of this tab so we can compare changes. If this | 378 // Load the last stored version of this tab so we can compare changes. If this |
| 379 // is a new tab, session_tab will be a blank/newly created SessionTab object. | 379 // is a new tab, session_tab will be a blank/newly created SessionTab object. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 393 // transaction to avoid jank. | 393 // transaction to avoid jank. |
| 394 tab_link->set_url(new_url); | 394 tab_link->set_url(new_url); |
| 395 if (new_url != old_tab_url) { | 395 if (new_url != old_tab_url) { |
| 396 LoadFaviconForTab(tab_link); | 396 LoadFaviconForTab(tab_link); |
| 397 } | 397 } |
| 398 | 398 |
| 399 // Update our last modified time. | 399 // Update our last modified time. |
| 400 synced_session_tracker_.GetSession(GetCurrentMachineTag())->modified_time = | 400 synced_session_tracker_.GetSession(GetCurrentMachineTag())->modified_time = |
| 401 base::Time::Now(); | 401 base::Time::Now(); |
| 402 | 402 |
| 403 csync::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 403 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 404 csync::WriteNode tab_node(&trans); | 404 syncer::WriteNode tab_node(&trans); |
| 405 if (tab_node.InitByIdLookup(sync_id) != csync::BaseNode::INIT_OK) { | 405 if (tab_node.InitByIdLookup(sync_id) != syncer::BaseNode::INIT_OK) { |
| 406 if (error) { | 406 if (error) { |
| 407 *error = error_handler_->CreateAndUploadError( | 407 *error = error_handler_->CreateAndUploadError( |
| 408 FROM_HERE, | 408 FROM_HERE, |
| 409 "Failed to look up local tab node", | 409 "Failed to look up local tab node", |
| 410 model_type()); | 410 model_type()); |
| 411 } | 411 } |
| 412 return false; | 412 return false; |
| 413 } | 413 } |
| 414 | 414 |
| 415 if (new_url == old_tab_url) { | 415 if (new_url == old_tab_url) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 499 |
| 500 // If this navigation is an old one, reuse the old timestamp. Otherwise we | 500 // If this navigation is an old one, reuse the old timestamp. Otherwise we |
| 501 // leave the timestamp as the current time. | 501 // leave the timestamp as the current time. |
| 502 if (prev_nav_iter != prev_tab->synced_tab_navigations.end() && | 502 if (prev_nav_iter != prev_tab->synced_tab_navigations.end() && |
| 503 prev_nav_iter->unique_id() == entry->GetUniqueID()) { | 503 prev_nav_iter->unique_id() == entry->GetUniqueID()) { |
| 504 // Check that we haven't gone back/foward in the nav stack to this page | 504 // Check that we haven't gone back/foward in the nav stack to this page |
| 505 // (if so, we want to refresh the timestamp). | 505 // (if so, we want to refresh the timestamp). |
| 506 if (!(current_index != prev_tab->current_navigation_index && | 506 if (!(current_index != prev_tab->current_navigation_index && |
| 507 current_index == i)) { | 507 current_index == i)) { |
| 508 sync_nav->set_timestamp( | 508 sync_nav->set_timestamp( |
| 509 csync::TimeToProtoTime(prev_nav_iter->timestamp())); | 509 syncer::TimeToProtoTime(prev_nav_iter->timestamp())); |
| 510 DVLOG(2) << "Nav to " << sync_nav->virtual_url() << " already known, " | 510 DVLOG(2) << "Nav to " << sync_nav->virtual_url() << " already known, " |
| 511 << "reusing old timestamp " << sync_nav->timestamp(); | 511 << "reusing old timestamp " << sync_nav->timestamp(); |
| 512 } | 512 } |
| 513 // Even if the user went back in their history, they may have skipped | 513 // Even if the user went back in their history, they may have skipped |
| 514 // over navigations, so the subsequent navigation entries may need their | 514 // over navigations, so the subsequent navigation entries may need their |
| 515 // old timestamps preserved. | 515 // old timestamps preserved. |
| 516 ++prev_nav_iter; | 516 ++prev_nav_iter; |
| 517 } else if (current_index != i && | 517 } else if (current_index != i && |
| 518 prev_tab->synced_tab_navigations.empty()) { | 518 prev_tab->synced_tab_navigations.empty()) { |
| 519 // If this is a new tab, and has more than one navigation, we don't | 519 // If this is a new tab, and has more than one navigation, we don't |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 DCHECK(tab_link); | 573 DCHECK(tab_link); |
| 574 DCHECK(tab_link->url().is_valid()); | 574 DCHECK(tab_link->url().is_valid()); |
| 575 // The tab_link holds the current url. Because this load request would have | 575 // The tab_link holds the current url. Because this load request would have |
| 576 // been canceled if the url had changed, we know the url must still be | 576 // been canceled if the url had changed, we know the url must still be |
| 577 // up to date. | 577 // up to date. |
| 578 | 578 |
| 579 if (favicon.is_valid()) { | 579 if (favicon.is_valid()) { |
| 580 DCHECK_EQ(handle, tab_link->favicon_load_handle()); | 580 DCHECK_EQ(handle, tab_link->favicon_load_handle()); |
| 581 tab_link->set_favicon_load_handle(0); | 581 tab_link->set_favicon_load_handle(0); |
| 582 DCHECK_EQ(favicon.icon_type, history::FAVICON); | 582 DCHECK_EQ(favicon.icon_type, history::FAVICON); |
| 583 DCHECK_NE(tab_link->sync_id(), csync::kInvalidId); | 583 DCHECK_NE(tab_link->sync_id(), syncer::kInvalidId); |
| 584 // Load the sync tab node and update the favicon data. | 584 // Load the sync tab node and update the favicon data. |
| 585 csync::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 585 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 586 csync::WriteNode tab_node(&trans); | 586 syncer::WriteNode tab_node(&trans); |
| 587 if (tab_node.InitByIdLookup(tab_link->sync_id()) != | 587 if (tab_node.InitByIdLookup(tab_link->sync_id()) != |
| 588 csync::BaseNode::INIT_OK) { | 588 syncer::BaseNode::INIT_OK) { |
| 589 LOG(WARNING) << "Failed to load sync tab node for tab id " << tab_id | 589 LOG(WARNING) << "Failed to load sync tab node for tab id " << tab_id |
| 590 << " and url " << tab_link->url().spec(); | 590 << " and url " << tab_link->url().spec(); |
| 591 return; | 591 return; |
| 592 } | 592 } |
| 593 sync_pb::SessionSpecifics session_specifics = | 593 sync_pb::SessionSpecifics session_specifics = |
| 594 tab_node.GetSessionSpecifics(); | 594 tab_node.GetSessionSpecifics(); |
| 595 DCHECK(session_specifics.has_tab()); | 595 DCHECK(session_specifics.has_tab()); |
| 596 sync_pb::SessionTab* tab = session_specifics.mutable_tab(); | 596 sync_pb::SessionTab* tab = session_specifics.mutable_tab(); |
| 597 if (favicon.image_data->size() > 0) { | 597 if (favicon.image_data->size() > 0) { |
| 598 DVLOG(1) << "Storing session favicon for " | 598 DVLOG(1) << "Storing session favicon for " |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 case content::PAGE_TRANSITION_SERVER_REDIRECT: | 709 case content::PAGE_TRANSITION_SERVER_REDIRECT: |
| 710 tab_navigation->set_navigation_qualifier( | 710 tab_navigation->set_navigation_qualifier( |
| 711 sync_pb::SyncEnums_PageTransitionQualifier_SERVER_REDIRECT); | 711 sync_pb::SyncEnums_PageTransitionQualifier_SERVER_REDIRECT); |
| 712 break; | 712 break; |
| 713 default: | 713 default: |
| 714 tab_navigation->set_page_transition( | 714 tab_navigation->set_page_transition( |
| 715 sync_pb::SyncEnums_PageTransition_TYPED); | 715 sync_pb::SyncEnums_PageTransition_TYPED); |
| 716 } | 716 } |
| 717 tab_navigation->set_unique_id(navigation.GetUniqueID()); | 717 tab_navigation->set_unique_id(navigation.GetUniqueID()); |
| 718 tab_navigation->set_timestamp( | 718 tab_navigation->set_timestamp( |
| 719 csync::TimeToProtoTime(base::Time::Now())); | 719 syncer::TimeToProtoTime(base::Time::Now())); |
| 720 } | 720 } |
| 721 | 721 |
| 722 void SessionModelAssociator::Associate(const SyncedTabDelegate* tab, | 722 void SessionModelAssociator::Associate(const SyncedTabDelegate* tab, |
| 723 int64 sync_id) { | 723 int64 sync_id) { |
| 724 NOTIMPLEMENTED(); | 724 NOTIMPLEMENTED(); |
| 725 } | 725 } |
| 726 | 726 |
| 727 void SessionModelAssociator::Disassociate(int64 sync_id) { | 727 void SessionModelAssociator::Disassociate(int64 sync_id) { |
| 728 DCHECK(CalledOnValidThread()); | 728 DCHECK(CalledOnValidThread()); |
| 729 NOTIMPLEMENTED(); | 729 NOTIMPLEMENTED(); |
| 730 } | 730 } |
| 731 | 731 |
| 732 csync::SyncError SessionModelAssociator::AssociateModels() { | 732 syncer::SyncError SessionModelAssociator::AssociateModels() { |
| 733 DCHECK(CalledOnValidThread()); | 733 DCHECK(CalledOnValidThread()); |
| 734 csync::SyncError error; | 734 syncer::SyncError error; |
| 735 | 735 |
| 736 // Ensure that we disassociated properly, otherwise memory might leak. | 736 // Ensure that we disassociated properly, otherwise memory might leak. |
| 737 DCHECK(synced_session_tracker_.Empty()); | 737 DCHECK(synced_session_tracker_.Empty()); |
| 738 DCHECK_EQ(0U, tab_pool_.capacity()); | 738 DCHECK_EQ(0U, tab_pool_.capacity()); |
| 739 | 739 |
| 740 local_session_syncid_ = csync::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 csync::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 745 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 746 | 746 |
| 747 csync::ReadNode root(&trans); | 747 syncer::ReadNode root(&trans); |
| 748 if (root.InitByTagLookup(syncable::ModelTypeToRootTag(model_type())) != | 748 if (root.InitByTagLookup(syncable::ModelTypeToRootTag(model_type())) != |
| 749 csync::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); |
| 759 // The session name is retrieved asynchronously so it might not come back | 759 // The session name is retrieved asynchronously so it might not come back |
| 760 // for the writing of the session. However, we write to the session often | 760 // for the writing of the session. However, we write to the session often |
| 761 // enough (on every navigation) that we'll pick it up quickly. | 761 // enough (on every navigation) that we'll pick it up quickly. |
| 762 InitializeCurrentSessionName(); | 762 InitializeCurrentSessionName(); |
| 763 } | 763 } |
| 764 synced_session_tracker_.SetLocalSessionTag(current_machine_tag_); | 764 synced_session_tracker_.SetLocalSessionTag(current_machine_tag_); |
| 765 if (!UpdateAssociationsFromSyncModel(root, &trans, &error)) { | 765 if (!UpdateAssociationsFromSyncModel(root, &trans, &error)) { |
| 766 DCHECK(error.IsSet()); | 766 DCHECK(error.IsSet()); |
| 767 return error; | 767 return error; |
| 768 } | 768 } |
| 769 | 769 |
| 770 if (local_session_syncid_ == csync::kInvalidId) { | 770 if (local_session_syncid_ == syncer::kInvalidId) { |
| 771 // The sync db didn't have a header node for us, we need to create one. | 771 // The sync db didn't have a header node for us, we need to create one. |
| 772 csync::WriteNode write_node(&trans); | 772 syncer::WriteNode write_node(&trans); |
| 773 csync::WriteNode::InitUniqueByCreationResult result = | 773 syncer::WriteNode::InitUniqueByCreationResult result = |
| 774 write_node.InitUniqueByCreation(SESSIONS, root, current_machine_tag_); | 774 write_node.InitUniqueByCreation(SESSIONS, root, current_machine_tag_); |
| 775 if (result != csync::WriteNode::INIT_SUCCESS) { | 775 if (result != syncer::WriteNode::INIT_SUCCESS) { |
| 776 // If we can't look it up, and we can't create it, chances are there's | 776 // If we can't look it up, and we can't create it, chances are there's |
| 777 // a pre-existing node that has encryption issues. But, since we can't | 777 // a pre-existing node that has encryption issues. But, since we can't |
| 778 // load the item, we can't remove it, and error out at this point. | 778 // load the item, we can't remove it, and error out at this point. |
| 779 return error_handler_->CreateAndUploadError( | 779 return error_handler_->CreateAndUploadError( |
| 780 FROM_HERE, | 780 FROM_HERE, |
| 781 "Failed to create sessions header sync node.", | 781 "Failed to create sessions header sync node.", |
| 782 model_type()); | 782 model_type()); |
| 783 } | 783 } |
| 784 | 784 |
| 785 // Write the initial values to the specifics so that in case of a crash or | 785 // Write the initial values to the specifics so that in case of a crash or |
| (...skipping 14 matching lines...) Expand all Loading... |
| 800 if (!UpdateSyncModelDataFromClient(&error)) { | 800 if (!UpdateSyncModelDataFromClient(&error)) { |
| 801 DCHECK(error.IsSet()); | 801 DCHECK(error.IsSet()); |
| 802 return error; | 802 return error; |
| 803 } | 803 } |
| 804 | 804 |
| 805 DVLOG(1) << "Session models associated."; | 805 DVLOG(1) << "Session models associated."; |
| 806 DCHECK(!error.IsSet()); | 806 DCHECK(!error.IsSet()); |
| 807 return error; | 807 return error; |
| 808 } | 808 } |
| 809 | 809 |
| 810 csync::SyncError SessionModelAssociator::DisassociateModels() { | 810 syncer::SyncError SessionModelAssociator::DisassociateModels() { |
| 811 DCHECK(CalledOnValidThread()); | 811 DCHECK(CalledOnValidThread()); |
| 812 DVLOG(1) << "Disassociating local session " << GetCurrentMachineTag(); | 812 DVLOG(1) << "Disassociating local session " << GetCurrentMachineTag(); |
| 813 synced_session_tracker_.Clear(); | 813 synced_session_tracker_.Clear(); |
| 814 tab_map_.clear(); | 814 tab_map_.clear(); |
| 815 tab_pool_.clear(); | 815 tab_pool_.clear(); |
| 816 local_session_syncid_ = csync::kInvalidId; | 816 local_session_syncid_ = syncer::kInvalidId; |
| 817 current_machine_tag_ = ""; | 817 current_machine_tag_ = ""; |
| 818 current_session_name_ = ""; | 818 current_session_name_ = ""; |
| 819 load_consumer_.CancelAllRequests(); | 819 load_consumer_.CancelAllRequests(); |
| 820 synced_favicons_.clear(); | 820 synced_favicons_.clear(); |
| 821 synced_favicon_pages_.clear(); | 821 synced_favicon_pages_.clear(); |
| 822 | 822 |
| 823 // There is no local model stored with which to disassociate, just notify | 823 // There is no local model stored with which to disassociate, just notify |
| 824 // foreign session handlers. | 824 // foreign session handlers. |
| 825 content::NotificationService::current()->Notify( | 825 content::NotificationService::current()->Notify( |
| 826 chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, | 826 chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, |
| 827 content::Source<Profile>(sync_service_->profile()), | 827 content::Source<Profile>(sync_service_->profile()), |
| 828 content::NotificationService::NoDetails()); | 828 content::NotificationService::NoDetails()); |
| 829 return csync::SyncError(); | 829 return syncer::SyncError(); |
| 830 } | 830 } |
| 831 | 831 |
| 832 void SessionModelAssociator::InitializeCurrentMachineTag( | 832 void SessionModelAssociator::InitializeCurrentMachineTag( |
| 833 csync::WriteTransaction* trans) { | 833 syncer::WriteTransaction* trans) { |
| 834 DCHECK(CalledOnValidThread()); | 834 DCHECK(CalledOnValidThread()); |
| 835 DCHECK(current_machine_tag_.empty()); | 835 DCHECK(current_machine_tag_.empty()); |
| 836 std::string persisted_guid; | 836 std::string persisted_guid; |
| 837 if (pref_service_) | 837 if (pref_service_) |
| 838 persisted_guid = pref_service_->GetString(kSyncSessionsGUID); | 838 persisted_guid = pref_service_->GetString(kSyncSessionsGUID); |
| 839 if (!persisted_guid.empty()) { | 839 if (!persisted_guid.empty()) { |
| 840 current_machine_tag_ = persisted_guid; | 840 current_machine_tag_ = persisted_guid; |
| 841 DVLOG(1) << "Restoring persisted session sync guid: " | 841 DVLOG(1) << "Restoring persisted session sync guid: " |
| 842 << persisted_guid; | 842 << persisted_guid; |
| 843 } else { | 843 } else { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 DCHECK(CalledOnValidThread()); | 884 DCHECK(CalledOnValidThread()); |
| 885 if (setup_for_test_) { | 885 if (setup_for_test_) { |
| 886 // We post this task to break out of any transactional locks a caller may be | 886 // We post this task to break out of any transactional locks a caller may be |
| 887 // holding. | 887 // holding. |
| 888 MessageLoop::current()->PostTask( | 888 MessageLoop::current()->PostTask( |
| 889 FROM_HERE, | 889 FROM_HERE, |
| 890 base::Bind(&SessionModelAssociator::OnSessionNameInitialized, | 890 base::Bind(&SessionModelAssociator::OnSessionNameInitialized, |
| 891 AsWeakPtr(), | 891 AsWeakPtr(), |
| 892 std::string("TestSessionName"))); | 892 std::string("TestSessionName"))); |
| 893 } else { | 893 } else { |
| 894 csync::GetSessionName( | 894 syncer::GetSessionName( |
| 895 BrowserThread::GetBlockingPool(), | 895 BrowserThread::GetBlockingPool(), |
| 896 base::Bind(&SessionModelAssociator::OnSessionNameInitialized, | 896 base::Bind(&SessionModelAssociator::OnSessionNameInitialized, |
| 897 AsWeakPtr())); | 897 AsWeakPtr())); |
| 898 } | 898 } |
| 899 } | 899 } |
| 900 | 900 |
| 901 bool SessionModelAssociator::UpdateAssociationsFromSyncModel( | 901 bool SessionModelAssociator::UpdateAssociationsFromSyncModel( |
| 902 const csync::ReadNode& root, | 902 const syncer::ReadNode& root, |
| 903 csync::WriteTransaction* trans, | 903 syncer::WriteTransaction* trans, |
| 904 csync::SyncError* error) { | 904 syncer::SyncError* error) { |
| 905 DCHECK(CalledOnValidThread()); | 905 DCHECK(CalledOnValidThread()); |
| 906 DCHECK(tab_pool_.empty()); | 906 DCHECK(tab_pool_.empty()); |
| 907 DCHECK_EQ(local_session_syncid_, csync::kInvalidId); | 907 DCHECK_EQ(local_session_syncid_, syncer::kInvalidId); |
| 908 | 908 |
| 909 // Iterate through the nodes and associate any foreign sessions. | 909 // Iterate through the nodes and associate any foreign sessions. |
| 910 int64 id = root.GetFirstChildId(); | 910 int64 id = root.GetFirstChildId(); |
| 911 while (id != csync::kInvalidId) { | 911 while (id != syncer::kInvalidId) { |
| 912 csync::WriteNode sync_node(trans); | 912 syncer::WriteNode sync_node(trans); |
| 913 if (sync_node.InitByIdLookup(id) != csync::BaseNode::INIT_OK) { | 913 if (sync_node.InitByIdLookup(id) != syncer::BaseNode::INIT_OK) { |
| 914 if (error) { | 914 if (error) { |
| 915 *error = error_handler_->CreateAndUploadError( | 915 *error = error_handler_->CreateAndUploadError( |
| 916 FROM_HERE, | 916 FROM_HERE, |
| 917 "Failed to load sync node", | 917 "Failed to load sync node", |
| 918 model_type()); | 918 model_type()); |
| 919 } | 919 } |
| 920 return false; | 920 return false; |
| 921 } | 921 } |
| 922 int64 next_id = sync_node.GetSuccessorId(); | 922 int64 next_id = sync_node.GetSuccessorId(); |
| 923 | 923 |
| 924 const sync_pb::SessionSpecifics& specifics = | 924 const sync_pb::SessionSpecifics& specifics = |
| 925 sync_node.GetSessionSpecifics(); | 925 sync_node.GetSessionSpecifics(); |
| 926 const base::Time& modification_time = sync_node.GetModificationTime(); | 926 const base::Time& modification_time = sync_node.GetModificationTime(); |
| 927 if (specifics.session_tag().empty()) { | 927 if (specifics.session_tag().empty()) { |
| 928 // This is a corrupted node. Just delete it. | 928 // This is a corrupted node. Just delete it. |
| 929 LOG(WARNING) << "Found node with no session tag, deleting."; | 929 LOG(WARNING) << "Found node with no session tag, deleting."; |
| 930 sync_node.Remove(); | 930 sync_node.Remove(); |
| 931 } else if (specifics.session_tag() != GetCurrentMachineTag()) { | 931 } else if (specifics.session_tag() != GetCurrentMachineTag()) { |
| 932 AssociateForeignSpecifics(specifics, modification_time); | 932 AssociateForeignSpecifics(specifics, modification_time); |
| 933 } else { | 933 } else { |
| 934 // This is previously stored local session information. | 934 // This is previously stored local session information. |
| 935 if (specifics.has_header() && | 935 if (specifics.has_header() && |
| 936 local_session_syncid_ == csync::kInvalidId) { | 936 local_session_syncid_ == syncer::kInvalidId) { |
| 937 // This is our previous header node, reuse it. | 937 // This is our previous header node, reuse it. |
| 938 local_session_syncid_ = id; | 938 local_session_syncid_ = id; |
| 939 if (specifics.header().has_client_name()) { | 939 if (specifics.header().has_client_name()) { |
| 940 current_session_name_ = specifics.header().client_name(); | 940 current_session_name_ = specifics.header().client_name(); |
| 941 } | 941 } |
| 942 } else { | 942 } else { |
| 943 if (specifics.has_header()) { | 943 if (specifics.has_header()) { |
| 944 LOG(WARNING) << "Found more than one session header node with local " | 944 LOG(WARNING) << "Found more than one session header node with local " |
| 945 << " tag."; | 945 << " tag."; |
| 946 } else if (!specifics.has_tab()) { | 946 } else if (!specifics.has_tab()) { |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 break; | 1264 break; |
| 1265 case sync_pb::SyncEnums_PageTransitionQualifier_SERVER_REDIRECT: | 1265 case sync_pb::SyncEnums_PageTransitionQualifier_SERVER_REDIRECT: |
| 1266 transition = content::PAGE_TRANSITION_SERVER_REDIRECT; | 1266 transition = content::PAGE_TRANSITION_SERVER_REDIRECT; |
| 1267 break; | 1267 break; |
| 1268 default: | 1268 default: |
| 1269 transition = content::PAGE_TRANSITION_TYPED; | 1269 transition = content::PAGE_TRANSITION_TYPED; |
| 1270 } | 1270 } |
| 1271 } | 1271 } |
| 1272 } | 1272 } |
| 1273 if (specifics.has_timestamp()) { | 1273 if (specifics.has_timestamp()) { |
| 1274 timestamp = csync::ProtoTimeToTime(specifics.timestamp()); | 1274 timestamp = syncer::ProtoTimeToTime(specifics.timestamp()); |
| 1275 } | 1275 } |
| 1276 if (specifics.has_unique_id()) { | 1276 if (specifics.has_unique_id()) { |
| 1277 unique_id = specifics.unique_id(); | 1277 unique_id = specifics.unique_id(); |
| 1278 } | 1278 } |
| 1279 SyncedTabNavigation tab_navigation( | 1279 SyncedTabNavigation tab_navigation( |
| 1280 index, virtual_url, | 1280 index, virtual_url, |
| 1281 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), title, | 1281 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), title, |
| 1282 state, transition, unique_id, timestamp); | 1282 state, transition, unique_id, timestamp); |
| 1283 // We insert it twice, once for our SyncedTabNavigations, once for the normal | 1283 // We insert it twice, once for our SyncedTabNavigations, once for the normal |
| 1284 // TabNavigation (used by the session restore UI). | 1284 // TabNavigation (used by the session restore UI). |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 synced_favicons_[favicon_source.spec()] = | 1320 synced_favicons_[favicon_source.spec()] = |
| 1321 make_linked_ptr<SyncedFaviconInfo>(new SyncedFaviconInfo(favicon)); | 1321 make_linked_ptr<SyncedFaviconInfo>(new SyncedFaviconInfo(favicon)); |
| 1322 } else { | 1322 } else { |
| 1323 favicon_iter->second->data = favicon; | 1323 favicon_iter->second->data = favicon; |
| 1324 ++favicon_iter->second->usage_count; | 1324 ++favicon_iter->second->usage_count; |
| 1325 } | 1325 } |
| 1326 synced_favicon_pages_[navigation_url.spec()] = favicon_source.spec(); | 1326 synced_favicon_pages_[navigation_url.spec()] = favicon_source.spec(); |
| 1327 } | 1327 } |
| 1328 | 1328 |
| 1329 bool SessionModelAssociator::UpdateSyncModelDataFromClient( | 1329 bool SessionModelAssociator::UpdateSyncModelDataFromClient( |
| 1330 csync::SyncError* error) { | 1330 syncer::SyncError* error) { |
| 1331 DCHECK(CalledOnValidThread()); | 1331 DCHECK(CalledOnValidThread()); |
| 1332 | 1332 |
| 1333 // Associate all open windows and their tabs. | 1333 // Associate all open windows and their tabs. |
| 1334 return AssociateWindows(true, error); | 1334 return AssociateWindows(true, error); |
| 1335 } | 1335 } |
| 1336 | 1336 |
| 1337 SessionModelAssociator::TabNodePool::TabNodePool( | 1337 SessionModelAssociator::TabNodePool::TabNodePool( |
| 1338 ProfileSyncService* sync_service) | 1338 ProfileSyncService* sync_service) |
| 1339 : tab_pool_fp_(-1), | 1339 : tab_pool_fp_(-1), |
| 1340 sync_service_(sync_service) { | 1340 sync_service_(sync_service) { |
| 1341 } | 1341 } |
| 1342 | 1342 |
| 1343 SessionModelAssociator::TabNodePool::~TabNodePool() {} | 1343 SessionModelAssociator::TabNodePool::~TabNodePool() {} |
| 1344 | 1344 |
| 1345 void SessionModelAssociator::TabNodePool::AddTabNode(int64 sync_id) { | 1345 void SessionModelAssociator::TabNodePool::AddTabNode(int64 sync_id) { |
| 1346 tab_syncid_pool_.resize(tab_syncid_pool_.size() + 1); | 1346 tab_syncid_pool_.resize(tab_syncid_pool_.size() + 1); |
| 1347 tab_syncid_pool_[static_cast<size_t>(++tab_pool_fp_)] = sync_id; | 1347 tab_syncid_pool_[static_cast<size_t>(++tab_pool_fp_)] = sync_id; |
| 1348 } | 1348 } |
| 1349 | 1349 |
| 1350 int64 SessionModelAssociator::TabNodePool::GetFreeTabNode() { | 1350 int64 SessionModelAssociator::TabNodePool::GetFreeTabNode() { |
| 1351 DCHECK_GT(machine_tag_.length(), 0U); | 1351 DCHECK_GT(machine_tag_.length(), 0U); |
| 1352 if (tab_pool_fp_ == -1) { | 1352 if (tab_pool_fp_ == -1) { |
| 1353 // Tab pool has no free nodes, allocate new one. | 1353 // Tab pool has no free nodes, allocate new one. |
| 1354 csync::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1354 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1355 csync::ReadNode root(&trans); | 1355 syncer::ReadNode root(&trans); |
| 1356 if (root.InitByTagLookup(kSessionsTag) != csync::BaseNode::INIT_OK) { | 1356 if (root.InitByTagLookup(kSessionsTag) != syncer::BaseNode::INIT_OK) { |
| 1357 LOG(ERROR) << kNoSessionsFolderError; | 1357 LOG(ERROR) << kNoSessionsFolderError; |
| 1358 return csync::kInvalidId; | 1358 return syncer::kInvalidId; |
| 1359 } | 1359 } |
| 1360 size_t tab_node_id = tab_syncid_pool_.size(); | 1360 size_t tab_node_id = tab_syncid_pool_.size(); |
| 1361 std::string tab_node_tag = TabIdToTag(machine_tag_, tab_node_id); | 1361 std::string tab_node_tag = TabIdToTag(machine_tag_, tab_node_id); |
| 1362 csync::WriteNode tab_node(&trans); | 1362 syncer::WriteNode tab_node(&trans); |
| 1363 csync::WriteNode::InitUniqueByCreationResult result = | 1363 syncer::WriteNode::InitUniqueByCreationResult result = |
| 1364 tab_node.InitUniqueByCreation(SESSIONS, root, tab_node_tag); | 1364 tab_node.InitUniqueByCreation(SESSIONS, root, tab_node_tag); |
| 1365 if (result != csync::WriteNode::INIT_SUCCESS) { | 1365 if (result != syncer::WriteNode::INIT_SUCCESS) { |
| 1366 LOG(ERROR) << "Could not create new node with tag " | 1366 LOG(ERROR) << "Could not create new node with tag " |
| 1367 << tab_node_tag << "!"; | 1367 << tab_node_tag << "!"; |
| 1368 return csync::kInvalidId; | 1368 return syncer::kInvalidId; |
| 1369 } | 1369 } |
| 1370 // We fill the new node with just enough data so that in case of a crash/bug | 1370 // We fill the new node with just enough data so that in case of a crash/bug |
| 1371 // we can identify the node as our own on re-association and reuse it. | 1371 // we can identify the node as our own on re-association and reuse it. |
| 1372 tab_node.SetTitle(UTF8ToWide(tab_node_tag)); | 1372 tab_node.SetTitle(UTF8ToWide(tab_node_tag)); |
| 1373 sync_pb::SessionSpecifics specifics; | 1373 sync_pb::SessionSpecifics specifics; |
| 1374 specifics.set_session_tag(machine_tag_); | 1374 specifics.set_session_tag(machine_tag_); |
| 1375 specifics.set_tab_node_id(tab_node_id); | 1375 specifics.set_tab_node_id(tab_node_id); |
| 1376 tab_node.SetSessionSpecifics(specifics); | 1376 tab_node.SetSessionSpecifics(specifics); |
| 1377 | 1377 |
| 1378 // Grow the pool by 1 since we created a new node. We don't actually need | 1378 // Grow the pool by 1 since we created a new node. We don't actually need |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1485 LOG(ERROR) << "Attempting to delete local session. This is not currently " | 1485 LOG(ERROR) << "Attempting to delete local session. This is not currently " |
| 1486 << "supported."; | 1486 << "supported."; |
| 1487 return; | 1487 return; |
| 1488 } | 1488 } |
| 1489 | 1489 |
| 1490 if (!DisassociateForeignSession(tag)) { | 1490 if (!DisassociateForeignSession(tag)) { |
| 1491 // We don't have any data for this session, our work here is done! | 1491 // We don't have any data for this session, our work here is done! |
| 1492 return; | 1492 return; |
| 1493 } | 1493 } |
| 1494 | 1494 |
| 1495 csync::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1495 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1496 csync::ReadNode root(&trans); | 1496 syncer::ReadNode root(&trans); |
| 1497 if (root.InitByTagLookup(kSessionsTag) != csync::BaseNode::INIT_OK) { | 1497 if (root.InitByTagLookup(kSessionsTag) != syncer::BaseNode::INIT_OK) { |
| 1498 LOG(ERROR) << kNoSessionsFolderError; | 1498 LOG(ERROR) << kNoSessionsFolderError; |
| 1499 return; | 1499 return; |
| 1500 } | 1500 } |
| 1501 int64 id = root.GetFirstChildId(); | 1501 int64 id = root.GetFirstChildId(); |
| 1502 while (id != csync::kInvalidId) { | 1502 while (id != syncer::kInvalidId) { |
| 1503 csync::WriteNode sync_node(&trans); | 1503 syncer::WriteNode sync_node(&trans); |
| 1504 if (sync_node.InitByIdLookup(id) != csync::BaseNode::INIT_OK) { | 1504 if (sync_node.InitByIdLookup(id) != syncer::BaseNode::INIT_OK) { |
| 1505 LOG(ERROR) << "Failed to fetch sync node for id " << id; | 1505 LOG(ERROR) << "Failed to fetch sync node for id " << id; |
| 1506 continue; | 1506 continue; |
| 1507 } | 1507 } |
| 1508 id = sync_node.GetSuccessorId(); | 1508 id = sync_node.GetSuccessorId(); |
| 1509 const sync_pb::SessionSpecifics& specifics = | 1509 const sync_pb::SessionSpecifics& specifics = |
| 1510 sync_node.GetSessionSpecifics(); | 1510 sync_node.GetSessionSpecifics(); |
| 1511 if (specifics.session_tag() == tag) | 1511 if (specifics.session_tag() == tag) |
| 1512 sync_node.Remove(); | 1512 sync_node.Remove(); |
| 1513 } | 1513 } |
| 1514 } | 1514 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 waiting_for_change_ = true; | 1572 waiting_for_change_ = true; |
| 1573 MessageLoop::current()->PostDelayedTask( | 1573 MessageLoop::current()->PostDelayedTask( |
| 1574 FROM_HERE, | 1574 FROM_HERE, |
| 1575 base::Bind(&SessionModelAssociator::QuitLoopForSubtleTesting, | 1575 base::Bind(&SessionModelAssociator::QuitLoopForSubtleTesting, |
| 1576 test_weak_factory_.GetWeakPtr()), | 1576 test_weak_factory_.GetWeakPtr()), |
| 1577 base::TimeDelta::FromMilliseconds(timeout_milliseconds)); | 1577 base::TimeDelta::FromMilliseconds(timeout_milliseconds)); |
| 1578 } | 1578 } |
| 1579 | 1579 |
| 1580 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1580 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
| 1581 // We only access the cryptographer while holding a transaction. | 1581 // We only access the cryptographer while holding a transaction. |
| 1582 csync::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1582 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1583 const syncable::ModelTypeSet encrypted_types = | 1583 const syncable::ModelTypeSet encrypted_types = |
| 1584 csync::GetEncryptedTypes(&trans); | 1584 syncer::GetEncryptedTypes(&trans); |
| 1585 return !encrypted_types.Has(SESSIONS) || | 1585 return !encrypted_types.Has(SESSIONS) || |
| 1586 sync_service_->IsCryptographerReady(&trans); | 1586 sync_service_->IsCryptographerReady(&trans); |
| 1587 } | 1587 } |
| 1588 | 1588 |
| 1589 } // namespace browser_sync | 1589 } // namespace browser_sync |
| OLD | NEW |