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
{
38 Directory
* directory() const;
40 virtual ~BaseTransaction();
42 // This should be called when a database corruption is detected and there is
43 // no way for us to recover short of wiping the database clean. When this is
44 // called we set a bool in the transaction. The caller has to unwind the
45 // stack. When the destructor for the transaction is called it acts upon the
46 // bool and calls the Directory to handle the unrecoverable error.
47 void OnUnrecoverableError(const tracked_objects::Location
& location
,
48 const std::string
& message
);
50 bool unrecoverable_error_set() const;
53 BaseTransaction(const tracked_objects::Location
& from_here
,
56 Directory
* directory
);
61 // This should be called before unlocking because it calls the Direcotry's
62 // OnUnrecoverableError method which is not protected by locks and could
63 // be called from any thread. Holding the transaction lock ensures only one
64 // thread could call the method at a time.
65 void HandleUnrecoverableErrorIfSet();
67 const tracked_objects::Location from_here_
;
68 const char* const name_
;
70 Directory
* const directory_
;
73 bool unrecoverable_error_set_
;
74 tracked_objects::Location unrecoverable_error_location_
;
75 std::string unrecoverable_error_msg_
;
79 DISALLOW_COPY_AND_ASSIGN(BaseTransaction
);
82 } // namespace syncable
85 #endif // SYNC_SYNCABLE_SYNCABLE_BASE_TRANSACTION_H_