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_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 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/tracked.h" | 12 #include "base/tracked.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/sessions/restore_tab_helper.h" | 15 #include "chrome/browser/sessions/restore_tab_helper.h" |
16 #include "chrome/browser/sessions/session_service_factory.h" | 16 #include "chrome/browser/sessions/session_service_factory.h" |
17 #include "chrome/browser/sync/api/sync_error.h" | |
18 #include "chrome/browser/sync/glue/synced_window_delegate.h" | 17 #include "chrome/browser/sync/glue/synced_window_delegate.h" |
19 #include "chrome/browser/sync/profile_sync_service.h" | 18 #include "chrome/browser/sync/profile_sync_service.h" |
20 #include "chrome/browser/sync/syncable/syncable.h" | 19 #include "chrome/browser/sync/syncable/syncable.h" |
21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
22 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
24 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
25 #include "content/browser/tab_contents/navigation_controller.h" | 24 #include "content/browser/tab_contents/navigation_controller.h" |
26 #include "content/browser/tab_contents/navigation_entry.h" | 25 #include "content/browser/tab_contents/navigation_entry.h" |
27 #include "content/common/notification_details.h" | 26 #include "content/common/notification_details.h" |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 sync_pb::TabNavigation_PageTransition_TYPED); | 400 sync_pb::TabNavigation_PageTransition_TYPED); |
402 } | 401 } |
403 } | 402 } |
404 | 403 |
405 void SessionModelAssociator::Disassociate(int64 sync_id) { | 404 void SessionModelAssociator::Disassociate(int64 sync_id) { |
406 DCHECK(CalledOnValidThread()); | 405 DCHECK(CalledOnValidThread()); |
407 NOTIMPLEMENTED(); | 406 NOTIMPLEMENTED(); |
408 // TODO(zea): we will need this once we support deleting foreign sessions. | 407 // TODO(zea): we will need this once we support deleting foreign sessions. |
409 } | 408 } |
410 | 409 |
411 bool SessionModelAssociator::AssociateModels(SyncError* error) { | 410 bool SessionModelAssociator::AssociateModels() { |
412 DCHECK(CalledOnValidThread()); | 411 DCHECK(CalledOnValidThread()); |
413 | 412 |
414 // Ensure that we disassociated properly, otherwise memory might leak. | 413 // Ensure that we disassociated properly, otherwise memory might leak. |
415 DCHECK(synced_session_tracker_.empty()); | 414 DCHECK(synced_session_tracker_.empty()); |
416 DCHECK_EQ(0U, tab_pool_.capacity()); | 415 DCHECK_EQ(0U, tab_pool_.capacity()); |
417 | 416 |
418 local_session_syncid_ = sync_api::kInvalidId; | 417 local_session_syncid_ = sync_api::kInvalidId; |
419 | 418 |
420 // Read any available foreign sessions and load any session data we may have. | 419 // Read any available foreign sessions and load any session data we may have. |
421 // If we don't have any local session data in the db, create a header node. | 420 // If we don't have any local session data in the db, create a header node. |
422 { | 421 { |
423 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 422 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
424 | 423 |
425 sync_api::ReadNode root(&trans); | 424 sync_api::ReadNode root(&trans); |
426 if (!root.InitByTagLookup(kSessionsTag)) { | 425 if (!root.InitByTagLookup(kSessionsTag)) { |
427 error->Reset(FROM_HERE, kNoSessionsFolderError, model_type()); | 426 LOG(ERROR) << kNoSessionsFolderError; |
428 return false; | 427 return false; |
429 } | 428 } |
430 | 429 |
431 // Make sure we have a machine tag. | 430 // Make sure we have a machine tag. |
432 if (current_machine_tag_.empty()) | 431 if (current_machine_tag_.empty()) |
433 InitializeCurrentMachineTag(&trans); | 432 InitializeCurrentMachineTag(&trans); |
434 synced_session_tracker_.SetLocalSessionTag(current_machine_tag_); | 433 synced_session_tracker_.SetLocalSessionTag(current_machine_tag_); |
435 UpdateAssociationsFromSyncModel(root, &trans); | 434 UpdateAssociationsFromSyncModel(root, &trans); |
436 | 435 |
437 if (local_session_syncid_ == sync_api::kInvalidId) { | 436 if (local_session_syncid_ == sync_api::kInvalidId) { |
438 // The sync db didn't have a header node for us, we need to create one. | 437 // The sync db didn't have a header node for us, we need to create one. |
439 sync_api::WriteNode write_node(&trans); | 438 sync_api::WriteNode write_node(&trans); |
440 if (!write_node.InitUniqueByCreation(syncable::SESSIONS, root, | 439 if (!write_node.InitUniqueByCreation(syncable::SESSIONS, root, |
441 current_machine_tag_)) { | 440 current_machine_tag_)) { |
442 error->Reset(FROM_HERE, | 441 LOG(ERROR) << "Failed to create sessions header sync node."; |
443 "Failed to create sessions header sync node.", | |
444 model_type()); | |
445 return false; | 442 return false; |
446 } | 443 } |
447 write_node.SetTitle(UTF8ToWide(current_machine_tag_)); | 444 write_node.SetTitle(UTF8ToWide(current_machine_tag_)); |
448 local_session_syncid_ = write_node.GetId(); | 445 local_session_syncid_ = write_node.GetId(); |
449 } | 446 } |
450 } | 447 } |
451 | 448 |
452 // Check if anything has changed on the client side. | 449 // Check if anything has changed on the client side. |
453 UpdateSyncModelDataFromClient(); | 450 UpdateSyncModelDataFromClient(); |
454 | 451 |
455 VLOG(1) << "Session models associated."; | 452 VLOG(1) << "Session models associated."; |
456 | 453 |
457 return true; | 454 return true; |
458 } | 455 } |
459 | 456 |
460 bool SessionModelAssociator::DisassociateModels(SyncError* error) { | 457 bool SessionModelAssociator::DisassociateModels() { |
461 DCHECK(CalledOnValidThread()); | 458 DCHECK(CalledOnValidThread()); |
462 synced_session_tracker_.clear(); | 459 synced_session_tracker_.clear(); |
463 tab_map_.clear(); | 460 tab_map_.clear(); |
464 tab_pool_.clear(); | 461 tab_pool_.clear(); |
465 local_session_syncid_ = sync_api::kInvalidId; | 462 local_session_syncid_ = sync_api::kInvalidId; |
466 | 463 |
467 // There is no local model stored with which to disassociate, just notify | 464 // There is no local model stored with which to disassociate, just notify |
468 // foreign session handlers. | 465 // foreign session handlers. |
469 NotificationService::current()->Notify( | 466 NotificationService::current()->Notify( |
470 chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, | 467 chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1054 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
1058 // We only access the cryptographer while holding a transaction. | 1055 // We only access the cryptographer while holding a transaction. |
1059 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1056 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
1060 syncable::ModelTypeSet encrypted_types; | 1057 syncable::ModelTypeSet encrypted_types; |
1061 encrypted_types = sync_api::GetEncryptedTypes(&trans); | 1058 encrypted_types = sync_api::GetEncryptedTypes(&trans); |
1062 return encrypted_types.count(syncable::SESSIONS) == 0 || | 1059 return encrypted_types.count(syncable::SESSIONS) == 0 || |
1063 sync_service_->IsCryptographerReady(&trans); | 1060 sync_service_->IsCryptographerReady(&trans); |
1064 } | 1061 } |
1065 | 1062 |
1066 } // namespace browser_sync | 1063 } // namespace browser_sync |
OLD | NEW |