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/internal_api/read_node.h" | 5 #include "chrome/browser/sync/internal_api/read_node.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/sync/internal_api/base_transaction.h" | 8 #include "chrome/browser/sync/internal_api/base_transaction.h" |
9 #include "sync/syncable/syncable.h" | 9 #include "sync/syncable/syncable.h" |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 | 28 |
29 void ReadNode::InitByRootLookup() { | 29 void ReadNode::InitByRootLookup() { |
30 DCHECK(!entry_) << "Init called twice"; | 30 DCHECK(!entry_) << "Init called twice"; |
31 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); | 31 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); |
32 entry_ = new syncable::Entry(trans, syncable::GET_BY_ID, trans->root_id()); | 32 entry_ = new syncable::Entry(trans, syncable::GET_BY_ID, trans->root_id()); |
33 if (!entry_->good()) | 33 if (!entry_->good()) |
34 DCHECK(false) << "Could not lookup root node for reading."; | 34 DCHECK(false) << "Could not lookup root node for reading."; |
35 } | 35 } |
36 | 36 |
37 bool ReadNode::InitByIdLookup(int64 id) { | 37 BaseNode::InitByLookupResult ReadNode::InitByIdLookup(int64 id) { |
38 DCHECK(!entry_) << "Init called twice"; | 38 DCHECK(!entry_) << "Init called twice"; |
39 DCHECK_NE(id, kInvalidId); | 39 DCHECK_NE(id, kInvalidId); |
40 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); | 40 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); |
41 entry_ = new syncable::Entry(trans, syncable::GET_BY_HANDLE, id); | 41 entry_ = new syncable::Entry(trans, syncable::GET_BY_HANDLE, id); |
42 if (!entry_->good()) | 42 if (!entry_->good()) |
43 return false; | 43 return INIT_FAILED_ENTRY_NOT_GOOD; |
44 if (entry_->Get(syncable::IS_DEL)) | 44 if (entry_->Get(syncable::IS_DEL)) |
45 return false; | 45 return INIT_FAILED_ENTRY_IS_DEL; |
46 syncable::ModelType model_type = GetModelType(); | 46 syncable::ModelType model_type = GetModelType(); |
47 LOG_IF(WARNING, model_type == syncable::UNSPECIFIED || | 47 LOG_IF(WARNING, model_type == syncable::UNSPECIFIED || |
48 model_type == syncable::TOP_LEVEL_FOLDER) | 48 model_type == syncable::TOP_LEVEL_FOLDER) |
49 << "SyncAPI InitByIdLookup referencing unusual object."; | 49 << "SyncAPI InitByIdLookup referencing unusual object."; |
50 return DecryptIfNecessary(); | 50 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY; |
51 } | 51 } |
52 | 52 |
53 bool ReadNode::InitByClientTagLookup(syncable::ModelType model_type, | 53 BaseNode::InitByLookupResult ReadNode::InitByClientTagLookup( |
54 const std::string& tag) { | 54 syncable::ModelType model_type, |
| 55 const std::string& tag) { |
55 DCHECK(!entry_) << "Init called twice"; | 56 DCHECK(!entry_) << "Init called twice"; |
56 if (tag.empty()) | 57 if (tag.empty()) |
57 return false; | 58 return INIT_FAILED_PRECONDITION; |
58 | 59 |
59 const std::string hash = GenerateSyncableHash(model_type, tag); | 60 const std::string hash = GenerateSyncableHash(model_type, tag); |
60 | 61 |
61 entry_ = new syncable::Entry(transaction_->GetWrappedTrans(), | 62 entry_ = new syncable::Entry(transaction_->GetWrappedTrans(), |
62 syncable::GET_BY_CLIENT_TAG, hash); | 63 syncable::GET_BY_CLIENT_TAG, hash); |
63 return (entry_->good() && !entry_->Get(syncable::IS_DEL) && | 64 if (!entry_->good()) |
64 DecryptIfNecessary()); | 65 return INIT_FAILED_ENTRY_NOT_GOOD; |
| 66 if (entry_->Get(syncable::IS_DEL)) |
| 67 return INIT_FAILED_ENTRY_IS_DEL; |
| 68 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY; |
65 } | 69 } |
66 | 70 |
67 const syncable::Entry* ReadNode::GetEntry() const { | 71 const syncable::Entry* ReadNode::GetEntry() const { |
68 return entry_; | 72 return entry_; |
69 } | 73 } |
70 | 74 |
71 const BaseTransaction* ReadNode::GetTransaction() const { | 75 const BaseTransaction* ReadNode::GetTransaction() const { |
72 return transaction_; | 76 return transaction_; |
73 } | 77 } |
74 | 78 |
75 bool ReadNode::InitByTagLookup(const std::string& tag) { | 79 BaseNode::InitByLookupResult ReadNode::InitByTagLookup( |
| 80 const std::string& tag) { |
76 DCHECK(!entry_) << "Init called twice"; | 81 DCHECK(!entry_) << "Init called twice"; |
77 if (tag.empty()) | 82 if (tag.empty()) |
78 return false; | 83 return INIT_FAILED_PRECONDITION; |
79 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); | 84 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); |
80 entry_ = new syncable::Entry(trans, syncable::GET_BY_SERVER_TAG, tag); | 85 entry_ = new syncable::Entry(trans, syncable::GET_BY_SERVER_TAG, tag); |
81 if (!entry_->good()) | 86 if (!entry_->good()) |
82 return false; | 87 return INIT_FAILED_ENTRY_NOT_GOOD; |
83 if (entry_->Get(syncable::IS_DEL)) | 88 if (entry_->Get(syncable::IS_DEL)) |
84 return false; | 89 return INIT_FAILED_ENTRY_IS_DEL; |
85 syncable::ModelType model_type = GetModelType(); | 90 syncable::ModelType model_type = GetModelType(); |
86 LOG_IF(WARNING, model_type == syncable::UNSPECIFIED || | 91 LOG_IF(WARNING, model_type == syncable::UNSPECIFIED || |
87 model_type == syncable::TOP_LEVEL_FOLDER) | 92 model_type == syncable::TOP_LEVEL_FOLDER) |
88 << "SyncAPI InitByTagLookup referencing unusually typed object."; | 93 << "SyncAPI InitByTagLookup referencing unusually typed object."; |
89 return DecryptIfNecessary(); | 94 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY; |
90 } | 95 } |
91 | 96 |
92 } // namespace sync_api | 97 } // namespace sync_api |
OLD | NEW |