blob: 405cdff587951d93c5cccac1534f32921f1ddfd5 [file] [log] [blame]
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001// Copyright 2012 The Chromium Authors. All rights reserved.
Torne (Richard Coles)58218062012-11-14 11:43:16 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SYNC_ENGINE_BUILD_COMMIT_COMMAND_H_
6#define SYNC_ENGINE_BUILD_COMMIT_COMMAND_H_
7
8#include "base/basictypes.h"
9#include "base/compiler_specific.h"
10#include "base/gtest_prod_util.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000011#include "sync/base/sync_export.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000012#include "sync/engine/syncer_command.h"
13#include "sync/syncable/entry_kernel.h"
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010014#include "sync/util/extensions_activity.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000015
16namespace syncer {
17
18namespace sessions {
19class OrderedCommitSet;
20}
21
22namespace syncable {
23class Entry;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000024class BaseTransaction;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000025}
26
27// A class that contains the code used to serialize a set of sync items into a
28// protobuf commit message. This conversion process references the
29// syncable::Directory, which is why it must be called within the same
30// transaction as the GetCommitIdsCommand that fetched the set of items to be
31// committed.
32//
33// See SyncerCommand documentation for more info.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000034class SYNC_EXPORT_PRIVATE BuildCommitCommand : public SyncerCommand {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000035 public:
36 // The batch_commit_set parameter contains a set of references to the items
37 // that should be committed.
38 //
39 // The commit_message parameter is an output parameter which will contain the
40 // fully initialized commit message once ExecuteImpl() has been called.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000041 BuildCommitCommand(
42 syncable::BaseTransaction* trans,
43 const sessions::OrderedCommitSet& batch_commit_set,
44 sync_pb::ClientToServerMessage* commit_message,
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010045 ExtensionsActivity::Records* extensions_activity_buffer);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000046 virtual ~BuildCommitCommand();
47
48 // SyncerCommand implementation.
49 virtual SyncerError ExecuteImpl(sessions::SyncSession* session) OVERRIDE;
50
51 private:
52 FRIEND_TEST_ALL_PREFIXES(BuildCommitCommandTest, InterpolatePosition);
53
Torne (Richard Coles)58218062012-11-14 11:43:16 +000054 void AddExtensionsActivityToMessage(sessions::SyncSession* session,
55 sync_pb::CommitMessage* message);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000056
57 // Fills the config_params field of |message|.
58 void AddClientConfigParamsToMessage(sessions::SyncSession* session,
59 sync_pb::CommitMessage* message);
60
Torne (Richard Coles)58218062012-11-14 11:43:16 +000061 DISALLOW_COPY_AND_ASSIGN(BuildCommitCommand);
62
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000063 // A pointer to a valid transaction not owned by this class.
64 syncable::BaseTransaction* trans_;
65
Torne (Richard Coles)58218062012-11-14 11:43:16 +000066 // Input parameter; see constructor comment.
67 const sessions::OrderedCommitSet& batch_commit_set_;
68
69 // Output parameter; see constructor comment.
70 sync_pb::ClientToServerMessage* commit_message_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000071
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010072 ExtensionsActivity::Records* extensions_activity_buffer_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000073};
74
75} // namespace syncer
76
77#endif // SYNC_ENGINE_BUILD_COMMIT_COMMAND_H_