summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-05 23:15:58 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-05 23:15:58 +0000
commit56fedfa29f49ce793d3343525f120eaff5f2b752 (patch)
treea4b709a6fbc9587338f3fed58f5f885e8138486a /chrome/browser
parent27bc9e8ac1922f88fbe003c9b050add4e27321b0 (diff)
downloadchromium_src-56fedfa29f49ce793d3343525f120eaff5f2b752.zip
chromium_src-56fedfa29f49ce793d3343525f120eaff5f2b752.tar.gz
chromium_src-56fedfa29f49ce793d3343525f120eaff5f2b752.tar.bz2
[Mac] Use Linux WorkerPool code.
Adapts things to use the Linux WorkerPool code by default, with --disable-linux-workerpool to switch back to the old version. The old implementation uses NSOperationQueue, which is implemented in terms of pthread workqueues. These are implicated by the stack traces from the recent unit test flakiness. This change attempts to influence that flakiness. BUG=20471, 60426 TEST=Tree green. Review URL: http://codereview.chromium.org/4595001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65273 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/app_controller_mac.mm10
-rw-r--r--chrome/browser/cocoa/keystone_glue.mm72
2 files changed, 64 insertions, 18 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index aa5af1f..f05548a 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -13,6 +13,7 @@
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
#include "base/sys_string_conversions.h"
+#import "base/worker_pool_mac.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_init.h"
@@ -222,6 +223,15 @@ void RecordLastRunAppBundlePath() {
if (parsed_command_line.HasSwitch(switches::kActivateOnLaunch)) {
[NSApp activateIgnoringOtherApps:YES];
}
+
+ // Temporary flag to revert to the old WorkerPool implementation.
+ // This will be removed once we either fix the Mac WorkerPool
+ // implementation, or completely switch to the shared (with Linux)
+ // implementation.
+ // http://crbug.com/44392
+ if (parsed_command_line.HasSwitch(switches::kDisableLinuxWorkerPool)) {
+ worker_pool_mac::SetUseLinuxWorkerPool(false);
+ }
}
// (NSApplicationDelegate protocol) This is the Apple-approved place to override
diff --git a/chrome/browser/cocoa/keystone_glue.mm b/chrome/browser/cocoa/keystone_glue.mm
index a0162a3..4ba9b21 100644
--- a/chrome/browser/cocoa/keystone_glue.mm
+++ b/chrome/browser/cocoa/keystone_glue.mm
@@ -13,8 +13,12 @@
#import "app/l10n_util_mac.h"
#include "base/logging.h"
#include "base/mac_util.h"
+#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/sys_string_conversions.h"
#import "base/worker_pool_mac.h"
+#include "base/ref_counted.h"
+#include "base/task.h"
+#include "base/worker_pool.h"
#include "chrome/browser/cocoa/authorization_util.h"
#include "chrome/common/chrome_constants.h"
#include "grit/chromium_strings.h"
@@ -89,6 +93,51 @@ NSString* SystemBrandFilePath() {
return [kBrandSystemFile stringByStandardizingPath];
}
+// Adaptor for scheduling an Objective-C method call on a |WorkerPool|
+// thread.
+// TODO(shess): Move this into workerpool_mac.h?
+class PerformBridge : public base::RefCountedThreadSafe<PerformBridge> {
+ public:
+
+ // Call |sel| on |target| with |arg| in a WorkerPool thread.
+ // |target| and |arg| are retained, |arg| may be |nil|.
+ static void PostPerform(id target, SEL sel, id arg) {
+ DCHECK(target);
+ DCHECK(sel);
+
+ scoped_refptr<PerformBridge> op = new PerformBridge(target, sel, arg);
+ WorkerPool::PostTask(
+ FROM_HERE, NewRunnableMethod(op.get(), &PerformBridge::Run), true);
+ }
+
+ // Convenience for the no-argument case.
+ static void PostPerform(id target, SEL sel) {
+ PostPerform(target, sel, nil);
+ }
+
+ private:
+ // Allow RefCountedThreadSafe<> to delete.
+ friend class base::RefCountedThreadSafe<PerformBridge>;
+
+ PerformBridge(id target, SEL sel, id arg)
+ : target_([target retain]),
+ sel_(sel),
+ arg_([arg retain]) {
+ }
+
+ ~PerformBridge() {}
+
+ // Happens on a WorkerPool thread.
+ void Run() {
+ base::mac::ScopedNSAutoreleasePool pool;
+ [target_ performSelector:sel_ withObject:arg_];
+ }
+
+ scoped_nsobject<id> target_;
+ SEL sel_;
+ scoped_nsobject<id> arg_;
+};
+
} // namespace
@interface KSRegistration : NSObject
@@ -147,7 +196,7 @@ NSString* SystemBrandFilePath() {
// -determineUpdateStatusAsync is called on the main thread to initiate the
// operation. It performs initial set-up work that must be done on the main
// thread and arranges for -determineUpdateStatus to be called on a work queue
-// thread managed by NSOperationQueue.
+// thread managed by WorkerPool.
// -determineUpdateStatus then reads the Info.plist, gets the version from the
// CFBundleShortVersionString key, and performs
// -determineUpdateStatusForVersion: on the main thread.
@@ -562,17 +611,10 @@ NSString* const kBrandKey = @"KSBrandID";
- (void)determineUpdateStatusAsync {
DCHECK([NSThread isMainThread]);
- SEL selector = @selector(determineUpdateStatus);
- NSInvocationOperation* operation =
- [[[NSInvocationOperation alloc] initWithTarget:self
- selector:selector
- object:nil] autorelease];
-
- NSOperationQueue* operationQueue = [WorkerPoolObjC sharedOperationQueue];
- [operationQueue addOperation:operation];
+ PerformBridge::PostPerform(self, @selector(determineUpdateStatus));
}
-// Runs on a thread managed by NSOperationQueue.
+// Runs on a thread managed by WorkerPool.
- (void)determineUpdateStatus {
DCHECK(![NSThread isMainThread]);
@@ -849,7 +891,7 @@ NSString* const kBrandKey = @"KSBrandID";
- (void)changePermissionsForPromotionAsync {
// NSBundle is not documented as being thread-safe. Do NSBundle operations
- // on the main thread before jumping over to a NSOperationQueue-managed
+ // on the main thread before jumping over to a WorkerPool-managed
// thread to run the tool.
DCHECK([NSThread isMainThread]);
@@ -858,13 +900,7 @@ NSString* const kBrandKey = @"KSBrandID";
[mac_util::MainAppBundle() pathForResource:@"keystone_promote_postflight"
ofType:@"sh"];
- NSInvocationOperation* operation =
- [[[NSInvocationOperation alloc] initWithTarget:self
- selector:selector
- object:toolPath] autorelease];
-
- NSOperationQueue* operationQueue = [WorkerPoolObjC sharedOperationQueue];
- [operationQueue addOperation:operation];
+ PerformBridge::PostPerform(self, selector, toolPath);
}
- (void)changePermissionsForPromotionWithTool:(NSString*)toolPath {