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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 TypedUrlChangeProcessor::TypedUrlChangeProcessor( | 37 TypedUrlChangeProcessor::TypedUrlChangeProcessor( |
38 Profile* profile, | 38 Profile* profile, |
39 TypedUrlModelAssociator* model_associator, | 39 TypedUrlModelAssociator* model_associator, |
40 history::HistoryBackend* history_backend, | 40 history::HistoryBackend* history_backend, |
41 DataTypeErrorHandler* error_handler) | 41 DataTypeErrorHandler* error_handler) |
42 : ChangeProcessor(error_handler), | 42 : ChangeProcessor(error_handler), |
43 profile_(profile), | 43 profile_(profile), |
44 model_associator_(model_associator), | 44 model_associator_(model_associator), |
45 history_backend_(history_backend), | 45 history_backend_(history_backend), |
46 expected_loop_(MessageLoop::current()) { | 46 expected_loop_(base::MessageLoop::current()) { |
47 DCHECK(model_associator); | 47 DCHECK(model_associator); |
48 DCHECK(history_backend); | 48 DCHECK(history_backend); |
49 DCHECK(error_handler); | 49 DCHECK(error_handler); |
50 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 50 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
51 // When running in unit tests, there is already a NotificationService object. | 51 // When running in unit tests, there is already a NotificationService object. |
52 // Since only one can exist at a time per thread, check first. | 52 // Since only one can exist at a time per thread, check first. |
53 if (!content::NotificationService::current()) | 53 if (!content::NotificationService::current()) |
54 notification_service_.reset(content::NotificationService::Create()); | 54 notification_service_.reset(content::NotificationService::Create()); |
55 } | 55 } |
56 | 56 |
57 TypedUrlChangeProcessor::~TypedUrlChangeProcessor() { | 57 TypedUrlChangeProcessor::~TypedUrlChangeProcessor() { |
58 DCHECK(expected_loop_ == MessageLoop::current()); | 58 DCHECK(expected_loop_ == base::MessageLoop::current()); |
59 } | 59 } |
60 | 60 |
61 void TypedUrlChangeProcessor::Observe( | 61 void TypedUrlChangeProcessor::Observe( |
62 int type, | 62 int type, |
63 const content::NotificationSource& source, | 63 const content::NotificationSource& source, |
64 const content::NotificationDetails& details) { | 64 const content::NotificationDetails& details) { |
65 DCHECK(expected_loop_ == MessageLoop::current()); | 65 DCHECK(expected_loop_ == base::MessageLoop::current()); |
66 | 66 |
67 DVLOG(1) << "Observed typed_url change."; | 67 DVLOG(1) << "Observed typed_url change."; |
68 if (type == chrome::NOTIFICATION_HISTORY_URLS_MODIFIED) { | 68 if (type == chrome::NOTIFICATION_HISTORY_URLS_MODIFIED) { |
69 HandleURLsModified( | 69 HandleURLsModified( |
70 content::Details<history::URLsModifiedDetails>(details).ptr()); | 70 content::Details<history::URLsModifiedDetails>(details).ptr()); |
71 } else if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) { | 71 } else if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) { |
72 HandleURLsDeleted( | 72 HandleURLsDeleted( |
73 content::Details<history::URLsDeletedDetails>(details).ptr()); | 73 content::Details<history::URLsDeletedDetails>(details).ptr()); |
74 } else { | 74 } else { |
75 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED, type); | 75 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED, type); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 return (transition == content::PAGE_TRANSITION_TYPED && | 232 return (transition == content::PAGE_TRANSITION_TYPED && |
233 typed_count > 0 && | 233 typed_count > 0 && |
234 (typed_count < kTypedUrlVisitThrottleThreshold || | 234 (typed_count < kTypedUrlVisitThrottleThreshold || |
235 (typed_count % kTypedUrlVisitThrottleMultiple) == 0)); | 235 (typed_count % kTypedUrlVisitThrottleMultiple) == 0)); |
236 } | 236 } |
237 | 237 |
238 void TypedUrlChangeProcessor::ApplyChangesFromSyncModel( | 238 void TypedUrlChangeProcessor::ApplyChangesFromSyncModel( |
239 const syncer::BaseTransaction* trans, | 239 const syncer::BaseTransaction* trans, |
240 int64 model_version, | 240 int64 model_version, |
241 const syncer::ImmutableChangeRecordList& changes) { | 241 const syncer::ImmutableChangeRecordList& changes) { |
242 DCHECK(expected_loop_ == MessageLoop::current()); | 242 DCHECK(expected_loop_ == base::MessageLoop::current()); |
243 | 243 |
244 syncer::ReadNode typed_url_root(trans); | 244 syncer::ReadNode typed_url_root(trans); |
245 if (typed_url_root.InitByTagLookup(kTypedUrlTag) != | 245 if (typed_url_root.InitByTagLookup(kTypedUrlTag) != |
246 syncer::BaseNode::INIT_OK) { | 246 syncer::BaseNode::INIT_OK) { |
247 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 247 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
248 "TypedUrl root node lookup failed."); | 248 "TypedUrl root node lookup failed."); |
249 return; | 249 return; |
250 } | 250 } |
251 | 251 |
252 DCHECK(pending_new_urls_.empty() && pending_new_visits_.empty() && | 252 DCHECK(pending_new_urls_.empty() && pending_new_visits_.empty() && |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 continue; | 288 continue; |
289 } | 289 } |
290 | 290 |
291 model_associator_->UpdateFromSyncDB( | 291 model_associator_->UpdateFromSyncDB( |
292 filtered_url, &pending_new_visits_, &pending_deleted_visits_, | 292 filtered_url, &pending_new_visits_, &pending_deleted_visits_, |
293 &pending_updated_urls_, &pending_new_urls_); | 293 &pending_updated_urls_, &pending_new_urls_); |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 void TypedUrlChangeProcessor::CommitChangesFromSyncModel() { | 297 void TypedUrlChangeProcessor::CommitChangesFromSyncModel() { |
298 DCHECK(expected_loop_ == MessageLoop::current()); | 298 DCHECK(expected_loop_ == base::MessageLoop::current()); |
299 | 299 |
300 // Make sure we stop listening for changes while we're modifying the backend, | 300 // Make sure we stop listening for changes while we're modifying the backend, |
301 // so we don't try to re-apply these changes to the sync DB. | 301 // so we don't try to re-apply these changes to the sync DB. |
302 ScopedStopObserving<TypedUrlChangeProcessor> stop_observing(this); | 302 ScopedStopObserving<TypedUrlChangeProcessor> stop_observing(this); |
303 if (!pending_deleted_urls_.empty()) | 303 if (!pending_deleted_urls_.empty()) |
304 history_backend_->DeleteURLs(pending_deleted_urls_); | 304 history_backend_->DeleteURLs(pending_deleted_urls_); |
305 | 305 |
306 model_associator_->WriteToHistoryBackend(&pending_new_urls_, | 306 model_associator_->WriteToHistoryBackend(&pending_new_urls_, |
307 &pending_updated_urls_, | 307 &pending_updated_urls_, |
308 &pending_new_visits_, | 308 &pending_new_visits_, |
309 &pending_deleted_visits_); | 309 &pending_deleted_visits_); |
310 | 310 |
311 pending_new_urls_.clear(); | 311 pending_new_urls_.clear(); |
312 pending_updated_urls_.clear(); | 312 pending_updated_urls_.clear(); |
313 pending_new_visits_.clear(); | 313 pending_new_visits_.clear(); |
314 pending_deleted_visits_.clear(); | 314 pending_deleted_visits_.clear(); |
315 pending_deleted_urls_.clear(); | 315 pending_deleted_urls_.clear(); |
316 UMA_HISTOGRAM_PERCENTAGE("Sync.TypedUrlChangeProcessorErrors", | 316 UMA_HISTOGRAM_PERCENTAGE("Sync.TypedUrlChangeProcessorErrors", |
317 model_associator_->GetErrorPercentage()); | 317 model_associator_->GetErrorPercentage()); |
318 } | 318 } |
319 | 319 |
320 void TypedUrlChangeProcessor::StartImpl(Profile* profile) { | 320 void TypedUrlChangeProcessor::StartImpl(Profile* profile) { |
321 DCHECK(expected_loop_ == MessageLoop::current()); | 321 DCHECK(expected_loop_ == base::MessageLoop::current()); |
322 DCHECK_EQ(profile, profile_); | 322 DCHECK_EQ(profile, profile_); |
323 StartObserving(); | 323 StartObserving(); |
324 } | 324 } |
325 | 325 |
326 void TypedUrlChangeProcessor::StartObserving() { | 326 void TypedUrlChangeProcessor::StartObserving() { |
327 DCHECK(expected_loop_ == MessageLoop::current()); | 327 DCHECK(expected_loop_ == base::MessageLoop::current()); |
328 DCHECK(profile_); | 328 DCHECK(profile_); |
329 notification_registrar_.Add( | 329 notification_registrar_.Add( |
330 this, chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, | 330 this, chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, |
331 content::Source<Profile>(profile_)); | 331 content::Source<Profile>(profile_)); |
332 notification_registrar_.Add( | 332 notification_registrar_.Add( |
333 this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 333 this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
334 content::Source<Profile>(profile_)); | 334 content::Source<Profile>(profile_)); |
335 notification_registrar_.Add( | 335 notification_registrar_.Add( |
336 this, chrome::NOTIFICATION_HISTORY_URL_VISITED, | 336 this, chrome::NOTIFICATION_HISTORY_URL_VISITED, |
337 content::Source<Profile>(profile_)); | 337 content::Source<Profile>(profile_)); |
338 } | 338 } |
339 | 339 |
340 void TypedUrlChangeProcessor::StopObserving() { | 340 void TypedUrlChangeProcessor::StopObserving() { |
341 DCHECK(expected_loop_ == MessageLoop::current()); | 341 DCHECK(expected_loop_ == base::MessageLoop::current()); |
342 DCHECK(profile_); | 342 DCHECK(profile_); |
343 notification_registrar_.Remove( | 343 notification_registrar_.Remove( |
344 this, chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, | 344 this, chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, |
345 content::Source<Profile>(profile_)); | 345 content::Source<Profile>(profile_)); |
346 notification_registrar_.Remove( | 346 notification_registrar_.Remove( |
347 this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 347 this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
348 content::Source<Profile>(profile_)); | 348 content::Source<Profile>(profile_)); |
349 notification_registrar_.Remove( | 349 notification_registrar_.Remove( |
350 this, chrome::NOTIFICATION_HISTORY_URL_VISITED, | 350 this, chrome::NOTIFICATION_HISTORY_URL_VISITED, |
351 content::Source<Profile>(profile_)); | 351 content::Source<Profile>(profile_)); |
352 } | 352 } |
353 | 353 |
354 } // namespace browser_sync | 354 } // namespace browser_sync |
OLD | NEW |