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