mukesh agrawal | 46c27cc | 2013-07-10 16:39:10 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS 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 "shill/result_aggregator.h" |
| 6 | |
| 7 | #include "shill/logging.h" |
| 8 | |
| 9 | namespace shill { |
| 10 | |
| 11 | ResultAggregator::ResultAggregator(const ResultCallback &callback) |
| 12 | : callback_(callback), got_result_(false) { |
| 13 | CHECK(!callback.is_null()); |
| 14 | } |
| 15 | |
| 16 | ResultAggregator::~ResultAggregator() { |
| 17 | if (got_result_) { |
| 18 | callback_.Run(error_); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | void ResultAggregator::ReportResult(const Error &error) { |
| 23 | CHECK(!error.IsOngoing()); // We want the final result. |
| 24 | got_result_ = true; |
| 25 | if (error_.IsSuccess()) { // Only copy first |error|. |
| 26 | error_.CopyFrom(error); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | } // namespace shill |