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 #ifndef SYNC_SYNCABLE_SYNCABLE_BASE_TRANSACTION_H_
6 #define SYNC_SYNCABLE_SYNCABLE_BASE_TRANSACTION_H_
8 #include "base/location.h"
9 #include "sync/base/sync_export.h"
10 #include "sync/syncable/syncable_id.h"
17 // A WriteTransaction has a writer tag describing which body of code is doing
18 // the write. This is defined up here since WriteTransactionInfo also contains
31 // Make sure to update this if you update WriterTag.
32 std::string
WriterTagToString(WriterTag writer_tag
);
34 class SYNC_EXPORT BaseTransaction
{
36 Directory
* directory() const;
39 virtual ~BaseTransaction();
41 // This should be called when a database corruption is detected and there is
42 // no way for us to recover short of wiping the database clean. When this is
43 // called we set a bool in the transaction. The caller has to unwind the
44 // stack. When the destructor for the transaction is called it acts upon the
45 // bool and calls the Directory to handle the unrecoverable error.
46 void OnUnrecoverableError(const tracked_objects::Location
& location
,
47 const std::string
& message
);
49 bool unrecoverable_error_set() const;
52 BaseTransaction(const tracked_objects::Location
& from_here
,
55 Directory
* directory
);
60 // This should be called before unlocking because it calls the Direcotry's
61 // OnUnrecoverableError method which is not protected by locks and could
62 // be called from any thread. Holding the transaction lock ensures only one
63 // thread could call the method at a time.
64 void HandleUnrecoverableErrorIfSet();
66 const tracked_objects::Location from_here_
;
67 const char* const name_
;
69 Directory
* const directory_
;
72 bool unrecoverable_error_set_
;
73 tracked_objects::Location unrecoverable_error_location_
;
74 std::string unrecoverable_error_msg_
;
78 DISALLOW_COPY_AND_ASSIGN(BaseTransaction
);
81 } // namespace syncable
84 #endif // SYNC_SYNCABLE_SYNCABLE_BASE_TRANSACTION_H_