| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.  Use of this | 
|  | 2 // source code is governed by a BSD-style license that can be found in the | 
|  | 3 // LICENSE file. | 
|  | 4 | 
|  | 5 // Some basic utilities for aiding in the management of Tasks and Callbacks. | 
|  | 6 // AutoTaskRunner, and its brother AutoCallbackRunner are the scoped_ptr | 
|  | 7 // equivalents for callbacks.  They are useful for ensuring a callback is | 
|  | 8 // executed and delete in the face of multiple return points in a function. | 
|  | 9 | 
|  | 10 #ifndef MEDIA_BASE_CALLBACK_ | 
|  | 11 #define MEDIA_BASE_CALLBACK_ | 
|  | 12 | 
|  | 13 #include "base/scoped_ptr.h" | 
|  | 14 #include "base/task.h" | 
|  | 15 | 
|  | 16 namespace media { | 
|  | 17 | 
|  | 18 class AutoTaskRunner { | 
|  | 19  public: | 
|  | 20   // Takes ownership of the task. | 
|  | 21   explicit AutoTaskRunner(Task* task) | 
|  | 22       : task_(task) { | 
|  | 23   } | 
|  | 24 | 
|  | 25   ~AutoTaskRunner() { | 
|  | 26     if (task_.get()) { | 
|  | 27       task_->Run(); | 
|  | 28     } | 
|  | 29   } | 
|  | 30 | 
|  | 31   Task* release() { return task_.release(); } | 
|  | 32 | 
|  | 33  private: | 
|  | 34   scoped_ptr<Task> task_; | 
|  | 35 | 
|  | 36   DISALLOW_COPY_AND_ASSIGN(AutoTaskRunner); | 
|  | 37 }; | 
|  | 38 | 
|  | 39 class AutoCallbackRunner { | 
|  | 40  public: | 
|  | 41   // Takes ownership of the callback. | 
|  | 42   explicit AutoCallbackRunner(Callback0::Type* callback) | 
|  | 43       : callback_(callback) { | 
|  | 44   } | 
|  | 45 | 
|  | 46   ~AutoCallbackRunner() { | 
|  | 47     if (callback_.get()) { | 
|  | 48       callback_->Run(); | 
|  | 49     } | 
|  | 50   } | 
|  | 51 | 
|  | 52   Callback0::Type* release() { return callback_.release(); } | 
|  | 53 | 
|  | 54  private: | 
|  | 55   scoped_ptr<Callback0::Type> callback_; | 
|  | 56 | 
|  | 57   DISALLOW_COPY_AND_ASSIGN(AutoCallbackRunner); | 
|  | 58 }; | 
|  | 59 | 
|  | 60 }  // namespace media | 
|  | 61 | 
|  | 62 #endif  // MEDIA_BASE_CALLBACK_ | 
| OLD | NEW | 
|---|