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

Side by Side Diff: chrome/browser/sync/internal_api/write_node.h

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: sync to head 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 #ifndef CHROME_BROWSER_SYNC_INTERNAL_API_WRITE_NODE_H_
6 #define CHROME_BROWSER_SYNC_INTERNAL_API_WRITE_NODE_H_
7 #pragma once
8
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "chrome/browser/sync/internal_api/base_node.h"
15 #include "sync/syncable/model_type.h"
16
17 namespace browser_sync {
18 class Cryptographer;
19 class TestBookmarkModelAssociator;
20 }
21
22 namespace syncable {
23 class Entry;
24 class MutableEntry;
25 }
26
27 namespace sync_pb {
28 class AppSpecifics;
29 class AutofillSpecifics;
30 class AutofillProfileSpecifics;
31 class BookmarkSpecifics;
32 class EntitySpecifics;
33 class ExtensionSpecifics;
34 class SessionSpecifics;
35 class NigoriSpecifics;
36 class PasswordSpecificsData;
37 class ThemeSpecifics;
38 class TypedUrlSpecifics;
39 }
40
41 namespace sync_api {
42
43 class WriteTransaction;
44
45 // WriteNode extends BaseNode to add mutation, and wraps
46 // syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode.
47 class WriteNode : public BaseNode {
48 public:
49 // Create a WriteNode using the given transaction.
50 explicit WriteNode(WriteTransaction* transaction);
51 virtual ~WriteNode();
52
53 // A client must use one (and only one) of the following Init variants to
54 // populate the node.
55
56 // BaseNode implementation.
57 virtual bool InitByIdLookup(int64 id) OVERRIDE;
58 virtual bool InitByClientTagLookup(syncable::ModelType model_type,
59 const std::string& tag) OVERRIDE;
60
61 // Create a new node with the specified parent and predecessor. |model_type|
62 // dictates the type of the item, and controls which EntitySpecifics proto
63 // extension can be used with this item. Use a NULL |predecessor|
64 // to indicate that this is to be the first child.
65 // |predecessor| must be a child of |new_parent| or NULL. Returns false on
66 // failure.
67 bool InitByCreation(syncable::ModelType model_type,
68 const BaseNode& parent,
69 const BaseNode* predecessor);
70
71 // Create nodes using this function if they're unique items that
72 // you want to fetch using client_tag. Note that the behavior of these
73 // items is slightly different than that of normal items.
74 // Most importantly, if it exists locally, this function will
75 // actually undelete it
76 // Client unique tagged nodes must NOT be folders.
77 bool InitUniqueByCreation(syncable::ModelType model_type,
78 const BaseNode& parent,
79 const std::string& client_tag);
80
81 // Each server-created permanent node is tagged with a unique string.
82 // Look up the node with the particular tag. If it does not exist,
83 // return false.
84 bool InitByTagLookup(const std::string& tag);
85
86 // These Set() functions correspond to the Get() functions of BaseNode.
87 void SetIsFolder(bool folder);
88 void SetTitle(const std::wstring& title);
89
90 // External ID is a client-only field, so setting it doesn't cause the item to
91 // be synced again.
92 void SetExternalId(int64 external_id);
93
94 // Remove this node and its children.
95 void Remove();
96
97 // Set a new parent and position. Position is specified by |predecessor|; if
98 // it is NULL, the node is moved to the first position. |predecessor| must
99 // be a child of |new_parent| or NULL. Returns false on failure..
100 bool SetPosition(const BaseNode& new_parent, const BaseNode* predecessor);
101
102 // Set the bookmark specifics (url and favicon).
103 // Should only be called if GetModelType() == BOOKMARK.
104 void SetBookmarkSpecifics(const sync_pb::BookmarkSpecifics& specifics);
105
106 // Legacy, bookmark-specific setters that wrap SetBookmarkSpecifics() above.
107 // Should only be called if GetModelType() == BOOKMARK.
108 // TODO(ncarter): Remove these two datatype-specific accessors.
109 void SetURL(const GURL& url);
110 void SetFaviconBytes(const std::vector<unsigned char>& bytes);
111
112 // Generic set specifics method. Will extract the model type from |specifics|.
113 void SetEntitySpecifics(const sync_pb::EntitySpecifics& specifics);
114
115 // Resets the EntitySpecifics for this node based on the unencrypted data.
116 // Will encrypt if necessary.
117 void ResetFromSpecifics();
118
119 // TODO(sync): Remove the setters below when the corresponding data
120 // types are ported to the new sync service API.
121
122 // Set the app specifics (id, update url, enabled state, etc).
123 // Should only be called if GetModelType() == APPS.
124 void SetAppSpecifics(const sync_pb::AppSpecifics& specifics);
125
126 // Set the autofill specifics (name and value).
127 // Should only be called if GetModelType() == AUTOFILL.
128 void SetAutofillSpecifics(const sync_pb::AutofillSpecifics& specifics);
129
130 void SetAutofillProfileSpecifics(
131 const sync_pb::AutofillProfileSpecifics& specifics);
132
133 // Set the nigori specifics.
134 // Should only be called if GetModelType() == NIGORI.
135 void SetNigoriSpecifics(const sync_pb::NigoriSpecifics& specifics);
136
137 // Set the password specifics.
138 // Should only be called if GetModelType() == PASSWORD.
139 void SetPasswordSpecifics(const sync_pb::PasswordSpecificsData& specifics);
140
141 // Set the theme specifics (name and value).
142 // Should only be called if GetModelType() == THEME.
143 void SetThemeSpecifics(const sync_pb::ThemeSpecifics& specifics);
144
145 // Set the typed_url specifics (url, title, typed_count, etc).
146 // Should only be called if GetModelType() == TYPED_URLS.
147 void SetTypedUrlSpecifics(const sync_pb::TypedUrlSpecifics& specifics);
148
149 // Set the extension specifics (id, update url, enabled state, etc).
150 // Should only be called if GetModelType() == EXTENSIONS.
151 void SetExtensionSpecifics(const sync_pb::ExtensionSpecifics& specifics);
152
153 // Set the session specifics (windows, tabs, navigations etc.).
154 // Should only be called if GetModelType() == SESSIONS.
155 void SetSessionSpecifics(const sync_pb::SessionSpecifics& specifics);
156
157 // Implementation of BaseNode's abstract virtual accessors.
158 virtual const syncable::Entry* GetEntry() const OVERRIDE;
159
160 virtual const BaseTransaction* GetTransaction() const OVERRIDE;
161
162 private:
163 friend class browser_sync::TestBookmarkModelAssociator;
164 FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, EncryptBookmarksWithLegacyData);
165
166 void* operator new(size_t size); // Node is meant for stack use only.
167
168 // Helper to set model type. This will clear any specifics data.
169 void PutModelType(syncable::ModelType model_type);
170
171 // Helper to set the previous node.
172 bool PutPredecessor(const BaseNode* predecessor) WARN_UNUSED_RESULT;
173
174 // Sets IS_UNSYNCED and SYNCING to ensure this entry is considered in an
175 // upcoming commit pass.
176 void MarkForSyncing();
177
178 // The underlying syncable object which this class wraps.
179 syncable::MutableEntry* entry_;
180
181 // The sync API transaction that is the parent of this node.
182 WriteTransaction* transaction_;
183
184 DISALLOW_COPY_AND_ASSIGN(WriteNode);
185 };
186
187 } // namespace sync_api
188
189 #endif // CHROME_BROWSER_SYNC_INTERNAL_API_WRITE_NODE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698