Permalink
Browse files

[Network] Download tracking implemented

  • Loading branch information...
1 parent b9da9de commit 0f95d8d011d796fa6398e222f2ea29fc0d5a4b34 @cemaleker cemaleker committed Nov 4, 2010
@@ -54,6 +54,9 @@
NSInteger _totalBytesLoaded;
NSInteger _totalBytesExpected;
+
+ NSInteger _totalBytesDownloaded;
+ NSInteger _totalContentLength;
id _userInfo;
@@ -180,6 +183,16 @@
*/
@property (nonatomic) NSInteger totalBytesExpected;
+/**
+ * The number of downloaded bytes from server.
+ */
+@property (nonatomic) NSInteger totalBytesDownloaded;
+
+/**
+ * The number of content length of request.
+ */
+@property (nonatomic) NSInteger totalContentLength;
+
/**
* Whether or not the request was loaded from the cache.
*
@@ -294,12 +294,20 @@ - (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSHTTPURLRes
}
_responseData = [[NSMutableData alloc] initWithCapacity:contentLength];
+
+ for (TTURLRequest* request in [[_requests copy] autorelease]) {
+ request.totalContentLength = contentLength;
+ }
+
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {
[_responseData appendData:data];
+ for (TTURLRequest* request in [[_requests copy] autorelease]) {
+ request.totalBytesDownloaded += [data length];
+ }
}
@@ -55,6 +55,9 @@ @implementation TTURLRequest
@synthesize totalBytesLoaded = _totalBytesLoaded;
@synthesize totalBytesExpected = _totalBytesExpected;
+@synthesize totalBytesDownloaded = _totalBytesDownloaded;
+@synthesize totalContentLength = _totalContentLength;
+
@synthesize userInfo = _userInfo;
@synthesize isLoading = _isLoading;
@@ -321,7 +324,6 @@ - (BOOL)send {
return [[TTURLRequestQueue mainQueue] sendRequest:self];
}
-
///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)sendSynchronously {
return [[TTURLRequestQueue mainQueue] sendSynchronousRequest:self];

0 comments on commit 0f95d8d

Please sign in to comment.