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