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

Side by Side Diff: sync/internal_api/read_node.cc

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

Powered by Google App Engine
This is Rietveld 408576698