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 <set> | |
10 | |
9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "chrome/browser/sync/engine/model_safe_worker.h" | |
10 #include "chrome/browser/sync/engine/syncer_command.h" | 13 #include "chrome/browser/sync/engine/syncer_command.h" |
11 #include "chrome/browser/sync/util/unrecoverable_error_info.h" | 14 #include "chrome/browser/sync/util/unrecoverable_error_info.h" |
12 | 15 |
13 namespace browser_sync { | 16 namespace browser_sync { |
14 namespace sessions { | 17 namespace sessions { |
15 class SyncSession; | 18 class SyncSession; |
16 } | 19 } |
17 | 20 |
18 // An abstract SyncerCommand which dispatches its Execute step to the | 21 // An abstract SyncerCommand which dispatches its Execute step to the |
19 // model-safe worker thread. Classes derived from ModelChangingSyncerCommand | 22 // model-safe worker thread. Classes derived from ModelChangingSyncerCommand |
20 // instead of SyncerCommand must implement ModelChangingExecuteImpl instead of | 23 // instead of SyncerCommand must implement ModelChangingExecuteImpl instead of |
21 // ExecuteImpl, but otherwise, the contract is the same. | 24 // ExecuteImpl, but otherwise, the contract is the same. |
22 // | 25 // |
23 // A command should derive from ModelChangingSyncerCommand instead of | 26 // A command should derive from ModelChangingSyncerCommand instead of |
24 // SyncerCommand whenever the operation might change any client-visible | 27 // SyncerCommand whenever the operation might change any client-visible |
25 // fields on any syncable::Entry. If the operation involves creating a | 28 // fields on any syncable::Entry. If the operation involves creating a |
26 // WriteTransaction, this is a sign that ModelChangingSyncerCommand is likely | 29 // WriteTransaction, this is a sign that ModelChangingSyncerCommand is likely |
27 // necessary. | 30 // necessary. |
28 class ModelChangingSyncerCommand : public SyncerCommand { | 31 class ModelChangingSyncerCommand : public SyncerCommand { |
29 public: | 32 public: |
30 ModelChangingSyncerCommand() : work_session_(NULL) { } | 33 ModelChangingSyncerCommand() : work_session_(NULL) { } |
31 virtual ~ModelChangingSyncerCommand() { } | 34 virtual ~ModelChangingSyncerCommand() { } |
32 | 35 |
33 // SyncerCommand implementation. Sets work_session to session. | 36 // SyncerCommand implementation. Sets work_session to session. |
34 virtual void ExecuteImpl(sessions::SyncSession* session) OVERRIDE; | 37 virtual void ExecuteImpl(sessions::SyncSession* session) OVERRIDE; |
35 | 38 |
36 // wrapper so implementations don't worry about storing work_session | 39 // wrapper so implementations don't worry about storing work_session |
37 UnrecoverableErrorInfo StartChangingModel() { | 40 UnrecoverableErrorInfo StartChangingModel() { |
38 // TODO(lipalani): |ModelChangingExecuteImpl| should return an | 41 // TODO(lipalani): |ModelChangingExecuteImpl| should return an |
tim (not reviewing)
2011/11/22 18:40:05
nit - remove this
akalin
2011/11/23 03:25:18
Eh, why? Doesn't it still hold?
tim (not reviewing)
2011/11/29 00:01:59
My bad. Nevermind.
| |
39 // UnrecoverableErrorInfo struct. | 42 // UnrecoverableErrorInfo struct. |
40 ModelChangingExecuteImpl(work_session_); | 43 ModelChangingExecuteImpl(work_session_); |
41 return UnrecoverableErrorInfo(); | 44 return UnrecoverableErrorInfo(); |
42 } | 45 } |
43 | 46 |
47 std::set<ModelSafeGroup> GetGroupsToChangeForTest( | |
48 const sessions::SyncSession& session) const { | |
49 return GetGroupsToChange(session); | |
50 } | |
51 | |
52 protected: | |
53 // This should return the set of groups in |session| that need to be | |
54 // changed. The returned set should be a subset of | |
55 // GetActiveGroups(). Subclasses can guarantee this either by | |
56 // calling GetActiveGroups() or GetActiveGroupsWithConflicts() and | |
57 // filtering that, or using GetGroupForModelType() (which handles | |
58 // top-level/unspecified nodes) to project from model types to | |
59 // groups. | |
60 virtual std::set<ModelSafeGroup> GetGroupsToChange( | |
61 const sessions::SyncSession& session) const = 0; | |
62 | |
44 // Sometimes, a command has work to do that needs to touch global state | 63 // Sometimes, a command has work to do that needs to touch global state |
45 // belonging to multiple ModelSafeGroups, but in a way that is known to be | 64 // belonging to multiple ModelSafeGroups, but in a way that is known to be |
46 // safe. This will be called once, prior to ModelChangingExecuteImpl, | 65 // safe. This will be called once, prior to ModelChangingExecuteImpl, |
47 // *without* a ModelSafeGroup restriction in place on the SyncSession. | 66 // *without* a ModelSafeGroup restriction in place on the SyncSession. |
48 // Returns true on success, false on failure. | 67 // Returns true on success, false on failure. |
49 // TODO(tim): Remove this (bug 36594). | 68 // TODO(tim): Remove this (bug 36594). |
50 virtual bool ModelNeutralExecuteImpl(sessions::SyncSession* session); | 69 virtual bool ModelNeutralExecuteImpl(sessions::SyncSession* session); |
51 | 70 |
52 // Abstract method to be implemented by subclasses to handle logic that | 71 // Abstract method to be implemented by subclasses to handle logic that |
53 // operates on the model. This is invoked with a SyncSession ModelSafeGroup | 72 // operates on the model. This is invoked with a SyncSession ModelSafeGroup |
54 // restriction in place so that bits of state belonging to data types | 73 // restriction in place so that bits of state belonging to data types |
55 // running on an unsafe thread are siloed away. | 74 // running on an unsafe thread are siloed away. |
56 virtual void ModelChangingExecuteImpl(sessions::SyncSession* session) = 0; | 75 virtual void ModelChangingExecuteImpl(sessions::SyncSession* session) = 0; |
57 | 76 |
77 // Returns the set of groups that have active (i.e., enabled) types. | |
tim (not reviewing)
2011/11/22 18:40:05
Can we avoid introducing a new adjective if we can
akalin
2011/11/23 03:25:18
Done.
| |
78 // Useful for implementing GetGroupsToChange(). | |
79 static std::set<ModelSafeGroup> GetActiveGroups( | |
80 const sessions::SyncSession& session); | |
81 | |
82 // Returns the set of active groups that have conflicts. Useful for | |
83 // implementing GetGroupsToChange(). | |
84 static std::set<ModelSafeGroup> GetActiveGroupsWithConflicts( | |
85 const sessions::SyncSession& session); | |
86 | |
58 private: | 87 private: |
59 // ExecuteImpl is expected to be run by SyncerCommand to set work_session. | 88 // ExecuteImpl is expected to be run by SyncerCommand to set work_session. |
60 // StartChangingModel is called to start this command running. | 89 // StartChangingModel is called to start this command running. |
61 // Implementations will implement ModelChangingExecuteImpl and not | 90 // Implementations will implement ModelChangingExecuteImpl and not |
62 // worry about storing the session or setting it. They are given work_session. | 91 // worry about storing the session or setting it. They are given work_session. |
63 sessions::SyncSession* work_session_; | 92 sessions::SyncSession* work_session_; |
64 | 93 |
65 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommand); | 94 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommand); |
66 }; | 95 }; |
67 | 96 |
68 } // namespace browser_sync | 97 } // namespace browser_sync |
69 | 98 |
70 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ | 99 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ |
OLD | NEW |