OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/hash_tables.h" | 9 #include "base/hash_tables.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/task.h" | 11 #include "base/task.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/bookmarks/bookmark_model.h" | 13 #include "chrome/browser/bookmarks/bookmark_model.h" |
14 #include "chrome/browser/browser_thread.h" | 14 #include "chrome/browser/browser_thread.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sync/engine/syncapi.h" | 16 #include "chrome/browser/sync/engine/syncapi.h" |
17 #include "chrome/browser/sync/syncable/syncable.h" | |
tim (not reviewing)
2010/12/13 19:24:33
illegal include
lipalani
2010/12/15 09:08:33
Done.
| |
17 #include "chrome/browser/sync/glue/bookmark_change_processor.h" | 18 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
18 #include "chrome/browser/sync/profile_sync_service.h" | 19 #include "chrome/browser/sync/profile_sync_service.h" |
19 | 20 |
20 namespace browser_sync { | 21 namespace browser_sync { |
21 | 22 |
22 // The sync protocol identifies top-level entities by means of well-known tags, | 23 // The sync protocol identifies top-level entities by means of well-known tags, |
23 // which should not be confused with titles. Each tag corresponds to a | 24 // which should not be confused with titles. Each tag corresponds to a |
24 // singleton instance of a particular top-level node in a user's share; the | 25 // singleton instance of a particular top-level node in a user's share; the |
25 // tags are consistent across users. The tags allow us to locate the specific | 26 // tags are consistent across users. The tags allow us to locate the specific |
26 // folders whose contents we care about synchronizing, without having to do a | 27 // folders whose contents we care about synchronizing, without having to do a |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 const BookmarkNode* BookmarkNodeIdIndex::Find(int64 id) const { | 153 const BookmarkNode* BookmarkNodeIdIndex::Find(int64 id) const { |
153 BookmarkIdMap::const_iterator iter = node_index_.find(id); | 154 BookmarkIdMap::const_iterator iter = node_index_.find(id); |
154 return iter == node_index_.end() ? NULL : iter->second; | 155 return iter == node_index_.end() ? NULL : iter->second; |
155 } | 156 } |
156 | 157 |
157 BookmarkModelAssociator::BookmarkModelAssociator( | 158 BookmarkModelAssociator::BookmarkModelAssociator( |
158 ProfileSyncService* sync_service, | 159 ProfileSyncService* sync_service, |
159 UnrecoverableErrorHandler* persist_ids_error_handler) | 160 UnrecoverableErrorHandler* persist_ids_error_handler) |
160 : sync_service_(sync_service), | 161 : sync_service_(sync_service), |
161 persist_ids_error_handler_(persist_ids_error_handler), | 162 persist_ids_error_handler_(persist_ids_error_handler), |
163 number_of_new_sync_nodes_created_at_association_(0), | |
162 ALLOW_THIS_IN_INITIALIZER_LIST(persist_associations_(this)) { | 164 ALLOW_THIS_IN_INITIALIZER_LIST(persist_associations_(this)) { |
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
164 DCHECK(sync_service_); | 166 DCHECK(sync_service_); |
165 DCHECK(persist_ids_error_handler_); | 167 DCHECK(persist_ids_error_handler_); |
166 } | 168 } |
167 | 169 |
168 BookmarkModelAssociator::~BookmarkModelAssociator() { | 170 BookmarkModelAssociator::~BookmarkModelAssociator() { |
169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
170 } | 172 } |
171 | 173 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 // At this point all the children nodes of the parent sync node have | 408 // At this point all the children nodes of the parent sync node have |
407 // corresponding children in the parent bookmark node and they are all in | 409 // corresponding children in the parent bookmark node and they are all in |
408 // the right positions: from 0 to index - 1. | 410 // the right positions: from 0 to index - 1. |
409 // So the children starting from index in the parent bookmark node are the | 411 // So the children starting from index in the parent bookmark node are the |
410 // ones that are not present in the parent sync node. So create them. | 412 // ones that are not present in the parent sync node. So create them. |
411 for (int i = index; i < parent_node->GetChildCount(); ++i) { | 413 for (int i = index; i < parent_node->GetChildCount(); ++i) { |
412 sync_child_id = BookmarkChangeProcessor::CreateSyncNode( | 414 sync_child_id = BookmarkChangeProcessor::CreateSyncNode( |
413 parent_node, model, i, &trans, this, sync_service_); | 415 parent_node, model, i, &trans, this, sync_service_); |
414 if (parent_node->GetChild(i)->is_folder()) | 416 if (parent_node->GetChild(i)->is_folder()) |
415 dfs_stack.push(sync_child_id); | 417 dfs_stack.push(sync_child_id); |
418 number_of_new_sync_nodes_created_at_association_++; | |
416 } | 419 } |
417 } | 420 } |
421 | |
422 if (sync_service_->backend()->GetAutofillMigrationState() != | |
423 syncable::MIGRATED) { | |
tim (not reviewing)
2010/12/13 19:24:33
4 space indent
lipalani
2010/12/14 21:05:57
Done.
| |
424 syncable::AutofillMigrationDebugInfo debug_info; | |
425 debug_info.bookmarks_added_during_migration = | |
426 number_of_new_sync_nodes_created_at_association_; | |
tim (not reviewing)
2010/12/13 19:24:33
4 space indent
lipalani
2010/12/14 21:05:57
Done.
| |
427 sync_service_->backend()->SetAutofillMigrationDebugInfo( | |
428 syncable::AutofillMigrationDebugInfo::BOOKMARK_ADDED, | |
tim (not reviewing)
2010/12/13 19:24:33
4 space indent
lipalani
2010/12/14 21:05:57
Done.
| |
429 debug_info); | |
430 } | |
418 return true; | 431 return true; |
419 } | 432 } |
420 | 433 |
421 void BookmarkModelAssociator::PostPersistAssociationsTask() { | 434 void BookmarkModelAssociator::PostPersistAssociationsTask() { |
422 // No need to post a task if a task is already pending. | 435 // No need to post a task if a task is already pending. |
423 if (!persist_associations_.empty()) | 436 if (!persist_associations_.empty()) |
424 return; | 437 return; |
425 MessageLoop::current()->PostTask( | 438 MessageLoop::current()->PostTask( |
426 FROM_HERE, | 439 FROM_HERE, |
427 persist_associations_.NewRunnableMethod( | 440 persist_associations_.NewRunnableMethod( |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 | 553 |
541 // It's possible that the number of nodes in the bookmark model is not the | 554 // It's possible that the number of nodes in the bookmark model is not the |
542 // same as number of nodes in the sync model. This can happen when the sync | 555 // same as number of nodes in the sync model. This can happen when the sync |
543 // model doesn't get a chance to persist its changes, for example when | 556 // model doesn't get a chance to persist its changes, for example when |
544 // Chrome does not shut down gracefully. In such cases we can't trust the | 557 // Chrome does not shut down gracefully. In such cases we can't trust the |
545 // loaded associations. | 558 // loaded associations. |
546 return sync_node_count == id_index.count(); | 559 return sync_node_count == id_index.count(); |
547 } | 560 } |
548 | 561 |
549 } // namespace browser_sync | 562 } // namespace browser_sync |
OLD | NEW |