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