ipc/chromium/src/base/worker_pool_mac.mm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Copyright (c) 2008 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.
     5 #include "base/worker_pool.h"
     7 #import <Foundation/Foundation.h>
     9 #include "base/logging.h"
    10 #import "base/singleton_objc.h"
    11 #include "base/task.h"
    13 // TaskOperation adapts Task->Run() for use in an NSOperationQueue.
    14 @interface TaskOperation : NSOperation {
    15  @private
    16   Task* task_;  // (strong)
    17 }
    19 // Returns an autoreleased instance of TaskOperation.  See -initWithTask: for
    20 // details.
    21 + (id)taskOperationWithTask:(Task*)task;
    23 // Designated initializer.  |task| is adopted as the Task* whose Run method
    24 // this operation will call when executed.
    25 - (id)initWithTask:(Task*)task;
    27 @end
    29 @implementation TaskOperation
    31 + (id)taskOperationWithTask:(Task*)task {
    32   return [[[TaskOperation alloc] initWithTask:task] autorelease];
    33 }
    35 - (id)init {
    36   return [self initWithTask:NULL];
    37 }
    39 - (id)initWithTask:(Task*)task {
    40   if ((self = [super init])) {
    41     task_ = task;
    42   }
    43   return self;
    44 }
    46 - (void)main {
    47   DCHECK(task_) << "-[TaskOperation main] called with no task";
    48   task_->Run();
    49   delete task_;
    50   task_ = NULL;
    51 }
    53 - (void)dealloc {
    54   DCHECK(!task_) << "-[TaskOperation dealloc] called on unused TaskOperation";
    55   delete task_;
    56   [super dealloc];
    57 }
    59 @end
    61 bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
    62                           Task* task, bool task_is_slow) {
    63   // Ignore |task_is_slow|, it doesn't map directly to any tunable aspect of
    64   // an NSOperation.
    66   task->SetBirthPlace(from_here);
    68   NSOperationQueue* operation_queue = SingletonObjC<NSOperationQueue>::get();
    69   [operation_queue addOperation:[TaskOperation taskOperationWithTask:task]];
    71   return true;
    72 }

mercurial