OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "chrome/browser/sync/glue/bookmark_model_associator.h" | 5 #include "chrome/browser/sync/glue/bookmark_model_associator.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 Profile* profile, | 253 Profile* profile, |
254 syncer::UserShare* user_share, | 254 syncer::UserShare* user_share, |
255 sync_driver::DataTypeErrorHandler* unrecoverable_error_handler, | 255 sync_driver::DataTypeErrorHandler* unrecoverable_error_handler, |
256 bool expect_mobile_bookmarks_folder) | 256 bool expect_mobile_bookmarks_folder) |
257 : bookmark_model_(bookmark_model), | 257 : bookmark_model_(bookmark_model), |
258 profile_(profile), | 258 profile_(profile), |
259 user_share_(user_share), | 259 user_share_(user_share), |
260 unrecoverable_error_handler_(unrecoverable_error_handler), | 260 unrecoverable_error_handler_(unrecoverable_error_handler), |
261 expect_mobile_bookmarks_folder_(expect_mobile_bookmarks_folder), | 261 expect_mobile_bookmarks_folder_(expect_mobile_bookmarks_folder), |
262 weak_factory_(this) { | 262 weak_factory_(this) { |
263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 263 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
264 DCHECK(bookmark_model_); | 264 DCHECK(bookmark_model_); |
265 DCHECK(user_share_); | 265 DCHECK(user_share_); |
266 DCHECK(unrecoverable_error_handler_); | 266 DCHECK(unrecoverable_error_handler_); |
267 } | 267 } |
268 | 268 |
269 BookmarkModelAssociator::~BookmarkModelAssociator() { | 269 BookmarkModelAssociator::~BookmarkModelAssociator() { |
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 270 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
271 } | 271 } |
272 | 272 |
273 void BookmarkModelAssociator::UpdatePermanentNodeVisibility() { | 273 void BookmarkModelAssociator::UpdatePermanentNodeVisibility() { |
274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 274 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
275 DCHECK(bookmark_model_->loaded()); | 275 DCHECK(bookmark_model_->loaded()); |
276 | 276 |
277 BookmarkNode::Type bookmark_node_types[] = { | 277 BookmarkNode::Type bookmark_node_types[] = { |
278 BookmarkNode::BOOKMARK_BAR, | 278 BookmarkNode::BOOKMARK_BAR, |
279 BookmarkNode::OTHER_NODE, | 279 BookmarkNode::OTHER_NODE, |
280 BookmarkNode::MOBILE, | 280 BookmarkNode::MOBILE, |
281 }; | 281 }; |
282 for (size_t i = 0; i < arraysize(bookmark_node_types); ++i) { | 282 for (size_t i = 0; i < arraysize(bookmark_node_types); ++i) { |
283 int64 id = bookmark_model_->PermanentNode(bookmark_node_types[i])->id(); | 283 int64 id = bookmark_model_->PermanentNode(bookmark_node_types[i])->id(); |
284 bookmark_model_->SetPermanentNodeVisible( | 284 bookmark_model_->SetPermanentNodeVisible( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 if (sync_id == syncer::kInvalidId) | 316 if (sync_id == syncer::kInvalidId) |
317 return false; | 317 return false; |
318 if (sync_node->InitByIdLookup(sync_id) != syncer::BaseNode::INIT_OK) | 318 if (sync_node->InitByIdLookup(sync_id) != syncer::BaseNode::INIT_OK) |
319 return false; | 319 return false; |
320 DCHECK(sync_node->GetId() == sync_id); | 320 DCHECK(sync_node->GetId() == sync_id); |
321 return true; | 321 return true; |
322 } | 322 } |
323 | 323 |
324 void BookmarkModelAssociator::Associate(const BookmarkNode* node, | 324 void BookmarkModelAssociator::Associate(const BookmarkNode* node, |
325 int64 sync_id) { | 325 int64 sync_id) { |
326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 326 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
327 int64 node_id = node->id(); | 327 int64 node_id = node->id(); |
328 DCHECK_NE(sync_id, syncer::kInvalidId); | 328 DCHECK_NE(sync_id, syncer::kInvalidId); |
329 DCHECK(id_map_.find(node_id) == id_map_.end()); | 329 DCHECK(id_map_.find(node_id) == id_map_.end()); |
330 DCHECK(id_map_inverse_.find(sync_id) == id_map_inverse_.end()); | 330 DCHECK(id_map_inverse_.find(sync_id) == id_map_inverse_.end()); |
331 id_map_[node_id] = sync_id; | 331 id_map_[node_id] = sync_id; |
332 id_map_inverse_[sync_id] = node; | 332 id_map_inverse_[sync_id] = node; |
333 dirty_associations_sync_ids_.insert(sync_id); | 333 dirty_associations_sync_ids_.insert(sync_id); |
334 PostPersistAssociationsTask(); | 334 PostPersistAssociationsTask(); |
335 UpdatePermanentNodeVisibility(); | 335 UpdatePermanentNodeVisibility(); |
336 } | 336 } |
337 | 337 |
338 void BookmarkModelAssociator::Disassociate(int64 sync_id) { | 338 void BookmarkModelAssociator::Disassociate(int64 sync_id) { |
339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 339 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
340 SyncIdToBookmarkNodeMap::iterator iter = id_map_inverse_.find(sync_id); | 340 SyncIdToBookmarkNodeMap::iterator iter = id_map_inverse_.find(sync_id); |
341 if (iter == id_map_inverse_.end()) | 341 if (iter == id_map_inverse_.end()) |
342 return; | 342 return; |
343 id_map_.erase(iter->second->id()); | 343 id_map_.erase(iter->second->id()); |
344 id_map_inverse_.erase(iter); | 344 id_map_inverse_.erase(iter); |
345 dirty_associations_sync_ids_.erase(sync_id); | 345 dirty_associations_sync_ids_.erase(sync_id); |
346 } | 346 } |
347 | 347 |
348 bool BookmarkModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { | 348 bool BookmarkModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { |
349 DCHECK(has_nodes); | 349 DCHECK(has_nodes); |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 syncer::SyncError::PERSISTENCE_ERROR, | 835 syncer::SyncError::PERSISTENCE_ERROR, |
836 message, | 836 message, |
837 syncer::BOOKMARKS); | 837 syncer::BOOKMARKS); |
838 } | 838 } |
839 } | 839 } |
840 } | 840 } |
841 return syncer::SyncError(); | 841 return syncer::SyncError(); |
842 } | 842 } |
843 | 843 |
844 } // namespace browser_sync | 844 } // namespace browser_sync |
OLD | NEW |