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

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

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

Powered by Google App Engine
This is Rietveld 408576698