Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(425)

Side by Side Diff: ios/web/web_state/error_translation_util.mm

Issue 1178063007: Updated error translation logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/error_translation_util.h" 5 #import "ios/web/web_state/error_translation_util.h"
6 6
7 #include <CFNetwork/CFNetwork.h> 7 #include <CFNetwork/CFNetwork.h>
8 8
9 #import "base/ios/ns_error_util.h"
9 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
10 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
11 12
12 namespace web { 13 namespace web {
13 14
14 namespace { 15 namespace {
15 // Translates an iOS error to a net error using |net_error_code| as an 16 // Translates an iOS error to a net error using |net_error_code| as an
16 // out-parameter. Returns true if a valid translation was found. 17 // out-parameter. Returns true if a valid translation was found.
17 bool GetNetErrorFromIOSErrorCode(NSInteger ios_error_code, 18 bool GetNetErrorFromIOSErrorCode(NSInteger ios_error_code,
18 NSInteger* net_error_code) { 19 NSInteger* net_error_code) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 break; 117 break;
117 default: 118 default:
118 translation_success = false; 119 translation_success = false;
119 break; 120 break;
120 } 121 }
121 return translation_success; 122 return translation_success;
122 } 123 }
123 } // namespace 124 } // namespace
124 125
125 NSError* NetErrorFromError(NSError* error) { 126 NSError* NetErrorFromError(NSError* error) {
126 NSError* underlying_error = error.userInfo[NSUnderlyingErrorKey]; 127 DCHECK(error);
127 NSString* net_error_domain = 128 NSError* underlying_error =
128 [NSString stringWithUTF8String:net::kErrorDomain]; 129 base::ios::GetFinalUnderlyingErrorFromError(error);
129 NSError* translated_error = error; 130 NSError* translated_error = error;
130 if (underlying_error) { 131 if ([underlying_error.domain isEqualToString:NSURLErrorDomain] ||
131 // If |error| already has an underlying error, it should be from the net 132 [underlying_error.domain
132 // stack and should already have the correct domain. 133 isEqualToString:static_cast<NSString*>(kCFErrorDomainCFNetwork)]) {
133 DCHECK([underlying_error.domain isEqualToString:net_error_domain]);
134 } else if ([error.domain isEqualToString:NSURLErrorDomain] ||
135 [error.domain isEqualToString:static_cast<NSString*>(
136 kCFErrorDomainCFNetwork)]) {
137 // Attempt to translate NSURL and CFNetwork error codes into their 134 // Attempt to translate NSURL and CFNetwork error codes into their
138 // corresponding net error codes. 135 // corresponding net error codes.
139 NSInteger net_error_code = net::OK; 136 NSInteger net_error_code = net::OK;
140 if (GetNetErrorFromIOSErrorCode(error.code, &net_error_code)) { 137 if (GetNetErrorFromIOSErrorCode(underlying_error.code, &net_error_code)) {
141 base::scoped_nsobject<NSMutableDictionary> user_info( 138 NSString* net_error_domain =
142 [error.userInfo mutableCopy]); 139 [NSString stringWithUTF8String:net::kErrorDomain];
143 [user_info setObject:[NSError errorWithDomain:net_error_domain 140 NSError* net_error = [NSError errorWithDomain:net_error_domain
144 code:net_error_code 141 code:net_error_code
145 userInfo:nil] 142 userInfo:nil];
146 forKey:NSUnderlyingErrorKey]; 143 translated_error =
147 translated_error = [NSError errorWithDomain:error.domain 144 base::ios::ErrorWithAppendedUnderlyingError(error, net_error);
148 code:error.code
149 userInfo:user_info];
150 } 145 }
151 } 146 }
152 return translated_error; 147 return translated_error;
153 } 148 }
154 } 149 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/web_state/error_translation_util.h ('k') | ios/web/web_state/ui/crw_ui_web_view_web_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698