Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: components/sync/core/read_node.cc

Issue 2407163004: [Sync] Move some directory-related things from core/ to syncable/. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/sync/core/read_node.h ('k') | components/sync/core/read_transaction.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 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 "components/sync/core/read_node.h"
6
7 #include "base/logging.h"
8 #include "components/sync/core/base_transaction.h"
9 #include "components/sync/syncable/entry.h"
10 #include "components/sync/syncable/syncable_base_transaction.h"
11 #include "components/sync/syncable/syncable_util.h"
12
13 namespace syncer {
14
15 //////////////////////////////////////////////////////////////////////////
16 // ReadNode member definitions
17 ReadNode::ReadNode(const BaseTransaction* transaction)
18 : entry_(NULL), transaction_(transaction) {
19 DCHECK(transaction);
20 }
21
22 ReadNode::ReadNode() {
23 entry_ = NULL;
24 transaction_ = NULL;
25 }
26
27 ReadNode::~ReadNode() {
28 delete entry_;
29 }
30
31 void ReadNode::InitByRootLookup() {
32 DCHECK(!entry_) << "Init called twice";
33 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans();
34 entry_ = new syncable::Entry(trans, syncable::GET_BY_ID, trans->root_id());
35 if (!entry_->good())
36 DCHECK(false) << "Could not lookup root node for reading.";
37 }
38
39 BaseNode::InitByLookupResult ReadNode::InitByIdLookup(int64_t id) {
40 DCHECK(!entry_) << "Init called twice";
41 DCHECK_NE(id, kInvalidId);
42 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans();
43 entry_ = new syncable::Entry(trans, syncable::GET_BY_HANDLE, id);
44 if (!entry_->good())
45 return INIT_FAILED_ENTRY_NOT_GOOD;
46 if (entry_->GetIsDel())
47 return INIT_FAILED_ENTRY_IS_DEL;
48 ModelType model_type = GetModelType();
49 LOG_IF(WARNING, model_type == UNSPECIFIED || model_type == TOP_LEVEL_FOLDER)
50 << "SyncAPI InitByIdLookup referencing unusual object.";
51 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY;
52 }
53
54 BaseNode::InitByLookupResult ReadNode::InitByClientTagLookup(
55 ModelType model_type,
56 const std::string& tag) {
57 DCHECK(!entry_) << "Init called twice";
58 if (tag.empty())
59 return INIT_FAILED_PRECONDITION;
60
61 const std::string hash = syncable::GenerateSyncableHash(model_type, tag);
62
63 entry_ = new syncable::Entry(transaction_->GetWrappedTrans(),
64 syncable::GET_BY_CLIENT_TAG, hash);
65 if (!entry_->good())
66 return INIT_FAILED_ENTRY_NOT_GOOD;
67 if (entry_->GetIsDel())
68 return INIT_FAILED_ENTRY_IS_DEL;
69 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY;
70 }
71
72 const syncable::Entry* ReadNode::GetEntry() const {
73 return entry_;
74 }
75
76 const BaseTransaction* ReadNode::GetTransaction() const {
77 return transaction_;
78 }
79
80 int64_t ReadNode::GetTransactionVersion() const {
81 return GetEntry()->GetTransactionVersion();
82 }
83
84 BaseNode::InitByLookupResult ReadNode::InitByTagLookupForBookmarks(
85 const std::string& tag) {
86 DCHECK(!entry_) << "Init called twice";
87 if (tag.empty())
88 return INIT_FAILED_PRECONDITION;
89 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans();
90 entry_ = new syncable::Entry(trans, syncable::GET_BY_SERVER_TAG, tag);
91 if (!entry_->good())
92 return INIT_FAILED_ENTRY_NOT_GOOD;
93 if (entry_->GetIsDel())
94 return INIT_FAILED_ENTRY_IS_DEL;
95 ModelType model_type = GetModelType();
96 DCHECK_EQ(model_type, BOOKMARKS)
97 << "InitByTagLookup deprecated for all types except bookmarks.";
98 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY;
99 }
100
101 BaseNode::InitByLookupResult ReadNode::InitTypeRoot(ModelType type) {
102 DCHECK(!entry_) << "Init called twice";
103 if (!IsRealDataType(type))
104 return INIT_FAILED_PRECONDITION;
105 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans();
106 entry_ = new syncable::Entry(trans, syncable::GET_TYPE_ROOT, type);
107 if (!entry_->good())
108 return INIT_FAILED_ENTRY_NOT_GOOD;
109 if (entry_->GetIsDel())
110 return INIT_FAILED_ENTRY_IS_DEL;
111 ModelType found_model_type = GetModelType();
112 LOG_IF(WARNING, found_model_type == UNSPECIFIED ||
113 found_model_type == TOP_LEVEL_FOLDER)
114 << "SyncAPI InitTypeRoot referencing unusually typed object.";
115 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY;
116 }
117
118 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/core/read_node.h ('k') | components/sync/core/read_transaction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698