/core/externals/update-engine/externals/gdata-objectivec-client/Source/HTTPFetcher/GTMHTTPFetcherService.h

http://macfuse.googlecode.com/ · C++ Header · 125 lines · 48 code · 20 blank · 57 comment · 0 complexity · b1739d82b7b69d59c918cd836c49ed09 MD5 · raw file

  1. /* Copyright (c) 2010 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. //
  16. // GTMHTTPFetcherService.h
  17. //
  18. // The fetcher service class maintains a history to be used by a sequence
  19. // of fetchers objects generated by the service.
  20. //
  21. // Fetchers that do not need to share a history may be generated independently,
  22. // like
  23. //
  24. // GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher fetcherWithRequest:request];
  25. //
  26. // Fetchers that should share cookies or an ETagged data cache should be
  27. // generated by a common GTMHTTPFetcherService instance, like
  28. //
  29. // GTMHTTPFetcherService *myFetcherService = [[GTMHTTPFetcherService alloc] init];
  30. // GTMHTTPFetcher* myFirstFetcher = [myFetcherService fetcherWithRequest:request1];
  31. // GTMHTTPFetcher* mySecondFetcher = [myFetcherService fetcherWithRequest:request2];
  32. #import "GTMHTTPFetcher.h"
  33. #import "GTMHTTPFetchHistory.h"
  34. @interface GTMHTTPFetcherService : NSObject<GTMHTTPFetcherServiceProtocol> {
  35. @private
  36. NSMutableDictionary *delayedHosts_;
  37. NSMutableDictionary *runningHosts_;
  38. NSUInteger maxRunningFetchersPerHost_;
  39. GTMHTTPFetchHistory *fetchHistory_;
  40. NSOperationQueue *delegateQueue_;
  41. NSArray *runLoopModes_;
  42. NSString *userAgent_;
  43. NSTimeInterval timeout_;
  44. NSURLCredential *credential_; // username & password
  45. NSURLCredential *proxyCredential_; // credential supplied to proxy servers
  46. NSInteger cookieStorageMethod_;
  47. BOOL shouldFetchInBackground_;
  48. id <GTMFetcherAuthorizationProtocol> authorizer_;
  49. }
  50. // Create a fetcher
  51. //
  52. // These methods will return an autoreleased fetcher, but if
  53. // the fetcher is successfully created, the connection will retain the
  54. // fetcher for the life of the connection as well. So the caller doesn't have
  55. // to retain the fetcher explicitly unless they want to be able to monitor
  56. // or cancel it.
  57. - (GTMHTTPFetcher *)fetcherWithRequest:(NSURLRequest *)request;
  58. - (GTMHTTPFetcher *)fetcherWithURL:(NSURL *)requestURL;
  59. - (GTMHTTPFetcher *)fetcherWithURLString:(NSString *)requestURLString;
  60. - (id)fetcherWithRequest:(NSURLRequest *)request
  61. fetcherClass:(Class)fetcherClass;
  62. // Queues of delayed and running fetchers. Each dictionary contains arrays
  63. // of fetchers, keyed by host
  64. //
  65. // A max value of 0 means no fetchers should be delayed.
  66. //
  67. // The default limit is 10 simultaneous fetchers targeting each host.
  68. @property (assign) NSUInteger maxRunningFetchersPerHost;
  69. @property (retain, readonly) NSDictionary *delayedHosts;
  70. @property (retain, readonly) NSDictionary *runningHosts;
  71. - (BOOL)isDelayingFetcher:(GTMHTTPFetcher *)fetcher;
  72. - (NSUInteger)numberOfFetchers; // running + delayed fetchers
  73. - (NSUInteger)numberOfRunningFetchers;
  74. - (NSUInteger)numberOfDelayedFetchers;
  75. // Search for running or delayed fetchers with the specified URL.
  76. //
  77. // Returns an array of fetcher objects found, or nil if none found.
  78. - (NSArray *)issuedFetchersWithRequestURL:(NSURL *)requestURL;
  79. - (void)stopAllFetchers;
  80. // Properties to be applied to each fetcher;
  81. // see GTMHTTPFetcher.h for descriptions
  82. @property (copy) NSString *userAgent;
  83. @property (assign) NSTimeInterval timeout;
  84. @property (retain) NSOperationQueue *delegateQueue;
  85. @property (retain) NSArray *runLoopModes;
  86. @property (retain) NSURLCredential *credential;
  87. @property (retain) NSURLCredential *proxyCredential;
  88. @property (assign) BOOL shouldFetchInBackground;
  89. // Fetch history
  90. @property (retain) GTMHTTPFetchHistory *fetchHistory;
  91. @property (assign) NSInteger cookieStorageMethod;
  92. @property (assign) BOOL shouldRememberETags; // default: NO
  93. @property (assign) BOOL shouldCacheETaggedData; // default: NO
  94. - (void)clearETaggedDataCache;
  95. - (void)clearHistory;
  96. @property (nonatomic, retain) id <GTMFetcherAuthorizationProtocol> authorizer;
  97. // Spin the run loop, discarding events, until all running and delayed fetchers
  98. // have completed
  99. //
  100. // This is only for use in testing or in tools without a user interface.
  101. //
  102. // Synchronous fetches should never be done by shipping apps; they are
  103. // sufficient reason for rejection from the app store.
  104. - (void)waitForCompletionOfAllFetchersWithTimeout:(NSTimeInterval)timeoutInSeconds;
  105. @end