data_type_error_handler_impl.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/sync/model/data_type_error_handler_impl.h"
  5. #include "base/bind.h"
  6. #include "base/metrics/histogram_macros.h"
  7. namespace syncer {
  8. DataTypeErrorHandlerImpl::DataTypeErrorHandlerImpl(
  9. const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
  10. const base::RepeatingClosure& dump_stack,
  11. const ErrorCallback& sync_callback)
  12. : ui_thread_(ui_thread),
  13. dump_stack_(dump_stack),
  14. sync_callback_(sync_callback) {}
  15. DataTypeErrorHandlerImpl::~DataTypeErrorHandlerImpl() = default;
  16. void DataTypeErrorHandlerImpl::OnUnrecoverableError(const SyncError& error) {
  17. if (!dump_stack_.is_null())
  18. dump_stack_.Run();
  19. UMA_HISTOGRAM_ENUMERATION("Sync.DataTypeRunFailures2",
  20. ModelTypeHistogramValue(error.model_type()));
  21. ui_thread_->PostTask(error.location(), base::BindOnce(sync_callback_, error));
  22. }
  23. SyncError DataTypeErrorHandlerImpl::CreateAndUploadError(
  24. const base::Location& location,
  25. const std::string& message,
  26. ModelType type) {
  27. if (!dump_stack_.is_null())
  28. dump_stack_.Run();
  29. return SyncError(location, SyncError::DATATYPE_ERROR, message, type);
  30. }
  31. std::unique_ptr<DataTypeErrorHandler> DataTypeErrorHandlerImpl::Copy() const {
  32. return std::make_unique<DataTypeErrorHandlerImpl>(ui_thread_, dump_stack_,
  33. sync_callback_);
  34. }
  35. } // namespace syncer