OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ | 5 #ifndef CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ |
6 #define CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ | 6 #define CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "chrome/browser/sync/engine/syncer_command.h" | 9 #include "chrome/browser/sync/engine/syncer_command.h" |
| 10 #include "chrome/browser/sync/util/unrecoverable_error_info.h" |
10 | 11 |
11 namespace browser_sync { | 12 namespace browser_sync { |
12 namespace sessions { | 13 namespace sessions { |
13 class SyncSession; | 14 class SyncSession; |
14 } | 15 } |
15 | 16 |
16 // An abstract SyncerCommand which dispatches its Execute step to the | 17 // An abstract SyncerCommand which dispatches its Execute step to the |
17 // model-safe worker thread. Classes derived from ModelChangingSyncerCommand | 18 // model-safe worker thread. Classes derived from ModelChangingSyncerCommand |
18 // instead of SyncerCommand must implement ModelChangingExecuteImpl instead of | 19 // instead of SyncerCommand must implement ModelChangingExecuteImpl instead of |
19 // ExecuteImpl, but otherwise, the contract is the same. | 20 // ExecuteImpl, but otherwise, the contract is the same. |
20 // | 21 // |
21 // A command should derive from ModelChangingSyncerCommand instead of | 22 // A command should derive from ModelChangingSyncerCommand instead of |
22 // SyncerCommand whenever the operation might change any client-visible | 23 // SyncerCommand whenever the operation might change any client-visible |
23 // fields on any syncable::Entry. If the operation involves creating a | 24 // fields on any syncable::Entry. If the operation involves creating a |
24 // WriteTransaction, this is a sign that ModelChangingSyncerCommand is likely | 25 // WriteTransaction, this is a sign that ModelChangingSyncerCommand is likely |
25 // necessary. | 26 // necessary. |
26 class ModelChangingSyncerCommand : public SyncerCommand { | 27 class ModelChangingSyncerCommand : public SyncerCommand { |
27 public: | 28 public: |
28 ModelChangingSyncerCommand() : work_session_(NULL) { } | 29 ModelChangingSyncerCommand() : work_session_(NULL) { } |
29 virtual ~ModelChangingSyncerCommand() { } | 30 virtual ~ModelChangingSyncerCommand() { } |
30 | 31 |
31 // SyncerCommand implementation. Sets work_session to session. | 32 // SyncerCommand implementation. Sets work_session to session. |
32 virtual void ExecuteImpl(sessions::SyncSession* session); | 33 virtual void ExecuteImpl(sessions::SyncSession* session); |
33 | 34 |
34 // wrapper so implementations don't worry about storing work_session | 35 // wrapper so implementations don't worry about storing work_session |
35 void StartChangingModel() { | 36 UnrecoverableErrorInfo StartChangingModel() { |
| 37 // TODO(lipalani): |ModelChangingExecuteImpl| should return an |
| 38 // UnrecoverableErrorInfo struct. |
36 ModelChangingExecuteImpl(work_session_); | 39 ModelChangingExecuteImpl(work_session_); |
| 40 return UnrecoverableErrorInfo(); |
37 } | 41 } |
38 | 42 |
39 // Sometimes, a command has work to do that needs to touch global state | 43 // Sometimes, a command has work to do that needs to touch global state |
40 // belonging to multiple ModelSafeGroups, but in a way that is known to be | 44 // belonging to multiple ModelSafeGroups, but in a way that is known to be |
41 // safe. This will be called once, prior to ModelChangingExecuteImpl, | 45 // safe. This will be called once, prior to ModelChangingExecuteImpl, |
42 // *without* a ModelSafeGroup restriction in place on the SyncSession. | 46 // *without* a ModelSafeGroup restriction in place on the SyncSession. |
43 // Returns true on success, false on failure. | 47 // Returns true on success, false on failure. |
44 // TODO(tim): Remove this (bug 36594). | 48 // TODO(tim): Remove this (bug 36594). |
45 virtual bool ModelNeutralExecuteImpl(sessions::SyncSession* session); | 49 virtual bool ModelNeutralExecuteImpl(sessions::SyncSession* session); |
46 | 50 |
47 // Abstract method to be implemented by subclasses to handle logic that | 51 // Abstract method to be implemented by subclasses to handle logic that |
48 // operates on the model. This is invoked with a SyncSession ModelSafeGroup | 52 // operates on the model. This is invoked with a SyncSession ModelSafeGroup |
49 // restriction in place so that bits of state belonging to data types | 53 // restriction in place so that bits of state belonging to data types |
50 // running on an unsafe thread are siloed away. | 54 // running on an unsafe thread are siloed away. |
51 virtual void ModelChangingExecuteImpl(sessions::SyncSession* session) = 0; | 55 virtual void ModelChangingExecuteImpl(sessions::SyncSession* session) = 0; |
52 | 56 |
53 private: | 57 private: |
54 // ExecuteImpl is expected to be run by SyncerCommand to set work_session. | 58 // ExecuteImpl is expected to be run by SyncerCommand to set work_session. |
55 // StartChangingModel is called to start this command running. | 59 // StartChangingModel is called to start this command running. |
56 // Implementations will implement ModelChangingExecuteImpl and not | 60 // Implementations will implement ModelChangingExecuteImpl and not |
57 // worry about storing the session or setting it. They are given work_session. | 61 // worry about storing the session or setting it. They are given work_session. |
58 sessions::SyncSession* work_session_; | 62 sessions::SyncSession* work_session_; |
59 | 63 |
60 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommand); | 64 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommand); |
61 }; | 65 }; |
62 | 66 |
63 } // namespace browser_sync | 67 } // namespace browser_sync |
64 | 68 |
65 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ | 69 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ |
OLD | NEW |