OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SYNC_GLUE_CHANGE_PROCESSOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_CHANGE_PROCESSOR_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_CHANGE_PROCESSOR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_CHANGE_PROCESSOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "chrome/browser/sync/engine/syncapi.h" | 9 #include "chrome/browser/sync/engine/syncapi.h" |
10 #include "chrome/browser/sync/glue/sync_backend_host.h" | 10 #include "chrome/browser/sync/glue/sync_backend_host.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 // The changes found in ApplyChangesFromSyncModel may be too slow to be | 46 // The changes found in ApplyChangesFromSyncModel may be too slow to be |
47 // performed while holding a [Read/Write]Transaction lock or may interact | 47 // performed while holding a [Read/Write]Transaction lock or may interact |
48 // with another thread, which might itself be waiting on the transaction lock, | 48 // with another thread, which might itself be waiting on the transaction lock, |
49 // putting us at risk of deadlock. | 49 // putting us at risk of deadlock. |
50 // This function is called once the transactional lock is released and it is | 50 // This function is called once the transactional lock is released and it is |
51 // safe to perform inter-thread or slow I/O operations. Note that not all | 51 // safe to perform inter-thread or slow I/O operations. Note that not all |
52 // datatypes need this, so we provide an empty default version. | 52 // datatypes need this, so we provide an empty default version. |
53 virtual void CommitChangesFromSyncModel(); | 53 virtual void CommitChangesFromSyncModel(); |
54 | 54 |
| 55 // This ensures that startobserving gets called after stopobserving even |
| 56 // if there is an early return in the function. |
| 57 template <class T> |
| 58 class ScopedStopObserving { |
| 59 public: |
| 60 explicit ScopedStopObserving(T* processor) |
| 61 : processor_(processor) { |
| 62 processor_->StopObserving(); |
| 63 } |
| 64 ~ScopedStopObserving() { |
| 65 processor_->StartObserving(); |
| 66 } |
| 67 |
| 68 private: |
| 69 ScopedStopObserving() {} |
| 70 T* processor_; |
| 71 }; |
| 72 |
55 protected: | 73 protected: |
56 // These methods are invoked by Start() and Stop() to do | 74 // These methods are invoked by Start() and Stop() to do |
57 // implementation-specific work. | 75 // implementation-specific work. |
58 virtual void StartImpl(Profile* profile) = 0; | 76 virtual void StartImpl(Profile* profile) = 0; |
59 virtual void StopImpl() = 0; | 77 virtual void StopImpl() = 0; |
60 | 78 |
61 bool running() { return running_; } | 79 bool running() { return running_; } |
62 UnrecoverableErrorHandler* error_handler(); | 80 UnrecoverableErrorHandler* error_handler(); |
63 virtual sync_api::UserShare* share_handle(); | 81 virtual sync_api::UserShare* share_handle(); |
64 | 82 |
65 private: | 83 private: |
66 bool running_; // True if we have been told it is safe to process changes. | 84 bool running_; // True if we have been told it is safe to process changes. |
67 UnrecoverableErrorHandler* error_handler_; // Guaranteed to outlive us. | 85 UnrecoverableErrorHandler* error_handler_; // Guaranteed to outlive us. |
68 | 86 |
69 // The sync model we are processing changes from. Non-NULL when |running_| is | 87 // The sync model we are processing changes from. Non-NULL when |running_| is |
70 // true. | 88 // true. |
71 sync_api::UserShare* share_handle_; | 89 sync_api::UserShare* share_handle_; |
72 | 90 |
73 DISALLOW_COPY_AND_ASSIGN(ChangeProcessor); | 91 DISALLOW_COPY_AND_ASSIGN(ChangeProcessor); |
74 }; | 92 }; |
75 | 93 |
76 } // namespace browser_sync | 94 } // namespace browser_sync |
77 | 95 |
78 #endif // CHROME_BROWSER_SYNC_GLUE_CHANGE_PROCESSOR_H_ | 96 #endif // CHROME_BROWSER_SYNC_GLUE_CHANGE_PROCESSOR_H_ |
OLD | NEW |