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 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 } | 758 } |
759 synced_session_tracker_.SetLocalSessionTag(current_machine_tag_); | 759 synced_session_tracker_.SetLocalSessionTag(current_machine_tag_); |
760 if (!UpdateAssociationsFromSyncModel(root, &trans, &error)) { | 760 if (!UpdateAssociationsFromSyncModel(root, &trans, &error)) { |
761 DCHECK(error.IsSet()); | 761 DCHECK(error.IsSet()); |
762 return error; | 762 return error; |
763 } | 763 } |
764 | 764 |
765 if (local_session_syncid_ == sync_api::kInvalidId) { | 765 if (local_session_syncid_ == sync_api::kInvalidId) { |
766 // The sync db didn't have a header node for us, we need to create one. | 766 // The sync db didn't have a header node for us, we need to create one. |
767 sync_api::WriteNode write_node(&trans); | 767 sync_api::WriteNode write_node(&trans); |
768 if (!write_node.InitUniqueByCreation(SESSIONS, | 768 sync_api::WriteNode::InitUniqueByCreationResult result = |
769 root, | 769 write_node.InitUniqueByCreation(SESSIONS, root, current_machine_tag_); |
770 current_machine_tag_)) { | 770 if (result != sync_api::WriteNode::INIT_SUCCESS) { |
771 // If we can't look it up, and we can't create it, chances are there's | 771 // If we can't look it up, and we can't create it, chances are there's |
772 // a pre-existing node that has encryption issues. But, since we can't | 772 // a pre-existing node that has encryption issues. But, since we can't |
773 // load the item, we can't remove it, and error out at this point. | 773 // load the item, we can't remove it, and error out at this point. |
774 return error_handler_->CreateAndUploadError( | 774 return error_handler_->CreateAndUploadError( |
775 FROM_HERE, | 775 FROM_HERE, |
776 "Failed to create sessions header sync node.", | 776 "Failed to create sessions header sync node.", |
777 model_type()); | 777 model_type()); |
778 } | 778 } |
779 | 779 |
780 // Write the initial values to the specifics so that in case of a crash or | 780 // Write the initial values to the specifics so that in case of a crash or |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1347 // Tab pool has no free nodes, allocate new one. | 1347 // Tab pool has no free nodes, allocate new one. |
1348 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1348 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
1349 sync_api::ReadNode root(&trans); | 1349 sync_api::ReadNode root(&trans); |
1350 if (root.InitByTagLookup(kSessionsTag) != sync_api::BaseNode::INIT_OK) { | 1350 if (root.InitByTagLookup(kSessionsTag) != sync_api::BaseNode::INIT_OK) { |
1351 LOG(ERROR) << kNoSessionsFolderError; | 1351 LOG(ERROR) << kNoSessionsFolderError; |
1352 return sync_api::kInvalidId; | 1352 return sync_api::kInvalidId; |
1353 } | 1353 } |
1354 size_t tab_node_id = tab_syncid_pool_.size(); | 1354 size_t tab_node_id = tab_syncid_pool_.size(); |
1355 std::string tab_node_tag = TabIdToTag(machine_tag_, tab_node_id); | 1355 std::string tab_node_tag = TabIdToTag(machine_tag_, tab_node_id); |
1356 sync_api::WriteNode tab_node(&trans); | 1356 sync_api::WriteNode tab_node(&trans); |
1357 if (!tab_node.InitUniqueByCreation(SESSIONS, root, tab_node_tag)) { | 1357 sync_api::WriteNode::InitUniqueByCreationResult result = |
| 1358 tab_node.InitUniqueByCreation(SESSIONS, root, tab_node_tag); |
| 1359 if (result != sync_api::WriteNode::INIT_SUCCESS) { |
1358 LOG(ERROR) << "Could not create new node with tag " | 1360 LOG(ERROR) << "Could not create new node with tag " |
1359 << tab_node_tag << "!"; | 1361 << tab_node_tag << "!"; |
1360 return sync_api::kInvalidId; | 1362 return sync_api::kInvalidId; |
1361 } | 1363 } |
1362 // We fill the new node with just enough data so that in case of a crash/bug | 1364 // We fill the new node with just enough data so that in case of a crash/bug |
1363 // we can identify the node as our own on re-association and reuse it. | 1365 // we can identify the node as our own on re-association and reuse it. |
1364 tab_node.SetTitle(UTF8ToWide(tab_node_tag)); | 1366 tab_node.SetTitle(UTF8ToWide(tab_node_tag)); |
1365 sync_pb::SessionSpecifics specifics; | 1367 sync_pb::SessionSpecifics specifics; |
1366 specifics.set_session_tag(machine_tag_); | 1368 specifics.set_session_tag(machine_tag_); |
1367 specifics.set_tab_node_id(tab_node_id); | 1369 specifics.set_tab_node_id(tab_node_id); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1574 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
1573 // We only access the cryptographer while holding a transaction. | 1575 // We only access the cryptographer while holding a transaction. |
1574 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1576 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
1575 const syncable::ModelTypeSet encrypted_types = | 1577 const syncable::ModelTypeSet encrypted_types = |
1576 sync_api::GetEncryptedTypes(&trans); | 1578 sync_api::GetEncryptedTypes(&trans); |
1577 return !encrypted_types.Has(SESSIONS) || | 1579 return !encrypted_types.Has(SESSIONS) || |
1578 sync_service_->IsCryptographerReady(&trans); | 1580 sync_service_->IsCryptographerReady(&trans); |
1579 } | 1581 } |
1580 | 1582 |
1581 } // namespace browser_sync | 1583 } // namespace browser_sync |
OLD | NEW |