michael@0: // Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_CRITICAL_CLOSURE_H_ michael@0: #define BASE_CRITICAL_CLOSURE_H_ michael@0: michael@0: #include "base/callback.h" michael@0: michael@0: namespace base { michael@0: michael@0: // Returns a closure that will continue to run for a period of time when the michael@0: // application goes to the background if possible on platforms where michael@0: // applications don't execute while backgrounded, otherwise the original task is michael@0: // returned. michael@0: // michael@0: // Example: michael@0: // file_message_loop_proxy_->PostTask( michael@0: // FROM_HERE, michael@0: // MakeCriticalClosure(base::Bind(&WriteToDiskTask, path_, data))); michael@0: // michael@0: // Note new closures might be posted in this closure. If the new closures need michael@0: // background running time, |MakeCriticalClosure| should be applied on them michael@0: // before posting. michael@0: #if defined(OS_IOS) michael@0: base::Closure MakeCriticalClosure(const base::Closure& closure); michael@0: #else michael@0: inline base::Closure MakeCriticalClosure(const base::Closure& closure) { michael@0: // No-op for platforms where the application does not need to acquire michael@0: // background time for closures to finish when it goes into the background. michael@0: return closure; michael@0: } michael@0: #endif // !defined(OS_IOS) michael@0: michael@0: } // namespace base michael@0: michael@0: #endif // BASE_CRITICAL_CLOSURE_H_