Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / installer / util / callback_work_item.h
blob3cc22f656ed415a4c1453444d0bffe700ba76b8c
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
15 // list is processed.
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.
21 // return true;
22 // }
24 // // Roll forward work goes here. The return value indicates success/failure
25 // // of the item.
26 // return true;
27 // }
29 // void SomeFunctionThatAddsItemsToAList(WorkItemList* item_list) {
30 // ...
31 // item_list->AddCallbackWorkItem(base::Bind(&SomeWorkItemCallback));
32 // ...
33 // }
34 class CallbackWorkItem : public WorkItem {
35 public:
36 ~CallbackWorkItem() override;
38 bool Do() override;
39 void Rollback() override;
41 bool IsRollback() const;
43 private:
44 friend class WorkItem;
46 enum RollState {
47 RS_UNDEFINED,
48 RS_FORWARD,
49 RS_BACKWARD,
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_