commit fb27f36872b58b7d74ac693639072daeebfd120b
Author: Miltiadis Vasilakis <mvasilak@gmail.com>
Date:   Sat Jul 6 14:49:19 2013 +0300

    Refactor use of pithos objects to accommodate
    retry of failed service requests
    
    In browser and nodes, use the pithos object of the
    account manager, instead of maintaining a copy.

diff --git a/pithos-macos/PithosContainerNode.m b/pithos-macos/PithosContainerNode.m
index a96a7cd..0ed3a48 100644
--- a/pithos-macos/PithosContainerNode.m
+++ b/pithos-macos/PithosContainerNode.m
@@ -2,7 +2,7 @@
 //  PithosContainerNode.m
 //  pithos-macos
 //
-// Copyright 2011-2012 GRNET S.A. All rights reserved.
+// Copyright 2011-2013 GRNET S.A. All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or
 // without modification, are permitted provided that the following
@@ -44,13 +44,14 @@
 #import "ASIPithosObject.h"
 #import "ASIDownloadCache.h"
 #import "PithosUtilities.h"
+#import "PithosAccount.h"
 #import "PithosContainerNodeInfoController.h"
 #import "PithosActivityFacility.h"
 
 static NSImage *sharedIcon = nil;
 
 @implementation PithosContainerNode
