Home | History | Annotate | Download | only in syncable
      1 // Copyright 2012 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 
      5 #include "sync/syncable/syncable_base_transaction.h"
      6 
      7 #include "base/debug/trace_event.h"
      8 #include "sync/syncable/directory.h"
      9 
     10 namespace syncer {
     11 namespace syncable {
     12 
     13 Directory* BaseTransaction::directory() const {
     14   return directory_;
     15 }
     16 
     17 Id BaseTransaction::root_id() const {
     18   return Id();
     19 }
     20 
     21 void BaseTransaction::Lock() {
     22   TRACE_EVENT2("sync_lock_contention", "AcquireLock",
     23                "src_file", from_here_.file_name(),
     24                "src_func", from_here_.function_name());
     25 
     26   directory_->kernel_->transaction_mutex.Acquire();
     27 }
     28 
     29 void BaseTransaction::Unlock() {
     30   directory_->kernel_->transaction_mutex.Release();
     31 }
     32 
     33 void BaseTransaction::OnUnrecoverableError(
     34     const tracked_objects::Location& location,
     35     const std::string& message) {
     36   unrecoverable_error_set_ = true;
     37   unrecoverable_error_location_ = location;
     38   unrecoverable_error_msg_ = message;
     39 
     40   // Note: We dont call the Directory's OnUnrecoverableError method right
     41   // away. Instead we wait to unwind the stack and in the destructor of the
     42   // transaction we would call the OnUnrecoverableError method.
     43 
     44   directory()->ReportUnrecoverableError();
     45 }
     46 
     47 bool BaseTransaction::unrecoverable_error_set() const {
     48   return unrecoverable_error_set_;
     49 }
     50 
     51 void BaseTransaction::HandleUnrecoverableErrorIfSet() {
     52   if (unrecoverable_error_set_) {
     53     directory()->OnUnrecoverableError(this,
     54         unrecoverable_error_location_,
     55         unrecoverable_error_msg_);
     56   }
     57 }
     58 
     59 BaseTransaction::BaseTransaction(const tracked_objects::Location& from_here,
     60                                  const char* name,
     61                                  WriterTag writer,
     62                                  Directory* directory)
     63     : from_here_(from_here), name_(name), writer_(writer),
     64       directory_(directory), unrecoverable_error_set_(false) {
     65   // TODO(lipalani): Don't issue a good transaction if the directory has
     66   // unrecoverable error set. And the callers have to check trans.good before
     67   // proceeding.
     68   TRACE_EVENT_BEGIN2("sync", name_,
     69                      "src_file", from_here_.file_name(),
     70                      "src_func", from_here_.function_name());
     71 }
     72 
     73 BaseTransaction::~BaseTransaction() {
     74   TRACE_EVENT_END0("sync", name_);
     75 }
     76 
     77 }  // namespace syncable
     78 }  // namespace syncer
     79