| 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_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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "chrome/browser/sync/engine/model_safe_worker.h" | |
| 11 #include "chrome/browser/sync/engine/syncer_command.h" | 10 #include "chrome/browser/sync/engine/syncer_command.h" |
| 12 #include "chrome/browser/sync/util/unrecoverable_error_info.h" | 11 #include "chrome/browser/sync/util/unrecoverable_error_info.h" |
| 13 | 12 |
| 14 namespace browser_sync { | 13 namespace browser_sync { |
| 15 namespace sessions { | 14 namespace sessions { |
| 16 class SyncSession; | 15 class SyncSession; |
| 17 } | 16 } |
| 18 | 17 |
| 19 // An abstract SyncerCommand which dispatches its Execute step to the | 18 // An abstract SyncerCommand which dispatches its Execute step to the |
| 20 // model-safe worker thread. Classes derived from ModelChangingSyncerCommand | 19 // model-safe worker thread. Classes derived from ModelChangingSyncerCommand |
| (...skipping 14 matching lines...) Expand all Loading... |
| 35 virtual void ExecuteImpl(sessions::SyncSession* session) OVERRIDE; | 34 virtual void ExecuteImpl(sessions::SyncSession* session) OVERRIDE; |
| 36 | 35 |
| 37 // wrapper so implementations don't worry about storing work_session | 36 // wrapper so implementations don't worry about storing work_session |
| 38 UnrecoverableErrorInfo StartChangingModel() { | 37 UnrecoverableErrorInfo StartChangingModel() { |
| 39 // TODO(lipalani): |ModelChangingExecuteImpl| should return an | 38 // TODO(lipalani): |ModelChangingExecuteImpl| should return an |
| 40 // UnrecoverableErrorInfo struct. | 39 // UnrecoverableErrorInfo struct. |
| 41 ModelChangingExecuteImpl(work_session_); | 40 ModelChangingExecuteImpl(work_session_); |
| 42 return UnrecoverableErrorInfo(); | 41 return UnrecoverableErrorInfo(); |
| 43 } | 42 } |
| 44 | 43 |
| 45 std::set<ModelSafeGroup> GetGroupsToChangeForTest( | |
| 46 const sessions::SyncSession& session) const { | |
| 47 return GetGroupsToChange(session); | |
| 48 } | |
| 49 | |
| 50 protected: | |
| 51 // This should return the set of groups in |session| that need to be | |
| 52 // changed. The returned set should be a subset of | |
| 53 // session.GetEnabledGroups(). Subclasses can guarantee this either | |
| 54 // by calling one of the session.GetEnabledGroups*() functions and | |
| 55 // filtering that, or using GetGroupForModelType() (which handles | |
| 56 // top-level/unspecified nodes) to project from model types to | |
| 57 // groups. | |
| 58 virtual std::set<ModelSafeGroup> GetGroupsToChange( | |
| 59 const sessions::SyncSession& session) const = 0; | |
| 60 | |
| 61 // Sometimes, a command has work to do that needs to touch global state | 44 // Sometimes, a command has work to do that needs to touch global state |
| 62 // belonging to multiple ModelSafeGroups, but in a way that is known to be | 45 // belonging to multiple ModelSafeGroups, but in a way that is known to be |
| 63 // safe. This will be called once, prior to ModelChangingExecuteImpl, | 46 // safe. This will be called once, prior to ModelChangingExecuteImpl, |
| 64 // *without* a ModelSafeGroup restriction in place on the SyncSession. | 47 // *without* a ModelSafeGroup restriction in place on the SyncSession. |
| 65 // Returns true on success, false on failure. | 48 // Returns true on success, false on failure. |
| 66 // TODO(tim): Remove this (bug 36594). | 49 // TODO(tim): Remove this (bug 36594). |
| 67 virtual bool ModelNeutralExecuteImpl(sessions::SyncSession* session); | 50 virtual bool ModelNeutralExecuteImpl(sessions::SyncSession* session); |
| 68 | 51 |
| 69 // Abstract method to be implemented by subclasses to handle logic that | 52 // Abstract method to be implemented by subclasses to handle logic that |
| 70 // operates on the model. This is invoked with a SyncSession ModelSafeGroup | 53 // operates on the model. This is invoked with a SyncSession ModelSafeGroup |
| 71 // restriction in place so that bits of state belonging to data types | 54 // restriction in place so that bits of state belonging to data types |
| 72 // running on an unsafe thread are siloed away. | 55 // running on an unsafe thread are siloed away. |
| 73 virtual void ModelChangingExecuteImpl(sessions::SyncSession* session) = 0; | 56 virtual void ModelChangingExecuteImpl(sessions::SyncSession* session) = 0; |
| 74 | 57 |
| 75 private: | 58 private: |
| 76 // ExecuteImpl is expected to be run by SyncerCommand to set work_session. | 59 // ExecuteImpl is expected to be run by SyncerCommand to set work_session. |
| 77 // StartChangingModel is called to start this command running. | 60 // StartChangingModel is called to start this command running. |
| 78 // Implementations will implement ModelChangingExecuteImpl and not | 61 // Implementations will implement ModelChangingExecuteImpl and not |
| 79 // worry about storing the session or setting it. They are given work_session. | 62 // worry about storing the session or setting it. They are given work_session. |
| 80 sessions::SyncSession* work_session_; | 63 sessions::SyncSession* work_session_; |
| 81 | 64 |
| 82 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommand); | 65 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommand); |
| 83 }; | 66 }; |
| 84 | 67 |
| 85 } // namespace browser_sync | 68 } // namespace browser_sync |
| 86 | 69 |
| 87 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ | 70 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ |
| OLD | NEW |