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 #ifndef SYNC_SYNCABLE_SYNCABLE_BASE_TRANSACTION_H_ | |
6 #define SYNC_SYNCABLE_SYNCABLE_BASE_TRANSACTION_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/location.h" | |
11 #include "base/macros.h" | |
12 #include "sync/base/sync_export.h" | |
13 #include "sync/syncable/syncable_id.h" | |
14 | |
15 namespace syncer { | |
16 namespace syncable { | |
17 | |
18 class Directory; | |
19 | |
20 // A WriteTransaction has a writer tag describing which body of code is doing | |
21 // the write. This is defined up here since WriteTransactionInfo also contains | |
22 // one. | |
23 enum WriterTag { | |
24 INVALID, | |
25 SYNCER, | |
26 AUTHWATCHER, | |
27 UNITTEST, | |
28 VACUUM_AFTER_SAVE, | |
29 HANDLE_SAVE_FAILURE, | |
30 PURGE_ENTRIES, | |
31 SYNCAPI, | |
32 }; | |
33 | |
34 // Make sure to update this if you update WriterTag. | |
35 std::string WriterTagToString(WriterTag writer_tag); | |
36 | |
37 class SYNC_EXPORT BaseTransaction { | |
38 public: | |
39 static Id root_id(); | |
40 | |
41 Directory* directory() const; | |
42 | |
43 virtual ~BaseTransaction(); | |
44 | |
45 // This should be called when a database corruption is detected and there is | |
46 // no way for us to recover short of wiping the database clean. When this is | |
47 // called we set a bool in the transaction. The caller has to unwind the | |
48 // stack. When the destructor for the transaction is called it acts upon the | |
49 // bool and calls the Directory to handle the unrecoverable error. | |
50 void OnUnrecoverableError(const tracked_objects::Location& location, | |
51 const std::string& message); | |
52 | |
53 bool unrecoverable_error_set() const; | |
54 | |
55 protected: | |
56 BaseTransaction(const tracked_objects::Location& from_here, | |
57 const char* name, | |
58 WriterTag writer, | |
59 Directory* directory); | |
60 | |
61 void Lock(); | |
62 void Unlock(); | |
63 | |
64 // This should be called before unlocking because it calls the Direcotry's | |
65 // OnUnrecoverableError method which is not protected by locks and could | |
66 // be called from any thread. Holding the transaction lock ensures only one | |
67 // thread could call the method at a time. | |
68 void HandleUnrecoverableErrorIfSet(); | |
69 | |
70 const tracked_objects::Location from_here_; | |
71 const char* const name_; | |
72 WriterTag writer_; | |
73 Directory* const directory_; | |
74 | |
75 // Error information. | |
76 bool unrecoverable_error_set_; | |
77 tracked_objects::Location unrecoverable_error_location_; | |
78 std::string unrecoverable_error_msg_; | |
79 | |
80 private: | |
81 friend class Entry; | |
82 DISALLOW_COPY_AND_ASSIGN(BaseTransaction); | |
83 }; | |
84 | |
85 } // namespace syncable | |
86 } // namespace syncer | |
87 | |
88 #endif // SYNC_SYNCABLE_SYNCABLE_BASE_TRANSACTION_H_ | |
OLD | NEW |