<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -9,11 +9,12 @@
 #import &lt;Cocoa/Cocoa.h&gt;
 
 @class AppController;
-// @class RequestDetailsController;
+@class LogParser;
 
 @interface LogDocument : NSDocument {
             BOOL                      compressedLog;
             NSArray                   *requests;
+            LogParser                 *logParser;
             
             NSPredicate               *filterPredicate;
             </diff>
      <filename>LogDocument.h</filename>
    </modified>
    <modified>
      <diff>@@ -29,8 +29,6 @@ static NSMutableDictionary *HTTPMethodColors;
 
 @interface LogDocument (PrivateMethods)
 + (NSColor *)colorForHTTPMethod:(NSString *)method brighten:(BOOL)brighten;
-- (void)parseLogData:(NSData *)data;
-- (NSData *)gunzipedDataFromData:(NSData *)compressedData;
 @end
 
 @implementation LogDocument
@@ -96,7 +94,13 @@ static NSMutableDictionary *HTTPMethodColors;
     [self setCompressedLog:NO];
   }
   
-  [NSThread detachNewThreadSelector:@selector(parseLogData:) toTarget:self withObject:data];
+  logParser = [[LogParser alloc] initWithDocument:self];
+  
+  // The parser handles the log data on a background thread. When it is done
+  // it will call back on the main thread to set the requests property.
+  [NSThread detachNewThreadSelector:@selector(parseLogData:)
+                           toTarget:logParser
+                         withObject:data];
   
   // Always return YES. Not quite sure what we should do if there is ever an error
   // in the legitimate load process.
@@ -214,17 +218,4 @@ static NSMutableDictionary *HTTPMethodColors;
 }
 
 
-#pragma mark Implementation
-
-/*
- * Parse the data read from the logfile passing on whether the log data is compressed
- * or not. The resulting array of RailsRequest instances assigned to the 'requests'
- * property back on the main thread.
- */
-- (void)parseLogData:(NSData *)data {
-  LogParser *parser = [[LogParser alloc] initWithDocument:self];
-  [self performSelectorOnMainThread:@selector(setRequests:) withObject:[parser parseLogData:data isCompressed:[self compressedLog]] waitUntilDone:YES];
-}
-
-
 @end</diff>
      <filename>LogDocument.m</filename>
    </modified>
    <modified>
      <diff>@@ -18,11 +18,13 @@
   NSDateFormatter             *dateParser;
   ParamParser                 *paramParser;
   
+  NSUInteger                  highWaterMark;
+  
   ParsingProgressController   *progressController;
 }
 
 - (id)initWithDocument:(LogDocument *)theDocument;
 
-- (NSArray *)parseLogData:(NSData *)data isCompressed:(BOOL)isCompressed;
+- (void)parseLogData:(NSData *)data;
 
 @end</diff>
      <filename>LogParser.h</filename>
    </modified>
    <modified>
      <diff>@@ -38,40 +38,44 @@
 
 - (id)initWithDocument:(LogDocument *)theDocument {
   if( ( self = [super init] ) ) {
-    document = theDocument;
-    dateParser = [[NSDateFormatter alloc] init];
+    document      = theDocument;
+    dateParser    = [[NSDateFormatter alloc] init];
     [dateParser setDateFormat:@&quot;yyyy-MM-dd HH:mm:ss&quot;];
     
-    paramParser = [[ParamParser alloc] init];
+    paramParser   = [[ParamParser alloc] init];
+    highWaterMark = 0;
   }
   
   return self;
 }
 
 
-- (NSArray *)parseLogData:(NSData *)data isCompressed:(BOOL)isCompressed {
+- (void)parseLogData:(NSData *)data {
   progressController = [[ParsingProgressController alloc] init];
   [progressController showWindow:self];
   [progressController setAnimated:YES];
   
-  if( isCompressed ) {
-    [progressController setStatus:@&quot;Decompressing log file&quot;];
+  if( [document compressedLog] ) {
+    [progressController setStatus:@&quot;Decompressing log data&quot;];
     data = [data gzipInflate];
   }
   
-  [progressController setStatus:@&quot;Scanning log file&quot;];
+  [progressController setStatus:@&quot;Scanning log data&quot;];
   NSString *content = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
   NSArray *lines = [content componentsSeparatedByString:@&quot;\n&quot;];
   
-  [progressController setStatus:@&quot;Parsing log file&quot;];
+  [progressController setStatus:@&quot;Parsing log data&quot;];
   [progressController setMin:0 max:[lines count]];
   NSLog( @&quot;%d lines to parse.&quot;, [lines count] );
   
   NSArray *requests = [self parseLogLines:lines];
-  [progressController close];
   NSLog( @&quot;%d requests parsed.&quot;, [requests count] );
   
-  return requests;
+  highWaterMark = [data length];
+  
+  [document performSelectorOnMainThread:@selector(setRequests:) withObject:requests waitUntilDone:YES];
+
+  [progressController close];
 }
 
 </diff>
      <filename>LogParser.m</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>bc239abc174e6bfb17bb8d7b1d0ab6e3fa0d6978</id>
    </parent>
  </parents>
  <author>
    <name>Matt Mower</name>
    <email>self@mattmower.com</email>
  </author>
  <url>http://github.com/mmower/spike/commit/b71f6604df5d397e6519a6d100d02e6b1725de7e</url>
  <id>b71f6604df5d397e6519a6d100d02e6b1725de7e</id>
  <committed-date>2009-02-21T06:26:47-08:00</committed-date>
  <authored-date>2009-02-21T06:26:47-08:00</authored-date>
  <message>Simplified relationship between LogDocument and LogParser.</message>
  <tree>b0e0f509f7764b6e163b0e433e031ab0969bfad1</tree>
  <committer>
    <name>Matt Mower</name>
    <email>self@mattmower.com</email>
  </committer>
</commit>
