Roll src/third_party/WebKit 116cf7f:79abaa8 (svn 189234:189235)
[chromium-blink-merge.git] / chrome / installer / util / conditional_work_item_list.h
blob1e90a78e60eb1551e7e4a97b652a22123eea1b71
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
3 // found in the LICENSE file.
5 #ifndef CHROME_INSTALLER_UTIL_CONDITIONAL_WORK_ITEM_LIST_H_
6 #define CHROME_INSTALLER_UTIL_CONDITIONAL_WORK_ITEM_LIST_H_
8 #include "chrome/installer/util/work_item_list.h"
10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h"
13 // A WorkItemList subclass that permits conditionally executing a set of
14 // WorkItems.
15 class ConditionalWorkItemList : public WorkItemList {
16 public:
17 explicit ConditionalWorkItemList(Condition* condition);
18 virtual ~ConditionalWorkItemList();
20 // If condition_->ShouldRun() returns true, then execute the items in this
21 // list and return true iff they all succeed. If condition_->ShouldRun()
22 // returns false, does nothing and returns true.
23 virtual bool Do();
25 // Does a rollback of the items (if any) that were run in Do.
26 virtual void Rollback();
28 protected:
29 // Pointer to a Condition that is used to determine whether to run this
30 // WorkItemList.
31 scoped_ptr<Condition> condition_;
35 // Pre-defined conditions:
36 //------------------------------------------------------------------------------
37 class ConditionRunIfFileExists : public WorkItem::Condition {
38 public:
39 explicit ConditionRunIfFileExists(const base::FilePath& key_path)
40 : key_path_(key_path) {}
41 bool ShouldRun() const;
43 private:
44 base::FilePath key_path_;
47 // Condition class that inverts the ShouldRun result of another Condition.
48 // This class assumes ownership of original_condition.
49 class Not : public WorkItem::Condition {
50 public:
51 explicit Not(WorkItem::Condition* original_condition)
52 : original_condition_(original_condition) {}
53 bool ShouldRun() const;
55 private:
56 scoped_ptr<WorkItem::Condition> original_condition_;
60 #endif // CHROME_INSTALLER_UTIL_CONDITIONAL_WORK_ITEM_LIST_H_