| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <sstream> | 7 #include <sstream> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "chrome/browser/extensions/extension_tab_helper.h" | 13 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/sync/glue/session_model_associator.h" | 15 #include "chrome/browser/sync/glue/session_model_associator.h" |
| 16 #include "chrome/browser/sync/internal_api/change_record.h" |
| 16 #include "chrome/browser/sync/internal_api/read_node.h" | 17 #include "chrome/browser/sync/internal_api/read_node.h" |
| 17 #include "chrome/browser/sync/internal_api/sync_manager.h" | |
| 18 #include "chrome/browser/sync/profile_sync_service.h" | 18 #include "chrome/browser/sync/profile_sync_service.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "content/browser/tab_contents/navigation_controller.h" | 21 #include "content/browser/tab_contents/navigation_controller.h" |
| 22 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
| 23 #include "content/common/notification_details.h" | 23 #include "content/common/notification_details.h" |
| 24 #include "content/common/notification_service.h" | 24 #include "content/common/notification_service.h" |
| 25 #include "content/common/notification_source.h" | 25 #include "content/common/notification_source.h" |
| 26 | 26 |
| 27 namespace browser_sync { | 27 namespace browser_sync { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 if (!modified_tabs.empty()) | 178 if (!modified_tabs.empty()) |
| 179 session_model_associator_->ReassociateTabs(modified_tabs); | 179 session_model_associator_->ReassociateTabs(modified_tabs); |
| 180 // Note, we always reassociate windows because it's possible a tab became | 180 // Note, we always reassociate windows because it's possible a tab became |
| 181 // "interesting" by going to a valid URL, in which case it needs to be added | 181 // "interesting" by going to a valid URL, in which case it needs to be added |
| 182 // to the window's tab information. | 182 // to the window's tab information. |
| 183 session_model_associator_->ReassociateWindows(false); | 183 session_model_associator_->ReassociateWindows(false); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void SessionChangeProcessor::ApplyChangesFromSyncModel( | 186 void SessionChangeProcessor::ApplyChangesFromSyncModel( |
| 187 const sync_api::BaseTransaction* trans, | 187 const sync_api::BaseTransaction* trans, |
| 188 const sync_api::SyncManager::ChangeRecord* changes, | 188 const sync_api::ImmutableChangeRecordList& changes) { |
| 189 int change_count) { | |
| 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 191 if (!running()) { | 190 if (!running()) { |
| 192 return; | 191 return; |
| 193 } | 192 } |
| 194 | 193 |
| 195 StopObserving(); | 194 StopObserving(); |
| 196 | 195 |
| 197 sync_api::ReadNode root(trans); | 196 sync_api::ReadNode root(trans); |
| 198 if (!root.InitByTagLookup(kSessionsTag)) { | 197 if (!root.InitByTagLookup(kSessionsTag)) { |
| 199 error_handler()->OnUnrecoverableError(FROM_HERE, | 198 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 200 "Sessions root node lookup failed."); | 199 "Sessions root node lookup failed."); |
| 201 return; | 200 return; |
| 202 } | 201 } |
| 203 | 202 |
| 204 for (int i = 0; i < change_count; ++i) { | 203 for (sync_api::ChangeRecordList::const_iterator it = |
| 205 const sync_api::SyncManager::ChangeRecord& change = changes[i]; | 204 changes.Get().begin(); it != changes.Get().end(); ++it) { |
| 206 sync_api::SyncManager::ChangeRecord::Action action(change.action); | 205 const sync_api::ChangeRecord& change = *it; |
| 207 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == action) { | 206 sync_api::ChangeRecord::Action action(change.action); |
| 207 if (sync_api::ChangeRecord::ACTION_DELETE == action) { |
| 208 // Deletions should only be for a foreign client itself, and hence affect | 208 // Deletions should only be for a foreign client itself, and hence affect |
| 209 // the header node, never a tab node. | 209 // the header node, never a tab node. |
| 210 sync_api::ReadNode node(trans); | 210 sync_api::ReadNode node(trans); |
| 211 if (!node.InitByIdLookup(change.id)) { | 211 if (!node.InitByIdLookup(change.id)) { |
| 212 error_handler()->OnUnrecoverableError(FROM_HERE, | 212 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 213 "Session node lookup failed."); | 213 "Session node lookup failed."); |
| 214 return; | 214 return; |
| 215 } | 215 } |
| 216 DCHECK_EQ(node.GetModelType(), syncable::SESSIONS); | 216 DCHECK_EQ(node.GetModelType(), syncable::SESSIONS); |
| 217 const sync_pb::SessionSpecifics& specifics = node.GetSessionSpecifics(); | 217 const sync_pb::SessionSpecifics& specifics = node.GetSessionSpecifics(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 NotificationService::AllBrowserContextsAndSources()); | 295 NotificationService::AllBrowserContextsAndSources()); |
| 296 } | 296 } |
| 297 | 297 |
| 298 void SessionChangeProcessor::StopObserving() { | 298 void SessionChangeProcessor::StopObserving() { |
| 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 300 DCHECK(profile_); | 300 DCHECK(profile_); |
| 301 notification_registrar_.RemoveAll(); | 301 notification_registrar_.RemoveAll(); |
| 302 } | 302 } |
| 303 | 303 |
| 304 } // namespace browser_sync | 304 } // namespace browser_sync |
| OLD | NEW |