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

Side by Side Diff: chrome/browser/sync/glue/bookmark_model_associator.h

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_ 5 #ifndef CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_
6 #define CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "chrome/browser/sync/glue/data_type_controller.h" 16 #include "chrome/browser/sync/glue/data_type_controller.h"
17 #include "chrome/browser/sync/glue/data_type_error_handler.h" 17 #include "chrome/browser/sync/glue/data_type_error_handler.h"
18 #include "chrome/browser/sync/glue/model_associator.h" 18 #include "chrome/browser/sync/glue/model_associator.h"
19 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" 19 #include "sync/internal_api/public/util/unrecoverable_error_handler.h"
20 20
21 class BookmarkModel; 21 class BookmarkModel;
22 class BookmarkNode; 22 class BookmarkNode;
23 23
24 namespace csync { 24 namespace syncer {
25 class BaseNode; 25 class BaseNode;
26 struct UserShare; 26 struct UserShare;
27 } 27 }
28 28
29 namespace browser_sync { 29 namespace browser_sync {
30 30
31 // Contains all model association related logic: 31 // Contains all model association related logic:
32 // * Algorithm to associate bookmark model and sync model. 32 // * Algorithm to associate bookmark model and sync model.
33 // * Methods to get a bookmark node for a given sync node and vice versa. 33 // * Methods to get a bookmark node for a given sync node and vice versa.
34 // * Persisting model associations and loading them back. 34 // * Persisting model associations and loading them back.
35 class BookmarkModelAssociator 35 class BookmarkModelAssociator
36 : public PerDataTypeAssociatorInterface<BookmarkNode, int64> { 36 : public PerDataTypeAssociatorInterface<BookmarkNode, int64> {
37 public: 37 public:
38 static syncable::ModelType model_type() { return syncable::BOOKMARKS; } 38 static syncable::ModelType model_type() { return syncable::BOOKMARKS; }
39 // |expect_mobile_bookmarks_folder| controls whether or not we 39 // |expect_mobile_bookmarks_folder| controls whether or not we
40 // expect the mobile bookmarks permanent folder to be created. 40 // expect the mobile bookmarks permanent folder to be created.
41 // Should be set to true only by mobile clients. 41 // Should be set to true only by mobile clients.
42 BookmarkModelAssociator( 42 BookmarkModelAssociator(
43 BookmarkModel* bookmark_model, 43 BookmarkModel* bookmark_model,
44 csync::UserShare* user_share, 44 syncer::UserShare* user_share,
45 DataTypeErrorHandler* unrecoverable_error_handler, 45 DataTypeErrorHandler* unrecoverable_error_handler,
46 bool expect_mobile_bookmarks_folder); 46 bool expect_mobile_bookmarks_folder);
47 virtual ~BookmarkModelAssociator(); 47 virtual ~BookmarkModelAssociator();
48 48
49 // Updates the visibility of the permanents node in the BookmarkModel. 49 // Updates the visibility of the permanents node in the BookmarkModel.
50 void UpdatePermanentNodeVisibility(); 50 void UpdatePermanentNodeVisibility();
51 51
52 // AssociatorInterface implementation. 52 // AssociatorInterface implementation.
53 // 53 //
54 // AssociateModels iterates through both the sync and the browser 54 // AssociateModels iterates through both the sync and the browser
55 // bookmark model, looking for matched pairs of items. For any pairs it 55 // bookmark model, looking for matched pairs of items. For any pairs it
56 // finds, it will call AssociateSyncID. For any unmatched items, 56 // finds, it will call AssociateSyncID. For any unmatched items,
57 // MergeAndAssociateModels will try to repair the match, e.g. by adding a new 57 // MergeAndAssociateModels will try to repair the match, e.g. by adding a new
58 // node. After successful completion, the models should be identical and 58 // node. After successful completion, the models should be identical and
59 // corresponding. Returns true on success. On failure of this step, we 59 // corresponding. Returns true on success. On failure of this step, we
60 // should abort the sync operation and report an error to the user. 60 // should abort the sync operation and report an error to the user.
61 virtual csync::SyncError AssociateModels() OVERRIDE; 61 virtual syncer::SyncError AssociateModels() OVERRIDE;
62 62
63 virtual csync::SyncError DisassociateModels() OVERRIDE; 63 virtual syncer::SyncError DisassociateModels() OVERRIDE;
64 64
65 // The has_nodes out param is true if the sync model has nodes other 65 // The has_nodes out param is true if the sync model has nodes other
66 // than the permanent tagged nodes. 66 // than the permanent tagged nodes.
67 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes) OVERRIDE; 67 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes) OVERRIDE;
68 68
69 // Returns sync id for the given bookmark node id. 69 // Returns sync id for the given bookmark node id.
70 // Returns csync::kInvalidId if the sync node is not found for the given 70 // Returns syncer::kInvalidId if the sync node is not found for the given
71 // bookmark node id. 71 // bookmark node id.
72 virtual int64 GetSyncIdFromChromeId(const int64& node_id) OVERRIDE; 72 virtual int64 GetSyncIdFromChromeId(const int64& node_id) OVERRIDE;
73 73
74 // Returns the bookmark node for the given sync id. 74 // Returns the bookmark node for the given sync id.
75 // Returns NULL if no bookmark node is found for the given sync id. 75 // Returns NULL if no bookmark node is found for the given sync id.
76 virtual const BookmarkNode* GetChromeNodeFromSyncId(int64 sync_id) OVERRIDE; 76 virtual const BookmarkNode* GetChromeNodeFromSyncId(int64 sync_id) OVERRIDE;
77 77
78 // Initializes the given sync node from the given bookmark node id. 78 // Initializes the given sync node from the given bookmark node id.
79 // Returns false if no sync node was found for the given bookmark node id or 79 // Returns false if no sync node was found for the given bookmark node id or
80 // if the initialization of sync node fails. 80 // if the initialization of sync node fails.
81 virtual bool InitSyncNodeFromChromeId( 81 virtual bool InitSyncNodeFromChromeId(
82 const int64& node_id, 82 const int64& node_id,
83 csync::BaseNode* sync_node) OVERRIDE; 83 syncer::BaseNode* sync_node) OVERRIDE;
84 84
85 // Associates the given bookmark node with the given sync id. 85 // Associates the given bookmark node with the given sync id.
86 virtual void Associate(const BookmarkNode* node, int64 sync_id) OVERRIDE; 86 virtual void Associate(const BookmarkNode* node, int64 sync_id) OVERRIDE;
87 // Remove the association that corresponds to the given sync id. 87 // Remove the association that corresponds to the given sync id.
88 virtual void Disassociate(int64 sync_id) OVERRIDE; 88 virtual void Disassociate(int64 sync_id) OVERRIDE;
89 89
90 virtual void AbortAssociation() OVERRIDE { 90 virtual void AbortAssociation() OVERRIDE {
91 // No implementation needed, this associator runs on the main 91 // No implementation needed, this associator runs on the main
92 // thread. 92 // thread.
93 } 93 }
(...skipping 17 matching lines...) Expand all
111 // Persists all dirty associations. 111 // Persists all dirty associations.
112 void PersistAssociations(); 112 void PersistAssociations();
113 113
114 // Loads the persisted associations into in-memory maps. 114 // Loads the persisted associations into in-memory maps.
115 // If the persisted associations are out-of-date due to some reason, returns 115 // If the persisted associations are out-of-date due to some reason, returns
116 // false; otherwise returns true. 116 // false; otherwise returns true.
117 bool LoadAssociations(); 117 bool LoadAssociations();
118 118
119 // Matches up the bookmark model and the sync model to build model 119 // Matches up the bookmark model and the sync model to build model
120 // associations. 120 // associations.
121 csync::SyncError BuildAssociations(); 121 syncer::SyncError BuildAssociations();
122 122
123 // Associate a top-level node of the bookmark model with a permanent node in 123 // Associate a top-level node of the bookmark model with a permanent node in
124 // the sync domain. Such permanent nodes are identified by a tag that is 124 // the sync domain. Such permanent nodes are identified by a tag that is
125 // well known to the server and the client, and is unique within a particular 125 // well known to the server and the client, and is unique within a particular
126 // user's share. For example, "other_bookmarks" is the tag for the Other 126 // user's share. For example, "other_bookmarks" is the tag for the Other
127 // Bookmarks folder. The sync nodes are server-created. 127 // Bookmarks folder. The sync nodes are server-created.
128 csync::SyncError AssociateTaggedPermanentNode( 128 syncer::SyncError AssociateTaggedPermanentNode(
129 const BookmarkNode* permanent_node, 129 const BookmarkNode* permanent_node,
130 const std::string& tag) WARN_UNUSED_RESULT; 130 const std::string& tag) WARN_UNUSED_RESULT;
131 131
132 // Compare the properties of a pair of nodes from either domain. 132 // Compare the properties of a pair of nodes from either domain.
133 bool NodesMatch(const BookmarkNode* bookmark, 133 bool NodesMatch(const BookmarkNode* bookmark,
134 const csync::BaseNode* sync_node) const; 134 const syncer::BaseNode* sync_node) const;
135 135
136 BookmarkModel* bookmark_model_; 136 BookmarkModel* bookmark_model_;
137 csync::UserShare* user_share_; 137 syncer::UserShare* user_share_;
138 DataTypeErrorHandler* unrecoverable_error_handler_; 138 DataTypeErrorHandler* unrecoverable_error_handler_;
139 const bool expect_mobile_bookmarks_folder_; 139 const bool expect_mobile_bookmarks_folder_;
140 BookmarkIdToSyncIdMap id_map_; 140 BookmarkIdToSyncIdMap id_map_;
141 SyncIdToBookmarkNodeMap id_map_inverse_; 141 SyncIdToBookmarkNodeMap id_map_inverse_;
142 // Stores sync ids for dirty associations. 142 // Stores sync ids for dirty associations.
143 DirtyAssociationsSyncIds dirty_associations_sync_ids_; 143 DirtyAssociationsSyncIds dirty_associations_sync_ids_;
144 144
145 // Used to post PersistAssociation tasks to the current message loop and 145 // Used to post PersistAssociation tasks to the current message loop and
146 // guarantees no invocations can occur if |this| has been deleted. (This 146 // guarantees no invocations can occur if |this| has been deleted. (This
147 // allows this class to be non-refcounted). 147 // allows this class to be non-refcounted).
148 base::WeakPtrFactory<BookmarkModelAssociator> weak_factory_; 148 base::WeakPtrFactory<BookmarkModelAssociator> weak_factory_;
149 149
150 int number_of_new_sync_nodes_created_at_association_; 150 int number_of_new_sync_nodes_created_at_association_;
151 151
152 DISALLOW_COPY_AND_ASSIGN(BookmarkModelAssociator); 152 DISALLOW_COPY_AND_ASSIGN(BookmarkModelAssociator);
153 }; 153 };
154 154
155 } // namespace browser_sync 155 } // namespace browser_sync
156 156
157 #endif // CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_ 157 #endif // CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_ASSOCIATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698