Home | History | Annotate | Download | only in util
      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.
      4 
      5 #include "chrome/installer/util/callback_work_item.h"
      6 
      7 #include "base/callback.h"
      8 #include "base/logging.h"
      9 #include "chrome/installer/util/work_item.h"
     10 
     11 CallbackWorkItem::CallbackWorkItem(
     12     base::Callback<bool(const CallbackWorkItem&)> callback)
     13     : callback_(callback),
     14       roll_state_(RS_UNDEFINED) {
     15 }
     16 
     17 CallbackWorkItem::~CallbackWorkItem() {
     18 }
     19 
     20 bool CallbackWorkItem::Do() {
     21   DCHECK_EQ(roll_state_, RS_UNDEFINED);
     22 
     23   roll_state_ = RS_FORWARD;
     24   bool result = callback_.Run(*this);
     25   roll_state_ = RS_UNDEFINED;
     26 
     27   return result;
     28 }
     29 
     30 void CallbackWorkItem::Rollback() {
     31   DCHECK_EQ(roll_state_, RS_UNDEFINED);
     32 
     33   roll_state_ = RS_BACKWARD;
     34   ignore_result(callback_.Run(*this));
     35   roll_state_ = RS_UNDEFINED;
     36 }
     37 
     38 bool CallbackWorkItem::IsRollback() const {
     39   DCHECK_NE(roll_state_, RS_UNDEFINED);
     40   return roll_state_ == RS_BACKWARD;
     41 }
     42