OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 SYNC_ENGINE_COMMIT_H_ | 5 #ifndef SYNC_ENGINE_COMMIT_H_ |
6 #define SYNC_ENGINE_COMMIT_H_ | 6 #define SYNC_ENGINE_COMMIT_H_ |
7 | 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/stl_util.h" |
| 11 #include "sync/base/sync_export.h" |
| 12 #include "sync/engine/sync_directory_commit_contributor.h" |
8 #include "sync/internal_api/public/base/model_type.h" | 13 #include "sync/internal_api/public/base/model_type.h" |
| 14 #include "sync/internal_api/public/engine/model_safe_worker.h" |
9 #include "sync/internal_api/public/util/syncer_error.h" | 15 #include "sync/internal_api/public/util/syncer_error.h" |
| 16 #include "sync/protocol/sync.pb.h" |
| 17 #include "sync/util/extensions_activity.h" |
| 18 |
| 19 namespace sync_pb { |
| 20 class ClientToServerMessage; |
| 21 class ClientToServerResponse; |
| 22 } |
10 | 23 |
11 namespace syncer { | 24 namespace syncer { |
12 | 25 |
13 namespace sessions { | 26 namespace sessions { |
| 27 class StatusController; |
14 class SyncSession; | 28 class SyncSession; |
15 } | 29 } |
16 | 30 |
| 31 class SyncDirectoryCommitContribution; |
| 32 class SyncDirectoryCommitContributor; |
17 class Syncer; | 33 class Syncer; |
18 | 34 |
19 // This function will commit batches of unsynced items to the server until the | 35 // This function will commit batches of unsynced items to the server until the |
20 // number of unsynced and ready to commit items reaches zero or an error is | 36 // number of unsynced and ready to commit items reaches zero or an error is |
21 // encountered. A request to exit early will be treated as an error and will | 37 // encountered. A request to exit early will be treated as an error and will |
22 // abort any blocking operations. | 38 // abort any blocking operations. |
23 // | 39 // |
24 // The Syncer parameter is provided only for access to its ExitRequested() | 40 // The Syncer parameter is provided only for access to its ExitRequested() |
25 // method. This is technically unnecessary since an early exit request should | 41 // method. This is technically unnecessary since an early exit request should |
26 // be detected as we attempt to contact the sync server. | 42 // be detected as we attempt to contact the sync server. |
27 // | 43 // |
28 // The SyncSession parameter contains pointers to various bits of state, | 44 // The SyncSession parameter contains pointers to various bits of state, |
29 // including the syncable::Directory that contains all sync items and the | 45 // including the syncable::Directory that contains all sync items and the |
30 // ServerConnectionManager used to contact the server. | 46 // ServerConnectionManager used to contact the server. |
31 SyncerError BuildAndPostCommits( | 47 SyncerError BuildAndPostCommits( |
32 ModelTypeSet request_types, | 48 ModelTypeSet request_types, |
33 Syncer* syncer, | 49 Syncer* syncer, |
34 sessions::SyncSession* session); | 50 sessions::SyncSession* session); |
35 | 51 |
| 52 // This class wraps the actions related to building and executing a single |
| 53 // commit operation. |
| 54 // |
| 55 // This class' most important responsibility is to manage the ContributionsMap. |
| 56 // This class serves as a container for those objects. Although it would have |
| 57 // been acceptable to let this class be a dumb container object, it turns out |
| 58 // that there was no other convenient place to put the Init() and |
| 59 // PostAndProcessCommitResponse() functions. So they ended up here. |
| 60 class SYNC_EXPORT_PRIVATE Commit { |
| 61 public: |
| 62 static Commit* Init( |
| 63 ModelTypeSet requested_types, |
| 64 CommitContributorMap* contributor_map, |
| 65 size_t max_entries, |
| 66 const std::string& account_name, |
| 67 const std::string& cache_guid, |
| 68 ExtensionsActivity* extensions_activity); |
| 69 |
| 70 explicit Commit( |
| 71 std::map<ModelType, SyncDirectoryCommitContribution*> contributions, |
| 72 sync_pb::ClientToServerMessage message, |
| 73 ExtensionsActivity::Records extensions_activity_buffer); |
| 74 ~Commit(); |
| 75 |
| 76 SyncerError PostAndProcessResponse( |
| 77 sessions::SyncSession* session, |
| 78 sessions::StatusController* status, |
| 79 ExtensionsActivity* extensions_activity); |
| 80 |
| 81 private: |
| 82 typedef std::map<ModelType, SyncDirectoryCommitContribution*> ContributionMap; |
| 83 |
| 84 ContributionMap contributions_; |
| 85 STLValueDeleter<ContributionMap> deleter_; |
| 86 |
| 87 sync_pb::ClientToServerMessage message_; |
| 88 sync_pb::ClientToServerResponse response_; |
| 89 ExtensionsActivity::Records extensions_activity_buffer_; |
| 90 }; |
| 91 |
36 } // namespace syncer | 92 } // namespace syncer |
37 | 93 |
38 #endif // SYNC_ENGINE_COMMIT_H_ | 94 #endif // SYNC_ENGINE_COMMIT_H_ |
OLD | NEW |