| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // Note, we always associate windows because it's possible a tab became | 233 // Note, we always associate windows because it's possible a tab became |
| 234 // "interesting" by going to a valid URL, in which case it needs to be added | 234 // "interesting" by going to a valid URL, in which case it needs to be added |
| 235 // to the window's tab information. | 235 // to the window's tab information. |
| 236 if (!reassociation_needed) { | 236 if (!reassociation_needed) { |
| 237 reassociation_needed = | 237 reassociation_needed = |
| 238 !session_model_associator_->AssociateWindows(false, NULL); | 238 !session_model_associator_->AssociateWindows(false, NULL); |
| 239 } | 239 } |
| 240 | 240 |
| 241 if (reassociation_needed) { | 241 if (reassociation_needed) { |
| 242 LOG(WARNING) << "Reassociation of local models triggered."; | 242 LOG(WARNING) << "Reassociation of local models triggered."; |
| 243 csync::SyncError error; | 243 syncer::SyncError error; |
| 244 error = session_model_associator_->DisassociateModels(); | 244 error = session_model_associator_->DisassociateModels(); |
| 245 error = session_model_associator_->AssociateModels(); | 245 error = session_model_associator_->AssociateModels(); |
| 246 if (error.IsSet()) { | 246 if (error.IsSet()) { |
| 247 error_handler()->OnSingleDatatypeUnrecoverableError( | 247 error_handler()->OnSingleDatatypeUnrecoverableError( |
| 248 error.location(), | 248 error.location(), |
| 249 error.message()); | 249 error.message()); |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 void SessionChangeProcessor::ApplyChangesFromSyncModel( | 254 void SessionChangeProcessor::ApplyChangesFromSyncModel( |
| 255 const csync::BaseTransaction* trans, | 255 const syncer::BaseTransaction* trans, |
| 256 const csync::ImmutableChangeRecordList& changes) { | 256 const syncer::ImmutableChangeRecordList& changes) { |
| 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 258 if (!running()) { | 258 if (!running()) { |
| 259 return; | 259 return; |
| 260 } | 260 } |
| 261 | 261 |
| 262 ScopedStopObserving<SessionChangeProcessor> stop_observing(this); | 262 ScopedStopObserving<SessionChangeProcessor> stop_observing(this); |
| 263 | 263 |
| 264 csync::ReadNode root(trans); | 264 syncer::ReadNode root(trans); |
| 265 if (root.InitByTagLookup(kSessionsTag) != csync::BaseNode::INIT_OK) { | 265 if (root.InitByTagLookup(kSessionsTag) != syncer::BaseNode::INIT_OK) { |
| 266 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 266 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 267 "Sessions root node lookup failed."); | 267 "Sessions root node lookup failed."); |
| 268 return; | 268 return; |
| 269 } | 269 } |
| 270 | 270 |
| 271 std::string local_tag = session_model_associator_->GetCurrentMachineTag(); | 271 std::string local_tag = session_model_associator_->GetCurrentMachineTag(); |
| 272 for (csync::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 csync::ChangeRecord& change = *it; | 274 const syncer::ChangeRecord& change = *it; |
| 275 csync::ChangeRecord::Action action(change.action); | 275 syncer::ChangeRecord::Action action(change.action); |
| 276 if (csync::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(syncable::GetModelTypeFromSpecifics(it->specifics), |
| 281 syncable::SESSIONS); | 281 syncable::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 csync::ReadNode sync_node(trans); | 297 syncer::ReadNode sync_node(trans); |
| 298 if (sync_node.InitByIdLookup(change.id) != csync::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(syncable::SESSIONS == sync_node.GetModelType()); |
| 307 | 307 |
| 308 const sync_pb::SessionSpecifics& specifics( | 308 const sync_pb::SessionSpecifics& specifics( |
| (...skipping 57 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 |