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 CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ | |
6 #define CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ | |
7 #pragma once | |
8 | |
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" | |
12 | |
13 namespace browser_sync { | |
14 namespace sessions { | |
15 class SyncSession; | |
16 } | |
17 | |
18 // An abstract SyncerCommand which dispatches its Execute step to the | |
19 // model-safe worker thread. Classes derived from ModelChangingSyncerCommand | |
20 // instead of SyncerCommand must implement ModelChangingExecuteImpl instead of | |
21 // ExecuteImpl, but otherwise, the contract is the same. | |
22 // | |
23 // A command should derive from ModelChangingSyncerCommand instead of | |
24 // SyncerCommand whenever the operation might change any client-visible | |
25 // fields on any syncable::Entry. If the operation involves creating a | |
26 // WriteTransaction, this is a sign that ModelChangingSyncerCommand is likely | |
27 // necessary. | |
28 class ModelChangingSyncerCommand : public SyncerCommand { | |
29 public: | |
30 ModelChangingSyncerCommand() : work_session_(NULL) { } | |
31 virtual ~ModelChangingSyncerCommand() { } | |
32 | |
33 // SyncerCommand implementation. Sets work_session to session. | |
34 virtual browser_sync::SyncerError ExecuteImpl( | |
35 sessions::SyncSession* session) OVERRIDE; | |
36 | |
37 // Wrapper so implementations don't worry about storing work_session. | |
38 SyncerError StartChangingModel() { | |
39 return ModelChangingExecuteImpl(work_session_); | |
40 } | |
41 | |
42 std::set<ModelSafeGroup> GetGroupsToChangeForTest( | |
43 const sessions::SyncSession& session) const { | |
44 return GetGroupsToChange(session); | |
45 } | |
46 | |
47 protected: | |
48 // This should return the set of groups in |session| that need to be | |
49 // changed. The returned set should be a subset of | |
50 // session.GetEnabledGroups(). Subclasses can guarantee this either | |
51 // by calling one of the session.GetEnabledGroups*() functions and | |
52 // filtering that, or using GetGroupForModelType() (which handles | |
53 // top-level/unspecified nodes) to project from model types to | |
54 // groups. | |
55 virtual std::set<ModelSafeGroup> GetGroupsToChange( | |
56 const sessions::SyncSession& session) const = 0; | |
57 | |
58 // Sometimes, a command has work to do that needs to touch global state | |
59 // belonging to multiple ModelSafeGroups, but in a way that is known to be | |
60 // safe. This will be called once, prior to ModelChangingExecuteImpl, | |
61 // *without* a ModelSafeGroup restriction in place on the SyncSession. | |
62 // Returns true on success, false on failure. | |
63 // TODO(tim): Remove this (bug 36594). | |
64 virtual SyncerError ModelNeutralExecuteImpl(sessions::SyncSession* session); | |
65 | |
66 // Abstract method to be implemented by subclasses to handle logic that | |
67 // operates on the model. This is invoked with a SyncSession ModelSafeGroup | |
68 // restriction in place so that bits of state belonging to data types | |
69 // running on an unsafe thread are siloed away. | |
70 virtual SyncerError ModelChangingExecuteImpl( | |
71 sessions::SyncSession* session) = 0; | |
72 | |
73 private: | |
74 // ExecuteImpl is expected to be run by SyncerCommand to set work_session. | |
75 // StartChangingModel is called to start this command running. | |
76 // Implementations will implement ModelChangingExecuteImpl and not | |
77 // worry about storing the session or setting it. They are given work_session. | |
78 sessions::SyncSession* work_session_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommand); | |
81 }; | |
82 | |
83 } // namespace browser_sync | |
84 | |
85 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ | |
OLD | NEW |