Revision: 12280
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=12280&view=rev
Author:   amaxwell
Date:     2008-01-05 10:54:31 -0800 (Sat, 05 Jan 2008)

Log Message:
-----------
Rename an ivar to better reflect its meaning.

Don't block the rendering thread waiting for renderOffscreenOnMainThread to
complete, since that can be slow.  I thought loadRequest: kicked off some
asynchronous calls, but something is blocking.

Remove some checks that should no longer be relevant, but assert the conditions
just in case.

Modified Paths:
--------------
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.h
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.h   2008-01-05 
18:48:31 UTC (rev 12279)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.h   2008-01-05 
18:54:31 UTC (rev 12280)
@@ -53,7 +53,7 @@
     NSSize           _desiredSize;
     char            *_diskCacheName;
     WebView         *_webView;
-    BOOL             _triedWebView;
+    BOOL             _isRendering;
     pthread_mutex_t  _mutex;
 }
 

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m   2008-01-05 
18:48:31 UTC (rev 12279)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVWebViewIcon.m   2008-01-05 
18:54:31 UTC (rev 12280)
@@ -82,8 +82,8 @@
         // track failure messages via the delegate
         _webviewFailed = NO;
         
-        // main thread only; keeps track of whether a webview has been created
-        _triedWebView = NO;
+        // keeps track of whether a webview has been created
+        _isRendering = NO;
         
         const char *name = [[aURL absoluteString] UTF8String];
         _diskCacheName = NSZoneMalloc([self zone], sizeof(char) * 
(strlen(name) + 1));
@@ -124,7 +124,7 @@
 {
     NSAssert(pthread_mutex_trylock(&_mutex) != 0, @"changing _webView without 
aquiring lock!");
     if (nil != _webView) {
-        _triedWebView = NO;
+        _isRendering = NO;
         [self _releaseWebView];
     }
 }
@@ -134,7 +134,7 @@
     // the thumbnail is small enough to always keep around
     pthread_mutex_lock(&_mutex);
     
-    // Cancel any pending loads; set _triedWebView to NO if there was a 
non-nil webview (i.e. it was loading), or else -renderOffscreenOnMainThread 
will never complete if it gets called again.
+    // Cancel any pending loads; set _isRendering to NO if there was a non-nil 
webview (i.e. it was loading), or else -renderOffscreenOnMainThread will never 
complete if it gets called again.
     [self 
performSelectorOnMainThread:@selector(_releaseWebViewAndRetryIfNeeded) 
withObject:nil waitUntilDone:YES];
     
     CGImageRelease(_fullImageRef);
@@ -167,10 +167,10 @@
         
         if (YES == _webviewFailed)
             needsRender = (nil == _fallbackIcon || [_fallbackIcon 
needsRenderForSize:size]);
-        else if (size.height > 1.2 * [self _thumbnailSize].height && NO == 
_triedWebView)
+        else if (size.height > 1.2 * [self _thumbnailSize].height && NO == 
_isRendering)
             needsRender = (NULL == _fullImageRef);
         else
-            needsRender = (NULL == _thumbnailRef && NO == _triedWebView);
+            needsRender = (NULL == _thumbnailRef && NO == _isRendering);
         pthread_mutex_unlock(&_mutex);
     }
     return needsRender;
@@ -348,46 +348,39 @@
     NSAssert2(pthread_main_np() != 0, @"*** threading violation *** -[%@ 
[EMAIL PROTECTED] requires main thread", [self class], 
NSStringFromSelector(_cmd));
 
     // Originally just checked nil here, but logging showed that a webview was 
instantiated twice and the page loaded both times.  A nil webview is not a 
sufficient condition, since there's a delay between needsRenderForSize: and 
renderOffscreen; remember that the webview isn't rendering synchronously as in 
the other subclasses, so it may finish in between those calls.
-    pthread_mutex_lock(&_mutex);
-    BOOL triedWebview = _triedWebView;
-    pthread_mutex_unlock(&_mutex);
     
