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