OLD | NEW |
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/typed_url_change_processor.h" | 5 #include "chrome/browser/sync/glue/typed_url_change_processor.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 159 } |
160 | 160 |
161 if (std::find_if(visit_vector.begin(), visit_vector.end(), | 161 if (std::find_if(visit_vector.begin(), visit_vector.end(), |
162 [](const history::VisitRow& visit) { | 162 [](const history::VisitRow& visit) { |
163 return ui::PageTransitionCoreTypeIs( | 163 return ui::PageTransitionCoreTypeIs( |
164 visit.transition, ui::PAGE_TRANSITION_TYPED); | 164 visit.transition, ui::PAGE_TRANSITION_TYPED); |
165 }) == visit_vector.end()) | 165 }) == visit_vector.end()) |
166 // This URL has no TYPED visits, don't sync it. | 166 // This URL has no TYPED visits, don't sync it. |
167 return false; | 167 return false; |
168 | 168 |
169 syncer::ReadNode typed_url_root(trans); | |
170 if (typed_url_root.InitTypeRoot(syncer::TYPED_URLS) != | |
171 syncer::BaseNode::INIT_OK) { | |
172 syncer::SyncError error(FROM_HERE, | |
173 syncer::SyncError::DATATYPE_ERROR, | |
174 "No top level folder", | |
175 syncer::TYPED_URLS); | |
176 error_handler()->OnSingleDataTypeUnrecoverableError(error); | |
177 return false; | |
178 } | |
179 | |
180 if (model_associator_->ShouldIgnoreUrl(url.url())) | 169 if (model_associator_->ShouldIgnoreUrl(url.url())) |
181 return true; | 170 return true; |
182 | 171 |
183 DCHECK(!visit_vector.empty()); | 172 DCHECK(!visit_vector.empty()); |
184 std::string tag = url.url().spec(); | 173 std::string tag = url.url().spec(); |
185 syncer::WriteNode update_node(trans); | 174 syncer::WriteNode update_node(trans); |
186 syncer::BaseNode::InitByLookupResult result = | 175 syncer::BaseNode::InitByLookupResult result = |
187 update_node.InitByClientTagLookup(syncer::TYPED_URLS, tag); | 176 update_node.InitByClientTagLookup(syncer::TYPED_URLS, tag); |
188 if (result == syncer::BaseNode::INIT_OK) { | 177 if (result == syncer::BaseNode::INIT_OK) { |
189 model_associator_->WriteToSyncNode(url, visit_vector, &update_node); | 178 model_associator_->WriteToSyncNode(url, visit_vector, &update_node); |
190 } else if (result == syncer::BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY) { | 179 } else if (result == syncer::BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY) { |
191 syncer::SyncError error(FROM_HERE, | 180 syncer::SyncError error(FROM_HERE, |
192 syncer::SyncError::DATATYPE_ERROR, | 181 syncer::SyncError::DATATYPE_ERROR, |
193 "Failed to decrypt.", | 182 "Failed to decrypt.", |
194 syncer::TYPED_URLS); | 183 syncer::TYPED_URLS); |
195 error_handler()->OnSingleDataTypeUnrecoverableError(error); | 184 error_handler()->OnSingleDataTypeUnrecoverableError(error); |
196 return false; | 185 return false; |
197 } else { | 186 } else { |
198 syncer::WriteNode create_node(trans); | 187 syncer::WriteNode create_node(trans); |
199 syncer::WriteNode::InitUniqueByCreationResult result = | 188 syncer::WriteNode::InitUniqueByCreationResult result = |
200 create_node.InitUniqueByCreation(syncer::TYPED_URLS, | 189 create_node.InitUniqueByCreation(syncer::TYPED_URLS, tag); |
201 typed_url_root, tag); | |
202 if (result != syncer::WriteNode::INIT_SUCCESS) { | 190 if (result != syncer::WriteNode::INIT_SUCCESS) { |
203 | 191 |
204 syncer::SyncError error(FROM_HERE, | 192 syncer::SyncError error(FROM_HERE, |
205 syncer::SyncError::DATATYPE_ERROR, | 193 syncer::SyncError::DATATYPE_ERROR, |
206 "Failed to create sync node", | 194 "Failed to create sync node", |
207 syncer::TYPED_URLS); | 195 syncer::TYPED_URLS); |
208 error_handler()->OnSingleDataTypeUnrecoverableError(error); | 196 error_handler()->OnSingleDataTypeUnrecoverableError(error); |
209 return false; | 197 return false; |
210 } | 198 } |
211 | 199 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 } | 334 } |
347 | 335 |
348 void TypedUrlChangeProcessor::StopObserving() { | 336 void TypedUrlChangeProcessor::StopObserving() { |
349 DCHECK(backend_loop_ == base::MessageLoop::current()); | 337 DCHECK(backend_loop_ == base::MessageLoop::current()); |
350 DCHECK(history_backend_); | 338 DCHECK(history_backend_); |
351 DCHECK(profile_); | 339 DCHECK(profile_); |
352 history_backend_observer_.RemoveAll(); | 340 history_backend_observer_.RemoveAll(); |
353 } | 341 } |
354 | 342 |
355 } // namespace browser_sync | 343 } // namespace browser_sync |
OLD | NEW |