-    if (nil == _webView && NO == triedWebview) {
-        
-        pthread_mutex_lock(&_mutex);
-        _triedWebView = YES;
-        pthread_mutex_unlock(&_mutex);
+    NSAssert(nil == _webView, @"*** Render error *** 
renderOffscreenOnMainThread called when _webView already exists");
 
-        NSSize size = [self _webviewSize];
-        
-        // always use the WebKit cache, and use a short timeout (default is 60 
seconds)
-        NSURLRequest *request = [NSURLRequest requestWithURL:_httpURL 
cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10.0];
-        
-        // See also 
http://lists.apple.com/archives/quicklook-dev/2007/Nov/msg00047.html
-        // Note: changed from blocking to non-blocking; we now just keep state 
and rely on the
-        // delegate methods.
-        
-        _webView = [[WebView alloc] initWithFrame:NSMakeRect(0, 0, size.width, 
size.height)];
-        
-        Class cls = [self class];
-        NSString *prefIdentifier = [NSString stringWithFormat:@"[EMAIL 
PROTECTED]@", [[NSBundle bundleForClass:cls] bundleIdentifier], cls];
-        [_webView setPreferencesIdentifier:prefIdentifier];
-        
-        WebPreferences *prefs = [_webView preferences];
-        [prefs setPlugInsEnabled:NO];
-        [prefs setJavaEnabled:NO];
-        [prefs setJavaScriptCanOpenWindowsAutomatically:NO];
-        [prefs setJavaScriptEnabled:NO];
-        [prefs setAllowsAnimatedImages:NO];
-        
-        // most memory-efficient setting; remote resources are still cached to 
disk
-        if ([prefs respondsToSelector:@selector(setCacheModel:)])
-            [prefs setCacheModel:WebCacheModelDocumentViewer];
-        
-        [_webView setFrameLoadDelegate:self];
-        [_webView setPolicyDelegate:self];
-        [[_webView mainFrame] loadRequest:request];
-    }
+    NSSize size = [self _webviewSize];
+    
+    // always use the WebKit cache, and use a short timeout (default is 60 
seconds)
+    NSURLRequest *request = [NSURLRequest requestWithURL:_httpURL 
cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10.0];
+    
+    // See also 
http://lists.apple.com/archives/quicklook-dev/2007/Nov/msg00047.html
+    // Note: changed from blocking to non-blocking; we now just keep state and 
rely on the
+    // delegate methods.
+    
+    _webView = [[WebView alloc] initWithFrame:NSMakeRect(0, 0, size.width, 
size.height)];
+    
+    Class cls = [self class];
+    NSString *prefIdentifier = [NSString stringWithFormat:@"[EMAIL 
PROTECTED]@", [[NSBundle bundleForClass:cls] bundleIdentifier], cls];
+    [_webView setPreferencesIdentifier:prefIdentifier];
+    
+    WebPreferences *prefs = [_webView preferences];
+    [prefs setPlugInsEnabled:NO];
+    [prefs setJavaEnabled:NO];
+    [prefs setJavaScriptCanOpenWindowsAutomatically:NO];
+    [prefs setJavaScriptEnabled:NO];
+    [prefs setAllowsAnimatedImages:NO];
+    
+    // most memory-efficient setting; remote resources are still cached to disk
+    if ([prefs respondsToSelector:@selector(setCacheModel:)])
+        [prefs setCacheModel:WebCacheModelDocumentViewer];
+    
+    [_webView setFrameLoadDelegate:self];
+    [_webView setPolicyDelegate:self];
+    [[_webView mainFrame] loadRequest:request];
+
 }
 
 - (void)renderOffscreen
@@ -395,7 +388,7 @@
     // !!! early return here after a cache check
     pthread_mutex_lock(&_mutex);
     
-    CGImageRelease(_fullImageRef);
+    NSParameterAssert(NULL == _fullImageRef);
     _fullImageRef = [FVIconCache newImageNamed:_diskCacheName];
     if (_fullImageRef) {
         
@@ -406,25 +399,24 @@
         pthread_mutex_unlock(&_mutex);
         return;
     }
-    
+        
+    // if we can't even reach the network, don't bother using the webview
     // may have failed in one of the delegate methods, so we'll continue on 
and load the fallback icon here
-    BOOL alreadyFailed = _webviewFailed;
-    
-    pthread_mutex_unlock(&_mutex);
-    
-    // if we can't even reach the network, don't bother blocking the main 
thread for a failed load
-    if ([self _canReachURL] && NO == alreadyFailed) {
-        [self 
performSelectorOnMainThread:@selector(renderOffscreenOnMainThread) 
withObject:nil waitUntilDone:YES];
+
+    if ([self _canReachURL] && NO == _webviewFailed && NO == _isRendering) {
+        // make sure needsRenderForSize: knows that we're actively rendering, 
so renderOffscreen doesn't get called again
+        _isRendering = YES;
+        [self 
performSelectorOnMainThread:@selector(renderOffscreenOnMainThread) 
withObject:nil waitUntilDone:NO];
     }
     else {
         // Unreachable or failed to load.  Load a Finder icon and set the 
webview failure bit; we won't try again.
-        pthread_mutex_lock(&_mutex);
         _webviewFailed = YES;
+        _isRendering = NO;
         if (nil == _fallbackIcon)
             _fallbackIcon = [[FVFinderIcon alloc] initWithURLScheme:[_httpURL 
scheme]];
         [_fallbackIcon renderOffscreen];
-        pthread_mutex_unlock(&_mutex);
     }
+    pthread_mutex_unlock(&_mutex);
 }
 
 - (void)fastDrawInRect:(NSRect)dstRect inCGContext:(CGContextRef)context;


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to