diff options
author | kkhorimoto <kkhorimoto@chromium.org> | 2015-07-06 14:22:15 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-06 21:22:39 +0000 |
commit | d70e5c4bd55edf8c901b11b6f1e0aa8f1bacdde5 (patch) | |
tree | 2786a6a36889a7356b6d7700235dd6599fca9478 /base | |
parent | fe38fa2ac06375c45ca4fcb5dbbc0299b82fad77 (diff) | |
download | chromium_src-d70e5c4bd55edf8c901b11b6f1e0aa8f1bacdde5.zip chromium_src-d70e5c4bd55edf8c901b11b6f1e0aa8f1bacdde5.tar.gz chromium_src-d70e5c4bd55edf8c901b11b6f1e0aa8f1bacdde5.tar.bz2 |
Updated error translation logic.
This CL changes several aspects of our error translation code:
- Moves the actual translation process to |-loadErrorInNativeView:|.
This allows the logic in |-handleLoadError:inMainFrame:| to correctly
differentiate between webview-generated errors and errors originating
from the net stack.
- Changes |NetErrorFromError()| to translate the ultimate underlying
error rather than the top-level error, and appends the translated
error to the end of the passed-in error's underlying error chain.
- Created |GetUltimateUnderlyingErrorForError()|, which iterates through
the underlying error chain to find the original error.
BUG=492434, 496972, 496115, 473888
Review URL: https://codereview.chromium.org/1178063007
Cr-Commit-Position: refs/heads/master@{#337475}
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gypi | 2 | ||||
-rw-r--r-- | base/ios/ns_error_util.h | 25 | ||||
-rw-r--r-- | base/ios/ns_error_util.mm | 53 |
3 files changed, 80 insertions, 0 deletions
diff --git a/base/base.gypi b/base/base.gypi index 0f9196a..86815b6 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -246,6 +246,8 @@ 'ios/device_util.mm', 'ios/ios_util.h', 'ios/ios_util.mm', + 'ios/ns_error_util.h', + 'ios/ns_error_util.mm', 'ios/scoped_critical_action.h', 'ios/scoped_critical_action.mm', 'ios/weak_nsobject.h', diff --git a/base/ios/ns_error_util.h b/base/ios/ns_error_util.h new file mode 100644 index 0000000..1012292 --- /dev/null +++ b/base/ios/ns_error_util.h @@ -0,0 +1,25 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_IOS_NS_ERROR_UTIL_H_ +#define BASE_IOS_NS_ERROR_UTIL_H_ + +@class NSError; + +namespace base { +namespace ios { + +// Iterates through |error|'s underlying errors and returns the first error for +// which there is no underlying error. +NSError* GetFinalUnderlyingErrorFromError(NSError* error); + +// Returns a copy of |original_error| with |underlying_error| appended to the +// end of its underlying error chain. +NSError* ErrorWithAppendedUnderlyingError(NSError* original_error, + NSError* underlying_error); + +} // namespace ios +} // namespace base + +#endif // BASE_IOS_NS_ERROR_UTIL_H_ diff --git a/base/ios/ns_error_util.mm b/base/ios/ns_error_util.mm new file mode 100644 index 0000000..c44d9ee --- /dev/null +++ b/base/ios/ns_error_util.mm @@ -0,0 +1,53 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "base/ios/ns_error_util.h" + +#import <Foundation/Foundation.h> + +#include "base/logging.h" +#include "base/mac/scoped_nsobject.h" + +namespace base { +namespace ios { + +namespace { +// Iterates through |error|'s underlying errors and returns them in an array. +NSArray* GetFullErrorChainForError(NSError* error) { + NSMutableArray* error_chain = [NSMutableArray array]; + NSError* current_error = error; + while (current_error) { + DCHECK([current_error isKindOfClass:[NSError class]]); + [error_chain addObject:current_error]; + current_error = current_error.userInfo[NSUnderlyingErrorKey]; + } + return error_chain; +} +} // namespace + +NSError* GetFinalUnderlyingErrorFromError(NSError* error) { + DCHECK(error); + return [GetFullErrorChainForError(error) lastObject]; +} + +NSError* ErrorWithAppendedUnderlyingError(NSError* original_error, + NSError* underlying_error) { + DCHECK(original_error); + DCHECK(underlying_error); + NSArray* error_chain = GetFullErrorChainForError(original_error); + NSError* current_error = underlying_error; + for (NSInteger idx = error_chain.count - 1; idx >= 0; --idx) { + NSError* error = error_chain[idx]; + scoped_nsobject<NSMutableDictionary> user_info( + [error.userInfo mutableCopy]); + [user_info setObject:current_error forKey:NSUnderlyingErrorKey]; + current_error = [NSError errorWithDomain:error.domain + code:error.code + userInfo:user_info]; + } + return current_error; +} + +} // namespace ios +} // namespace base |