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