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
3 // found in the LICENSE file.
5 #ifndef CHROME_INSTALLER_UTIL_CALLBACK_WORK_ITEM_H_
6 #define CHROME_INSTALLER_UTIL_CALLBACK_WORK_ITEM_H_
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/gtest_prod_util.h"
11 #include "chrome/installer/util/work_item.h"
13 // A work item that invokes a callback on Do() and Rollback(). In the following
14 // example, the function SomeWorkItemCallback() will be invoked when an item
17 // // A callback invoked to do some work.
18 // bool SomeWorkItemCallback(const CallbackWorkItem& item) {
19 // if (item.IsRollback()) {
20 // // Rollback work goes here. The return value is ignored in this case.
24 // // Roll forward work goes here. The return value indicates success/failure
29 // void SomeFunctionThatAddsItemsToAList(WorkItemList* item_list) {
31 // item_list->AddCallbackWorkItem(base::Bind(&SomeWorkItemCallback));
34 class CallbackWorkItem
: public WorkItem
{
36 virtual ~CallbackWorkItem();
38 virtual bool Do() override
;
39 virtual void Rollback() override
;
41 bool IsRollback() const;
44 friend class WorkItem
;
52 CallbackWorkItem(base::Callback
<bool(const CallbackWorkItem
&)> callback
);
54 base::Callback
<bool(const CallbackWorkItem
&)> callback_
;
55 RollState roll_state_
;
57 FRIEND_TEST_ALL_PREFIXES(CallbackWorkItemTest
, TestFailure
);
58 FRIEND_TEST_ALL_PREFIXES(CallbackWorkItemTest
, TestForwardBackward
);
61 #endif // CHROME_INSTALLER_UTIL_CALLBACK_WORK_ITEM_H_