| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/web/web_state/crw_pass_kit_downloader.h" | 5 #import "ios/web/web_state/crw_pass_kit_downloader.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #import "base/ios/weak_nsobject.h" | |
| 10 #include "base/mac/scoped_block.h" | 9 #include "base/mac/scoped_block.h" |
| 11 #include "base/macros.h" | 10 #include "base/macros.h" |
| 12 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 14 #import "ios/web/crw_network_activity_indicator_manager.h" | 13 #import "ios/web/crw_network_activity_indicator_manager.h" |
| 15 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
| 16 #include "net/url_request/url_fetcher.h" | 15 #include "net/url_request/url_fetcher.h" |
| 17 #include "net/url_request/url_fetcher_delegate.h" | 16 #include "net/url_request/url_fetcher_delegate.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
| 19 | 18 |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 20 #error "This file requires ARC support." |
| 21 #endif |
| 22 |
| 20 using net::URLFetcher; | 23 using net::URLFetcher; |
| 21 using net::URLFetcherDelegate; | 24 using net::URLFetcherDelegate; |
| 22 using net::URLRequestContextGetter; | 25 using net::URLRequestContextGetter; |
| 23 | 26 |
| 24 namespace { | 27 namespace { |
| 25 | 28 |
| 26 // Key of the UMA Download.IOSDownloadPassKitResult histogram. | 29 // Key of the UMA Download.IOSDownloadPassKitResult histogram. |
| 27 const char kUMADownloadPassKitResult[] = "Download.IOSDownloadPassKitResult"; | 30 const char kUMADownloadPassKitResult[] = "Download.IOSDownloadPassKitResult"; |
| 28 | 31 |
| 29 // Enum for the Download.IOSDownloadPassKitResult UMA histogram to report the | 32 // Enum for the Download.IOSDownloadPassKitResult UMA histogram to report the |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // download is complete. | 71 // download is complete. |
| 69 class PassKitFetcherDelegate : public URLFetcherDelegate { | 72 class PassKitFetcherDelegate : public URLFetcherDelegate { |
| 70 public: | 73 public: |
| 71 explicit PassKitFetcherDelegate(CRWPassKitDownloader* owner) | 74 explicit PassKitFetcherDelegate(CRWPassKitDownloader* owner) |
| 72 : owner_(owner) {} | 75 : owner_(owner) {} |
| 73 void OnURLFetchComplete(const URLFetcher* source) override { | 76 void OnURLFetchComplete(const URLFetcher* source) override { |
| 74 [owner_ didFinishDownload]; | 77 [owner_ didFinishDownload]; |
| 75 } | 78 } |
| 76 | 79 |
| 77 private: | 80 private: |
| 78 base::WeakNSObject<CRWPassKitDownloader> owner_; | 81 __weak CRWPassKitDownloader* owner_; |
| 79 DISALLOW_COPY_AND_ASSIGN(PassKitFetcherDelegate); | 82 DISALLOW_COPY_AND_ASSIGN(PassKitFetcherDelegate); |
| 80 }; | 83 }; |
| 81 | 84 |
| 82 } // namespace | 85 } // namespace |
| 83 | 86 |
| 84 @implementation CRWPassKitDownloader { | 87 @implementation CRWPassKitDownloader { |
| 85 // Completion handler that is called when PassKit data is downloaded. | 88 // Completion handler that is called when PassKit data is downloaded. |
| 86 base::mac::ScopedBlock<web::PassKitCompletionHandler> _completionHandler; | 89 base::mac::ScopedBlock<web::PassKitCompletionHandler> _completionHandler; |
| 87 | 90 |
| 88 // URLFetcher with which PassKit data is downloaded. It is initialized | 91 // URLFetcher with which PassKit data is downloaded. It is initialized |
| (...skipping 28 matching lines...) Expand all Loading... |
| 117 } | 120 } |
| 118 | 121 |
| 119 - (instancetype)init { | 122 - (instancetype)init { |
| 120 NOTREACHED(); | 123 NOTREACHED(); |
| 121 return nil; | 124 return nil; |
| 122 } | 125 } |
| 123 | 126 |
| 124 - (void)dealloc { | 127 - (void)dealloc { |
| 125 [[CRWNetworkActivityIndicatorManager sharedInstance] | 128 [[CRWNetworkActivityIndicatorManager sharedInstance] |
| 126 clearNetworkTasksForGroup:[self networkActivityKey]]; | 129 clearNetworkTasksForGroup:[self networkActivityKey]]; |
| 127 [super dealloc]; | |
| 128 } | 130 } |
| 129 | 131 |
| 130 - (BOOL)isMIMETypePassKitType:(NSString*)MIMEType { | 132 - (BOOL)isMIMETypePassKitType:(NSString*)MIMEType { |
| 131 return [MIMEType isEqualToString:@"application/vnd.apple.pkpass"]; | 133 return [MIMEType isEqualToString:@"application/vnd.apple.pkpass"]; |
| 132 } | 134 } |
| 133 | 135 |
| 134 - (void)downloadPassKitFileWithURL:(const GURL&)URL { | 136 - (void)downloadPassKitFileWithURL:(const GURL&)URL { |
| 135 _fetcher = URLFetcher::Create(URL, URLFetcher::GET, _fetcherDelegate.get()); | 137 _fetcher = URLFetcher::Create(URL, URLFetcher::GET, _fetcherDelegate.get()); |
| 136 _fetcher->SetRequestContext(_requestContextGetter.get()); | 138 _fetcher->SetRequestContext(_requestContextGetter.get()); |
| 137 CRWNetworkActivityIndicatorManager* sharedManager = | 139 CRWNetworkActivityIndicatorManager* sharedManager = |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 stringWithFormat:@"PassKitDownloader.NetworkActivityIndicatorKey.%d", | 196 stringWithFormat:@"PassKitDownloader.NetworkActivityIndicatorKey.%d", |
| 195 _passKitDownloaderID]; | 197 _passKitDownloaderID]; |
| 196 } | 198 } |
| 197 | 199 |
| 198 - (void)reportUMAPassKitResult:(DownloadPassKitResult)result { | 200 - (void)reportUMAPassKitResult:(DownloadPassKitResult)result { |
| 199 UMA_HISTOGRAM_ENUMERATION(kUMADownloadPassKitResult, result, | 201 UMA_HISTOGRAM_ENUMERATION(kUMADownloadPassKitResult, result, |
| 200 DOWNLOAD_PASS_KIT_RESULT_COUNT); | 202 DOWNLOAD_PASS_KIT_RESULT_COUNT); |
| 201 } | 203 } |
| 202 | 204 |
| 203 @end | 205 @end |
| OLD | NEW |