Makes the view manager client lib remove children when embedding
[chromium-blink-merge.git] / sync / syncable / syncable_base_transaction.cc
blobc145c1f339c22b582e2a3d3a29f2b1fbf6de18a3
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.
5 #include "sync/syncable/syncable_base_transaction.h"
7 #include "base/trace_event/trace_event.h"
8 #include "sync/syncable/directory.h"
10 namespace syncer {
11 namespace syncable {
13 // static
14 Id BaseTransaction::root_id() {
15 return Id::GetRoot();
18 Directory* BaseTransaction::directory() const {
19 return directory_;
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());
27 directory_->kernel()->transaction_mutex.Acquire();
30 void BaseTransaction::Unlock() {
31 directory_->kernel()->transaction_mutex.Release();
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;
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.
45 directory()->ReportUnrecoverableError();
48 bool BaseTransaction::unrecoverable_error_set() const {
49 return unrecoverable_error_set_;
52 void BaseTransaction::HandleUnrecoverableErrorIfSet() {
53 if (unrecoverable_error_set_) {
54 directory()->OnUnrecoverableError(this,
55 unrecoverable_error_location_,
56 unrecoverable_error_msg_);
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());
74 BaseTransaction::~BaseTransaction() {
75 TRACE_EVENT_END0("sync", name_);
78 } // namespace syncable
79 } // namespace syncer