OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/sync/internal_api/read_node.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "chrome/browser/sync/internal_api/base_transaction.h" | |
9 #include "sync/syncable/syncable.h" | |
10 | |
11 namespace sync_api { | |
12 | |
13 ////////////////////////////////////////////////////////////////////////// | |
14 // ReadNode member definitions | |
15 ReadNode::ReadNode(const BaseTransaction* transaction) | |
16 : entry_(NULL), transaction_(transaction) { | |
17 DCHECK(transaction); | |
18 } | |
19 | |
20 ReadNode::ReadNode() { | |
21 entry_ = NULL; | |
22 transaction_ = NULL; | |
23 } | |
24 | |
25 ReadNode::~ReadNode() { | |
26 delete entry_; | |
27 } | |
28 | |
29 void ReadNode::InitByRootLookup() { | |
30 DCHECK(!entry_) << "Init called twice"; | |
31 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); | |
32 entry_ = new syncable::Entry(trans, syncable::GET_BY_ID, trans->root_id()); | |
33 if (!entry_->good()) | |
34 DCHECK(false) << "Could not lookup root node for reading."; | |
35 } | |
36 | |
37 bool ReadNode::InitByIdLookup(int64 id) { | |
38 DCHECK(!entry_) << "Init called twice"; | |
39 DCHECK_NE(id, kInvalidId); | |
40 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); | |
41 entry_ = new syncable::Entry(trans, syncable::GET_BY_HANDLE, id); | |
42 if (!entry_->good()) | |
43 return false; | |
44 if (entry_->Get(syncable::IS_DEL)) | |
45 return false; | |
46 syncable::ModelType model_type = GetModelType(); | |
47 LOG_IF(WARNING, model_type == syncable::UNSPECIFIED || | |
48 model_type == syncable::TOP_LEVEL_FOLDER) | |
49 << "SyncAPI InitByIdLookup referencing unusual object."; | |
50 return DecryptIfNecessary(); | |
51 } | |
52 | |
53 bool ReadNode::InitByClientTagLookup(syncable::ModelType model_type, | |
54 const std::string& tag) { | |
55 DCHECK(!entry_) << "Init called twice"; | |
56 if (tag.empty()) | |
57 return false; | |
58 | |
59 const std::string hash = GenerateSyncableHash(model_type, tag); | |
60 | |
61 entry_ = new syncable::Entry(transaction_->GetWrappedTrans(), | |
62 syncable::GET_BY_CLIENT_TAG, hash); | |
63 return (entry_->good() && !entry_->Get(syncable::IS_DEL) && | |
64 DecryptIfNecessary()); | |
65 } | |
66 | |
67 const syncable::Entry* ReadNode::GetEntry() const { | |
68 return entry_; | |
69 } | |
70 | |
71 const BaseTransaction* ReadNode::GetTransaction() const { | |
72 return transaction_; | |
73 } | |
74 | |
75 bool ReadNode::InitByTagLookup(const std::string& tag) { | |
76 DCHECK(!entry_) << "Init called twice"; | |
77 if (tag.empty()) | |
78 return false; | |
79 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans(); | |
80 entry_ = new syncable::Entry(trans, syncable::GET_BY_SERVER_TAG, tag); | |
81 if (!entry_->good()) | |
82 return false; | |
83 if (entry_->Get(syncable::IS_DEL)) | |
84 return false; | |
85 syncable::ModelType model_type = GetModelType(); | |
86 LOG_IF(WARNING, model_type == syncable::UNSPECIFIED || | |
87 model_type == syncable::TOP_LEVEL_FOLDER) | |
88 << "SyncAPI InitByTagLookup referencing unusually typed object."; | |
89 return DecryptIfNecessary(); | |
90 } | |
91 | |
92 } // namespace sync_api | |
OLD | NEW |