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

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

Issue 10147003: [Sync] Move 'syncapi_core' and 'sync_unit_tests' targets to sync/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Win update errors Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
(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 BaseNode::InitByLookupResult 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 INIT_FAILED_ENTRY_NOT_GOOD;
44 if (entry_->Get(syncable::IS_DEL))
45 return INIT_FAILED_ENTRY_IS_DEL;
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() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY;
51 }
52
53 BaseNode::InitByLookupResult ReadNode::InitByClientTagLookup(
54 syncable::ModelType model_type,
55 const std::string& tag) {
56 DCHECK(!entry_) << "Init called twice";
57 if (tag.empty())
58 return INIT_FAILED_PRECONDITION;
59
60 const std::string hash = GenerateSyncableHash(model_type, tag);
61
62 entry_ = new syncable::Entry(transaction_->GetWrappedTrans(),
63 syncable::GET_BY_CLIENT_TAG, hash);
64 if (!entry_->good())
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;
69 }
70
71 const syncable::Entry* ReadNode::GetEntry() const {
72 return entry_;
73 }
74
75 const BaseTransaction* ReadNode::GetTransaction() const {
76 return transaction_;
77 }
78
79 BaseNode::InitByLookupResult ReadNode::InitByTagLookup(
80 const std::string& tag) {
81 DCHECK(!entry_) << "Init called twice";
82 if (tag.empty())
83 return INIT_FAILED_PRECONDITION;
84 syncable::BaseTransaction* trans = transaction_->GetWrappedTrans();
85 entry_ = new syncable::Entry(trans, syncable::GET_BY_SERVER_TAG, tag);
86 if (!entry_->good())
87 return INIT_FAILED_ENTRY_NOT_GOOD;
88 if (entry_->Get(syncable::IS_DEL))
89 return INIT_FAILED_ENTRY_IS_DEL;
90 syncable::ModelType model_type = GetModelType();
91 LOG_IF(WARNING, model_type == syncable::UNSPECIFIED ||
92 model_type == syncable::TOP_LEVEL_FOLDER)
93 << "SyncAPI InitByTagLookup referencing unusually typed object.";
94 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY;
95 }
96
97 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/read_node.h ('k') | chrome/browser/sync/internal_api/read_transaction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698