| Index: base/worker_pool_mac.mm
|
| ===================================================================
|
| --- base/worker_pool_mac.mm (revision 30049)
|
| +++ base/worker_pool_mac.mm (working copy)
|
| @@ -2,18 +2,26 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "base/worker_pool.h"
|
| +#include "base/worker_pool_mac.h"
|
|
|
| -#import <Foundation/Foundation.h>
|
| -
|
| #include "base/logging.h"
|
| +#import "base/scoped_nsautorelease_pool.h"
|
| +#include "base/scoped_ptr.h"
|
| #import "base/singleton_objc.h"
|
| #include "base/task.h"
|
|
|
| +@implementation WorkerPoolObjC
|
| +
|
| ++ (NSOperationQueue*)sharedOperationQueue {
|
| + return SingletonObjC<NSOperationQueue>::get();
|
| +}
|
| +
|
| +@end // @implementation WorkerPoolObjC
|
| +
|
| // TaskOperation adapts Task->Run() for use in an NSOperationQueue.
|
| @interface TaskOperation : NSOperation {
|
| @private
|
| - Task* task_; // (strong)
|
| + scoped_ptr<Task> task_;
|
| }
|
|
|
| // Returns an autoreleased instance of TaskOperation. See -initWithTask: for
|
| @@ -24,7 +32,7 @@
|
| // this operation will call when executed.
|
| - (id)initWithTask:(Task*)task;
|
|
|
| -@end
|
| +@end // @interface TaskOperation
|
|
|
| @implementation TaskOperation
|
|
|
| @@ -38,34 +46,45 @@
|
|
|
| - (id)initWithTask:(Task*)task {
|
| if ((self = [super init])) {
|
| - task_ = task;
|
| + task_.reset(task);
|
| }
|
| return self;
|
| }
|
|
|
| - (void)main {
|
| - DCHECK(task_) << "-[TaskOperation main] called with no task";
|
| + DCHECK(task_.get()) << "-[TaskOperation main] called with no task";
|
| + if (!task_.get()) {
|
| + return;
|
| + }
|
| +
|
| + base::ScopedNSAutoreleasePool autoreleasePool;
|
| +
|
| task_->Run();
|
| - delete task_;
|
| - task_ = NULL;
|
| + task_.reset(NULL);
|
| }
|
|
|
| - (void)dealloc {
|
| - DCHECK(!task_) << "-[TaskOperation dealloc] called on unused TaskOperation";
|
| - delete task_;
|
| + DCHECK(!task_.get())
|
| + << "-[TaskOperation dealloc] called without running task";
|
| +
|
| [super dealloc];
|
| }
|
|
|
| -@end
|
| +@end // @implementation TaskOperation
|
|
|
| bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
|
| Task* task, bool task_is_slow) {
|
| // Ignore |task_is_slow|, it doesn't map directly to any tunable aspect of
|
| // an NSOperation.
|
|
|
| + DCHECK(task) << "WorkerPool::PostTask called with no task";
|
| + if (!task) {
|
| + return false;
|
| + }
|
| +
|
| task->SetBirthPlace(from_here);
|
|
|
| - NSOperationQueue* operation_queue = SingletonObjC<NSOperationQueue>::get();
|
| + NSOperationQueue* operation_queue = [WorkerPoolObjC sharedOperationQueue];
|
| [operation_queue addOperation:[TaskOperation taskOperationWithTask:task]];
|
|
|
| return true;
|
|
|