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

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

Issue 9036003: Avoid useless SYNC_CYCLE_CONTINUATION sync cycle (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/model_safe_worker.h"
11 #include "chrome/browser/sync/engine/syncer_command.h" 11 #include "chrome/browser/sync/engine/syncer_command.h"
12 #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
21 // instead of SyncerCommand must implement ModelChangingExecuteImpl instead of 20 // instead of SyncerCommand must implement ModelChangingExecuteImpl instead of
22 // ExecuteImpl, but otherwise, the contract is the same. 21 // ExecuteImpl, but otherwise, the contract is the same.
23 // 22 //
24 // A command should derive from ModelChangingSyncerCommand instead of 23 // A command should derive from ModelChangingSyncerCommand instead of
25 // SyncerCommand whenever the operation might change any client-visible 24 // SyncerCommand whenever the operation might change any client-visible
26 // fields on any syncable::Entry. If the operation involves creating a 25 // fields on any syncable::Entry. If the operation involves creating a
27 // WriteTransaction, this is a sign that ModelChangingSyncerCommand is likely 26 // WriteTransaction, this is a sign that ModelChangingSyncerCommand is likely
28 // necessary. 27 // necessary.
29 class ModelChangingSyncerCommand : public SyncerCommand { 28 class ModelChangingSyncerCommand : public SyncerCommand {
30 public: 29 public:
31 ModelChangingSyncerCommand() : work_session_(NULL) { } 30 ModelChangingSyncerCommand() : work_session_(NULL) { }
32 virtual ~ModelChangingSyncerCommand() { } 31 virtual ~ModelChangingSyncerCommand() { }
33 32
34 // SyncerCommand implementation. Sets work_session to session. 33 // SyncerCommand implementation. Sets work_session to session.
35 virtual void ExecuteImpl(sessions::SyncSession* session) OVERRIDE; 34 virtual browser_sync::SyncerError ExecuteImpl(
35 sessions::SyncSession* session) OVERRIDE;
36 36
37 // wrapper so implementations don't worry about storing work_session 37 // wrapper so implementations don't worry about storing work_session
38 UnrecoverableErrorInfo StartChangingModel() { 38 SyncerError StartChangingModel() {
39 // TODO(lipalani): |ModelChangingExecuteImpl| should return an 39 return ModelChangingExecuteImpl(work_session_);
40 // UnrecoverableErrorInfo struct.
41 ModelChangingExecuteImpl(work_session_);
42 return UnrecoverableErrorInfo();
43 } 40 }
44 41
45 std::set<ModelSafeGroup> GetGroupsToChangeForTest( 42 std::set<ModelSafeGroup> GetGroupsToChangeForTest(
46 const sessions::SyncSession& session) const { 43 const sessions::SyncSession& session) const {
47 return GetGroupsToChange(session); 44 return GetGroupsToChange(session);
48 } 45 }
49 46
50 protected: 47 protected:
51 // This should return the set of groups in |session| that need to be 48 // This should return the set of groups in |session| that need to be
52 // changed. The returned set should be a subset of 49 // changed. The returned set should be a subset of
53 // session.GetEnabledGroups(). Subclasses can guarantee this either 50 // session.GetEnabledGroups(). Subclasses can guarantee this either
54 // by calling one of the session.GetEnabledGroups*() functions and 51 // by calling one of the session.GetEnabledGroups*() functions and
55 // filtering that, or using GetGroupForModelType() (which handles 52 // filtering that, or using GetGroupForModelType() (which handles
56 // top-level/unspecified nodes) to project from model types to 53 // top-level/unspecified nodes) to project from model types to
57 // groups. 54 // groups.
58 virtual std::set<ModelSafeGroup> GetGroupsToChange( 55 virtual std::set<ModelSafeGroup> GetGroupsToChange(
59 const sessions::SyncSession& session) const = 0; 56 const sessions::SyncSession& session) const = 0;
60 57
61 // Sometimes, a command has work to do that needs to touch global state 58 // 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 59 // belonging to multiple ModelSafeGroups, but in a way that is known to be
63 // safe. This will be called once, prior to ModelChangingExecuteImpl, 60 // safe. This will be called once, prior to ModelChangingExecuteImpl,
64 // *without* a ModelSafeGroup restriction in place on the SyncSession. 61 // *without* a ModelSafeGroup restriction in place on the SyncSession.
65 // Returns true on success, false on failure. 62 // Returns true on success, false on failure.
66 // TODO(tim): Remove this (bug 36594). 63 // TODO(tim): Remove this (bug 36594).
67 virtual bool ModelNeutralExecuteImpl(sessions::SyncSession* session); 64 virtual SyncerError ModelNeutralExecuteImpl(sessions::SyncSession* session);
68 65
69 // Abstract method to be implemented by subclasses to handle logic that 66 // Abstract method to be implemented by subclasses to handle logic that
70 // operates on the model. This is invoked with a SyncSession ModelSafeGroup 67 // operates on the model. This is invoked with a SyncSession ModelSafeGroup
71 // restriction in place so that bits of state belonging to data types 68 // restriction in place so that bits of state belonging to data types
72 // running on an unsafe thread are siloed away. 69 // running on an unsafe thread are siloed away.
73 virtual void ModelChangingExecuteImpl(sessions::SyncSession* session) = 0; 70 virtual SyncerError ModelChangingExecuteImpl(
71 sessions::SyncSession* session) = 0;
74 72
75 private: 73 private:
76 // ExecuteImpl is expected to be run by SyncerCommand to set work_session. 74 // ExecuteImpl is expected to be run by SyncerCommand to set work_session.
77 // StartChangingModel is called to start this command running. 75 // StartChangingModel is called to start this command running.
78 // Implementations will implement ModelChangingExecuteImpl and not 76 // Implementations will implement ModelChangingExecuteImpl and not
79 // worry about storing the session or setting it. They are given work_session. 77 // worry about storing the session or setting it. They are given work_session.
80 sessions::SyncSession* work_session_; 78 sessions::SyncSession* work_session_;
81 79
82 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommand); 80 DISALLOW_COPY_AND_ASSIGN(ModelChangingSyncerCommand);
83 }; 81 };
84 82
85 } // namespace browser_sync 83 } // namespace browser_sync
86 84
87 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_ 85 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_CHANGING_SYNCER_COMMAND_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/get_commit_ids_command.cc ('k') | chrome/browser/sync/engine/model_changing_syncer_command.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698