Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: chrome/browser/sync/engine/model_changing_syncer_command.h

Issue 8637006: [Sync] Make syncer commands avoid posting tasks on threads with no work to do (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments, add tests Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // 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 session.GetEnabledGroups() or
55 // session.GetEnabledGroupsWithConflicts() and filtering that, or
56 // using GetGroupForModelType() (which handles top-level/unspecified
57 // nodes) to project from model types to groups.
58 virtual std::set<ModelSafeGroup> GetGroupsToChange(
59 const sessions::SyncSession& session) const = 0;
60
44 // Sometimes, a command has work to do that needs to touch global state 61 // 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 62 // belonging to multiple ModelSafeGroups, but in a way that is known to be
46 // safe. This will be called once, prior to ModelChangingExecuteImpl, 63 // safe. This will be called once, prior to ModelChangingExecuteImpl,
47 // *without* a ModelSafeGroup restriction in place on the SyncSession. 64 // *without* a ModelSafeGroup restriction in place on the SyncSession.
48 // Returns true on success, false on failure. 65 // Returns true on success, false on failure.
49 // TODO(tim): Remove this (bug 36594). 66 // TODO(tim): Remove this (bug 36594).
50 virtual bool ModelNeutralExecuteImpl(sessions::SyncSession* session); 67 virtual bool ModelNeutralExecuteImpl(sessions::SyncSession* session);
51 68
52 // Abstract method to be implemented by subclasses to handle logic that 69 // Abstract method to be implemented by subclasses to handle logic that
53 // operates on the model. This is invoked with a SyncSession ModelSafeGroup 70 // operates on the model. This is invoked with a SyncSession ModelSafeGroup
54 // restriction in place so that bits of state belonging to data types 71 // restriction in place so that bits of state belonging to data types
55 // running on an unsafe thread are siloed away. 72 // running on an unsafe thread are siloed away.
56 virtual void ModelChangingExecuteImpl(sessions::SyncSession* session) = 0; 73 virtual void ModelChangingExecuteImpl(sessions::SyncSession* session) = 0;
57 74
58 private: 75 private:
59 // ExecuteImpl is expected to be run by SyncerCommand to set work_session. 76 // ExecuteImpl is expected to be run by SyncerCommand to set work_session.
60 // StartChangingModel is called to start this command running. 77 // StartChangingModel is called to start this command running.
61 // Implementations will implement ModelChangingExecuteImpl and not 78 // Implementations will implement ModelChangingExecuteImpl and not
62 // worry about storing the session or setting it. They are given work_session. 79 // worry about storing the session or setting it. They are given work_session.
63 sessions::SyncSession* work_session_; 80 sessions::SyncSession* work_session_;
64 81
65 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommand); 82 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommand);
66 }; 83 };
67 84
68 } // namespace browser_sync 85 } // namespace browser_sync
69 86
70 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ 87 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698