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

Side by Side Diff: chrome/browser/sync/glue/generic_change_processor.cc

Issue 14667013: sync: Better iteration in GenericChangeProcessor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review fixes Created 7 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/sync/glue/generic_change_processor_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/sync/glue/generic_change_processor.h" 5 #include "chrome/browser/sync/glue/generic_change_processor.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 syncer::SyncError error(FROM_HERE, 109 syncer::SyncError error(FROM_HERE,
110 "Server did not create the top-level " + type_name + 110 "Server did not create the top-level " + type_name +
111 " node. We might be running against an out-of-date server.", 111 " node. We might be running against an out-of-date server.",
112 type); 112 type);
113 return error; 113 return error;
114 } 114 }
115 115
116 // TODO(akalin): We'll have to do a tree traversal for bookmarks. 116 // TODO(akalin): We'll have to do a tree traversal for bookmarks.
117 DCHECK_NE(type, syncer::BOOKMARKS); 117 DCHECK_NE(type, syncer::BOOKMARKS);
118 118
119 int64 sync_child_id = root.GetFirstChildId(); 119 std::vector<int64> child_ids;
120 while (sync_child_id != syncer::kInvalidId) { 120 root.GetChildIds(&child_ids);
121
122 for (std::vector<int64>::iterator it = child_ids.begin();
123 it != child_ids.end(); ++it) {
121 syncer::ReadNode sync_child_node(&trans); 124 syncer::ReadNode sync_child_node(&trans);
122 if (sync_child_node.InitByIdLookup(sync_child_id) != 125 if (sync_child_node.InitByIdLookup(*it) !=
123 syncer::BaseNode::INIT_OK) { 126 syncer::BaseNode::INIT_OK) {
124 syncer::SyncError error(FROM_HERE, 127 syncer::SyncError error(FROM_HERE,
125 "Failed to fetch child node for type " + type_name + ".", 128 "Failed to fetch child node for type " + type_name + ".",
126 type); 129 type);
127 return error; 130 return error;
128 } 131 }
129 current_sync_data->push_back(syncer::SyncData::CreateRemoteData( 132 current_sync_data->push_back(syncer::SyncData::CreateRemoteData(
130 sync_child_node.GetId(), sync_child_node.GetEntitySpecifics())); 133 sync_child_node.GetId(), sync_child_node.GetEntitySpecifics()));
131 sync_child_id = sync_child_node.GetSuccessorId();
132 } 134 }
133 return syncer::SyncError(); 135 return syncer::SyncError();
134 } 136 }
135 137
136 int GenericChangeProcessor::GetSyncCountForType(syncer::ModelType type) { 138 int GenericChangeProcessor::GetSyncCountForType(syncer::ModelType type) {
137 syncer::ReadTransaction trans(FROM_HERE, share_handle()); 139 syncer::ReadTransaction trans(FROM_HERE, share_handle());
138 syncer::ReadNode root(&trans); 140 syncer::ReadNode root(&trans);
139 if (root.InitByTagLookup(syncer::ModelTypeToRootTag(type)) != 141 if (root.InitByTagLookup(syncer::ModelTypeToRootTag(type)) !=
140 syncer::BaseNode::INIT_OK) 142 syncer::BaseNode::INIT_OK)
141 return 0; 143 return 0;
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 void GenericChangeProcessor::StartImpl(Profile* profile) { 511 void GenericChangeProcessor::StartImpl(Profile* profile) {
510 DCHECK(CalledOnValidThread()); 512 DCHECK(CalledOnValidThread());
511 } 513 }
512 514
513 syncer::UserShare* GenericChangeProcessor::share_handle() const { 515 syncer::UserShare* GenericChangeProcessor::share_handle() const {
514 DCHECK(CalledOnValidThread()); 516 DCHECK(CalledOnValidThread());
515 return share_handle_; 517 return share_handle_;
516 } 518 }
517 519
518 } // namespace browser_sync 520 } // namespace browser_sync
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/glue/generic_change_processor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698