-@synthesize pithos, pithosContainer, containerRequest, prefix, applyMetadataContainerRequest, refreshMetadataContainerRequest;
+@synthesize pithosContainer, containerRequest, prefix, applyMetadataContainerRequest, refreshMetadataContainerRequest;
 @synthesize policyVersioning, policyQuota;
 
 + (void)initialize {
@@ -61,31 +62,26 @@ static NSImage *sharedIcon = nil;
 #pragma mark -
 #pragma mark Object Lifecycle
 
-- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager
-                         andPithos:(ASIPithos *)aPithos pithosContainer:(ASIPithosContainer *)aPithosContainer icon:(NSImage *)anIcon {
+- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager pithosContainer:(ASIPithosContainer *)aPithosContainer icon:(NSImage *)anIcon {
     if ((self = [super initWithPithosAccountManager:aPithosAccountManager])) {
-        pithos = aPithos;
         self.pithosContainer = aPithosContainer;
         self.icon = anIcon;
     }
     return self;
 }
 
-- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager
-                         andPithos:(ASIPithos *)aPithos pithosContainer:(ASIPithosContainer *)aPithosContainer {
-    return [self initWithPithosAccountManager:aPithosAccountManager andPithos:aPithos pithosContainer:aPithosContainer icon:nil];
+- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager pithosContainer:(ASIPithosContainer *)aPithosContainer {
+    return [self initWithPithosAccountManager:aPithosAccountManager pithosContainer:aPithosContainer icon:nil];
 }
 
-- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager
-                         andPithos:(ASIPithos *)aPithos containerName:(NSString *)aContainerName icon:(NSImage *)anIcon {
+- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager containerName:(NSString *)aContainerName icon:(NSImage *)anIcon {
     ASIPithosContainer *container = [ASIPithosContainer container];
     container.name = aContainerName;
-    return [self initWithPithosAccountManager:aPithosAccountManager andPithos:aPithos pithosContainer:container icon:anIcon];
+    return [self initWithPithosAccountManager:aPithosAccountManager pithosContainer:container icon:anIcon];
 }
 
-- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager
-                         andPithos:(ASIPithos *)aPithos containerName:(NSString *)aContainerName {
-    return [self initWithPithosAccountManager:aPithosAccountManager andPithos:aPithos containerName:aContainerName icon:nil];
+- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager containerName:(NSString *)aContainerName {
+    return [self initWithPithosAccountManager:aPithosAccountManager containerName:aContainerName icon:nil];
 }
 
 - (void)dealloc {
@@ -97,20 +93,11 @@ static NSImage *sharedIcon = nil;
 #pragma mark -
 #pragma mark Properties
 
-- (void)setPithos:(ASIPithos *)aPithos {
-    if (aPithos && ![aPithos isEqualTo:pithos]) {
-        pithos = aPithos;
-        url = nil;
-    }
-}
-
 - (NSString *)url {
-    if (url == nil)
-        url = [[NSString alloc] initWithFormat:@"%@/%@%@", 
-               (sharingAccount ? [pithos storageURLWithAuthUser:sharingAccount] : pithos.storageURL), 
-               pithosContainer.name, 
-               (shared ? @"?shared" : @"")];
-    return url;
+    return [NSString stringWithFormat:@"@container@%@/%@%@",
+            (sharingAccount ? sharingAccount : pithosAccountManager.pithos.authUser),
+            pithosContainer.name,
+            (shared ? @"?shared" : @"")];
 }
 
 - (NSArray *)children {
@@ -120,7 +107,7 @@ static NSImage *sharedIcon = nil;
                 break;
             case PithosNodeStateRefreshNeeded:
                 freshness = PithosNodeStateRefreshing;
-                self.containerRequest = [ASIPithosContainerRequest listObjectsRequestWithPithos:pithos
+                self.containerRequest = [ASIPithosContainerRequest listObjectsRequestWithPithos:pithosAccountManager.pithos
                                                                                   containerName:pithosContainer.name
                                                                                           limit:0
                                                                                          marker:nil
@@ -131,7 +118,7 @@ static NSImage *sharedIcon = nil;
                                                                                          shared:shared
                                                                                           until:nil];
                 if (sharingAccount)
-                    [containerRequest setRequestUserFromDefaultTo:sharingAccount withPithos:pithos];
+                    [containerRequest setRequestUserFromDefaultTo:sharingAccount withPithos:pithosAccountManager.pithos];
                 else if (!forcedRefresh)
                     containerRequest.downloadCache = [ASIDownloadCache sharedCache];
                 containerRequest.delegate = self;
@@ -273,7 +260,6 @@ static NSImage *sharedIcon = nil;
                                 if ((sameNameObjectIndex == NSNotFound) || 
                                     ![PithosUtilities isContentTypeDirectory:[[objects objectAtIndex:sameNameObjectIndex] contentType]]) {
                                     PithosSubdirNode *node = [[PithosSubdirNode alloc] initWithPithosAccountManager:pithosAccountManager
-                                                                                                          andPithos:pithos
                                                                                                     pithosContainer:pithosContainer
                                                                                                        pithosObject:object];
                                     node.parent = self;
@@ -297,7 +283,6 @@ static NSImage *sharedIcon = nil;
                                 }
                             } else if ([PithosUtilities isContentTypeDirectory:object.contentType]) {
                                 PithosSubdirNode *node = [[PithosSubdirNode alloc] initWithPithosAccountManager:pithosAccountManager
-                                                                                                      andPithos:pithos
                                                                                                 pithosContainer:pithosContainer
                                                                                                    pithosObject:object];
                                 node.parent = self;
@@ -318,7 +303,6 @@ static NSImage *sharedIcon = nil;
                                 [newChildren addObject:node];
                             } else {
                                 PithosObjectNode *node = [[PithosObjectNode alloc] initWithPithosAccountManager:pithosAccountManager
-                                                                                                      andPithos:pithos
                                                                                                 pithosContainer:pithosContainer
                                                                                                    pithosObject:object];
                                 node.parent = self;
@@ -356,7 +340,7 @@ static NSImage *sharedIcon = nil;
                 [self postChildrenUpdatedNotificationName];
             } else {
                 // Do an additional request to fetch more objects
-                self.containerRequest = [ASIPithosContainerRequest listObjectsRequestWithPithos:pithos
+                self.containerRequest = [ASIPithosContainerRequest listObjectsRequestWithPithos:pithosAccountManager.pithos
                                                                                   containerName:pithosContainer.name
                                                                                           limit:0
                                                                                          marker:[[someObjects lastObject] name]
@@ -367,7 +351,7 @@ static NSImage *sharedIcon = nil;
                                                                                          shared:shared
                                                                                           until:nil];
                 if (sharingAccount)
-                    [containerRequest setRequestUserFromDefaultTo:sharingAccount withPithos:pithos];
+                    [containerRequest setRequestUserFromDefaultTo:sharingAccount withPithos:pithosAccountManager.pithos];
                 else if (!forcedRefresh)
                     containerRequest.downloadCache = [ASIDownloadCache sharedCache];
                 containerRequest.delegate = self;
@@ -455,7 +439,7 @@ static NSImage *sharedIcon = nil;
     @synchronized(self) {
         if (applyMetadataContainerRequest == nil) {
             [[pithosNodeInfoController window] makeFirstResponder:nil];
-            self.applyMetadataContainerRequest = [ASIPithosContainerRequest updateContainerMetadataRequestWithPithos:pithos
+            self.applyMetadataContainerRequest = [ASIPithosContainerRequest updateContainerMetadataRequestWithPithos:pithosAccountManager.pithos
                                                                                                        containerName:pithosContainer.name
                                                                                                               policy:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                                                                       policyVersioning, @"versioning",
@@ -480,7 +464,7 @@ static NSImage *sharedIcon = nil;
 - (void)refreshInfo {
     @synchronized(self) {
         if (refreshMetadataContainerRequest == nil) {
-            self.refreshMetadataContainerRequest = [ASIPithosContainerRequest containerMetadataRequestWithPithos:pithos
+            self.refreshMetadataContainerRequest = [ASIPithosContainerRequest containerMetadataRequestWithPithos:pithosAccountManager.pithos
                                                                                                    containerName:pithosContainer.name];
             refreshMetadataContainerRequest.delegate = self;
             refreshMetadataContainerRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:);
