| 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_change_processor.h" | 5 #include "chrome/browser/sync/glue/session_change_processor.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // it being a modified tab, we know the tab is active (so we won't do | 206 // it being a modified tab, we know the tab is active (so we won't do |
| 207 // refreshes just because the refresh page is open in a background tab). | 207 // refreshes just because the refresh page is open in a background tab). |
| 208 if (!modified_tabs.empty()) { | 208 if (!modified_tabs.empty()) { |
| 209 SyncedTabDelegate* tab = modified_tabs.front(); | 209 SyncedTabDelegate* tab = modified_tabs.front(); |
| 210 const content::NavigationEntry* entry = tab->GetActiveEntry(); | 210 const content::NavigationEntry* entry = tab->GetActiveEntry(); |
| 211 if (!tab->IsBeingDestroyed() && | 211 if (!tab->IsBeingDestroyed() && |
| 212 entry && | 212 entry && |
| 213 entry->GetVirtualURL().is_valid() && | 213 entry->GetVirtualURL().is_valid() && |
| 214 entry->GetVirtualURL().spec() == kNTPOpenTabSyncURL) { | 214 entry->GetVirtualURL().spec() == kNTPOpenTabSyncURL) { |
| 215 DVLOG(1) << "Triggering sync refresh for sessions datatype."; | 215 DVLOG(1) << "Triggering sync refresh for sessions datatype."; |
| 216 const syncable::ModelType type = syncable::SESSIONS; | 216 const syncer::ModelType type = syncer::SESSIONS; |
| 217 syncable::ModelTypePayloadMap payload_map; | 217 syncer::ModelTypePayloadMap payload_map; |
| 218 payload_map[type] = ""; | 218 payload_map[type] = ""; |
| 219 content::NotificationService::current()->Notify( | 219 content::NotificationService::current()->Notify( |
| 220 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 220 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
| 221 content::Source<Profile>(profile_), | 221 content::Source<Profile>(profile_), |
| 222 content::Details<const syncable::ModelTypePayloadMap>(&payload_map)); | 222 content::Details<const syncer::ModelTypePayloadMap>(&payload_map)); |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 // Associate tabs first so the synced session tracker is aware of them. | 226 // Associate tabs first so the synced session tracker is aware of them. |
| 227 // Note that if we fail to associate, it means something has gone wrong, | 227 // Note that if we fail to associate, it means something has gone wrong, |
| 228 // such as our local session being deleted, so we disassociate and associate | 228 // such as our local session being deleted, so we disassociate and associate |
| 229 // again. | 229 // again. |
| 230 bool reassociation_needed = !modified_tabs.empty() && | 230 bool reassociation_needed = !modified_tabs.empty() && |
| 231 !session_model_associator_->AssociateTabs(modified_tabs, NULL); | 231 !session_model_associator_->AssociateTabs(modified_tabs, NULL); |
| 232 | 232 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 270 |
| 271 std::string local_tag = session_model_associator_->GetCurrentMachineTag(); | 271 std::string local_tag = session_model_associator_->GetCurrentMachineTag(); |
| 272 for (syncer::ChangeRecordList::const_iterator it = | 272 for (syncer::ChangeRecordList::const_iterator it = |
| 273 changes.Get().begin(); it != changes.Get().end(); ++it) { | 273 changes.Get().begin(); it != changes.Get().end(); ++it) { |
| 274 const syncer::ChangeRecord& change = *it; | 274 const syncer::ChangeRecord& change = *it; |
| 275 syncer::ChangeRecord::Action action(change.action); | 275 syncer::ChangeRecord::Action action(change.action); |
| 276 if (syncer::ChangeRecord::ACTION_DELETE == action) { | 276 if (syncer::ChangeRecord::ACTION_DELETE == action) { |
| 277 // Deletions are all or nothing (since we only ever delete entire | 277 // Deletions are all or nothing (since we only ever delete entire |
| 278 // sessions). Therefore we don't care if it's a tab node or meta node, | 278 // sessions). Therefore we don't care if it's a tab node or meta node, |
| 279 // and just ensure we've disassociated. | 279 // and just ensure we've disassociated. |
| 280 DCHECK_EQ(syncable::GetModelTypeFromSpecifics(it->specifics), | 280 DCHECK_EQ(syncer::GetModelTypeFromSpecifics(it->specifics), |
| 281 syncable::SESSIONS); | 281 syncer::SESSIONS); |
| 282 const sync_pb::SessionSpecifics& specifics = it->specifics.session(); | 282 const sync_pb::SessionSpecifics& specifics = it->specifics.session(); |
| 283 if (specifics.session_tag() == local_tag) { | 283 if (specifics.session_tag() == local_tag) { |
| 284 // Another client has attempted to delete our local data (possibly by | 284 // Another client has attempted to delete our local data (possibly by |
| 285 // error or their/our clock is inaccurate). Just ignore the deletion | 285 // error or their/our clock is inaccurate). Just ignore the deletion |
| 286 // for now to avoid any possible ping-pong delete/reassociate sequence. | 286 // for now to avoid any possible ping-pong delete/reassociate sequence. |
| 287 LOG(WARNING) << "Local session data deleted. Ignoring until next local " | 287 LOG(WARNING) << "Local session data deleted. Ignoring until next local " |
| 288 << "navigation event."; | 288 << "navigation event."; |
| 289 } else { | 289 } else { |
| 290 session_model_associator_->DisassociateForeignSession( | 290 session_model_associator_->DisassociateForeignSession( |
| 291 specifics.session_tag()); | 291 specifics.session_tag()); |
| 292 } | 292 } |
| 293 continue; | 293 continue; |
| 294 } | 294 } |
| 295 | 295 |
| 296 // Handle an update or add. | 296 // Handle an update or add. |
| 297 syncer::ReadNode sync_node(trans); | 297 syncer::ReadNode sync_node(trans); |
| 298 if (sync_node.InitByIdLookup(change.id) != syncer::BaseNode::INIT_OK) { | 298 if (sync_node.InitByIdLookup(change.id) != syncer::BaseNode::INIT_OK) { |
| 299 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 299 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 300 "Session node lookup failed."); | 300 "Session node lookup failed."); |
| 301 return; | 301 return; |
| 302 } | 302 } |
| 303 | 303 |
| 304 // Check that the changed node is a child of the session folder. | 304 // Check that the changed node is a child of the session folder. |
| 305 DCHECK(root.GetId() == sync_node.GetParentId()); | 305 DCHECK(root.GetId() == sync_node.GetParentId()); |
| 306 DCHECK(syncable::SESSIONS == sync_node.GetModelType()); | 306 DCHECK(syncer::SESSIONS == sync_node.GetModelType()); |
| 307 | 307 |
| 308 const sync_pb::SessionSpecifics& specifics( | 308 const sync_pb::SessionSpecifics& specifics( |
| 309 sync_node.GetSessionSpecifics()); | 309 sync_node.GetSessionSpecifics()); |
| 310 if (specifics.session_tag() == local_tag && | 310 if (specifics.session_tag() == local_tag && |
| 311 !setup_for_test_) { | 311 !setup_for_test_) { |
| 312 // We should only ever receive a change to our own machine's session info | 312 // We should only ever receive a change to our own machine's session info |
| 313 // if encryption was turned on. In that case, the data is still the same, | 313 // if encryption was turned on. In that case, the data is still the same, |
| 314 // so we can ignore. | 314 // so we can ignore. |
| 315 LOG(WARNING) << "Dropping modification to local session."; | 315 LOG(WARNING) << "Dropping modification to local session."; |
| 316 return; | 316 return; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 notification_registrar_.Add(this, chrome::NOTIFICATION_FAVICON_CHANGED, | 366 notification_registrar_.Add(this, chrome::NOTIFICATION_FAVICON_CHANGED, |
| 367 content::Source<Profile>(profile_)); | 367 content::Source<Profile>(profile_)); |
| 368 } | 368 } |
| 369 | 369 |
| 370 void SessionChangeProcessor::StopObserving() { | 370 void SessionChangeProcessor::StopObserving() { |
| 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 372 notification_registrar_.RemoveAll(); | 372 notification_registrar_.RemoveAll(); |
| 373 } | 373 } |
| 374 | 374 |
| 375 } // namespace browser_sync | 375 } // namespace browser_sync |
| OLD | NEW |