|
|
Created:
7 years, 7 months ago by mrunal Modified:
7 years, 6 months ago CC:
chromium-reviews, darin-cc_chromium.org Base URL:
https://chromium.googlesource.com/chromium/src.git@filepath2 Visibility:
Public. |
DescriptionClean up ifdef around FilePath creation(webkit)
Splitting from the original patch here, crrev.com/14942008
to only include 'webkit' specific changes
BUG=102853
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=203002
Patch Set 1 #
Total comments: 6
Patch Set 2 : Clean up ifdef around FilePath creation(webkit) #
Total comments: 4
Patch Set 3 : Clean up ifdef around FilePath creation(webkit) #
Total comments: 1
Patch Set 4 : Clean up ifdef around FilePath creation(webkit) #
Messages
Total messages: 21 (0 generated)
Looks plausible, I'd like defer this to NPAPI owners.
https://codereview.chromium.org/14680012/diff/1/webkit/plugins/npapi/plugin_s... File webkit/plugins/npapi/plugin_stream.cc (right): https://codereview.chromium.org/14680012/diff/1/webkit/plugins/npapi/plugin_s... webkit/plugins/npapi/plugin_stream.cc:87: if (net::GetMimeTypeFromFile(path, &temp_mime_type)) I think MimeUtil::GetMimeTypeFromExtensionHelper() should also be updated, otherwise we have a SysWideToNativeMB conversion here on Windows that we don't undo.
https://codereview.chromium.org/14680012/diff/1/webkit/plugins/npapi/plugin_s... File webkit/plugins/npapi/plugin_stream.cc (right): https://codereview.chromium.org/14680012/diff/1/webkit/plugins/npapi/plugin_s... webkit/plugins/npapi/plugin_stream.cc:87: if (net::GetMimeTypeFromFile(path, &temp_mime_type)) I don't think it will call SysWideToNativeMB for Windows since there is a different version of FromUTF8Unsafe() (file_path.cc:line 622) for Windows which would get called here.
https://codereview.chromium.org/14680012/diff/1/webkit/plugins/npapi/plugin_s... File webkit/plugins/npapi/plugin_stream.cc (right): https://codereview.chromium.org/14680012/diff/1/webkit/plugins/npapi/plugin_s... webkit/plugins/npapi/plugin_stream.cc:87: if (net::GetMimeTypeFromFile(path, &temp_mime_type)) On 2013/05/17 00:16:00, mrunal wrote: > I don't think it will call SysWideToNativeMB for Windows since there is a > different version of FromUTF8Unsafe() (file_path.cc:line 622) for Windows which > would get called here. Oh, right! But what about Linux then? Basically, MimeUtil uses the same #ifdef that we have here, just with a FilePath::StringType instead of a FilePath (and in reverse), so if this is the right thing to do here and we want to get the same string back, we should also change that.
https://codereview.chromium.org/14680012/diff/1/webkit/plugins/npapi/plugin_s... File webkit/plugins/npapi/plugin_stream.cc (right): https://codereview.chromium.org/14680012/diff/1/webkit/plugins/npapi/plugin_s... webkit/plugins/npapi/plugin_stream.cc:87: if (net::GetMimeTypeFromFile(path, &temp_mime_type)) > Basically, MimeUtil uses the same #ifdef that we have here, just with a > FilePath::StringType instead of a FilePath (and in reverse), so if this is the > right thing to do here and we want to get the same string back, we should also > change that. Specifically what do you want me to change? Are you suggesting I change MimeUtil::GetMimeTypeFromExtensionHelper() by substituting WideToUTF8(SysNativeMBToWide(ext)) for OS_POSIX? I'm not sure if that's the right thing to do as not all the functions calling GetMimeTypeFromFile() are/will be calling FromUTF8Unsafe(). As per the bug description it sounded this change won't be any worse than the current #ifdef
https://codereview.chromium.org/14680012/diff/1/webkit/plugins/npapi/plugin_s... File webkit/plugins/npapi/plugin_stream.cc (right): https://codereview.chromium.org/14680012/diff/1/webkit/plugins/npapi/plugin_s... webkit/plugins/npapi/plugin_stream.cc:87: if (net::GetMimeTypeFromFile(path, &temp_mime_type)) On 2013/05/20 23:48:06, mrunal wrote: > > Basically, MimeUtil uses the same #ifdef that we have here, just with a > > FilePath::StringType instead of a FilePath (and in reverse), so if this is the > > right thing to do here and we want to get the same string back, we should also > > change that. > Specifically what do you want me to change? Are you suggesting I change > MimeUtil::GetMimeTypeFromExtensionHelper() by substituting > WideToUTF8(SysNativeMBToWide(ext)) for OS_POSIX? No, only for defined(OS_POSIX) && !(defined(OS_MACOSX) || defined(OS_CHROMEOS)), just like FilePath::AsUTF8Unsafe does. In fact, it might be the right thing to just use FilePath::AsUTF8Unsafe instead (as you can see, this is very subtle to get right). > I'm not sure if that's the right thing to do as not all the functions calling > GetMimeTypeFromFile() are/will be calling FromUTF8Unsafe(). Well, all the functions that construct a FilePath from a UTF8 string are (or at least they should be, and that's what you're changing here). > As per the bug > description it sounded this change won't be any worse than the current #ifdef Yes, that's why I'm asking you to make the change in more places. Basically, we're making the assumption that on Linux, file paths are in the native encoding. That assumption isn't always correct, but if we make it, we should make it everywhere in the code instead of just in some places. In particular, if we use the same reversible mapping from FilePath to UTF8 string everywhere, in places like here it doesn't make a difference whether our assumption that all file paths are native encoding is correct, because we'll get back the same string in any case!
https://codereview.chromium.org/14680012/diff/1/webkit/plugins/npapi/plugin_s... File webkit/plugins/npapi/plugin_stream.cc (right): https://codereview.chromium.org/14680012/diff/1/webkit/plugins/npapi/plugin_s... webkit/plugins/npapi/plugin_stream.cc:87: if (net::GetMimeTypeFromFile(path, &temp_mime_type)) Hi Bernhard, Thanks for the clarification. I will update the MimeUtil::GetMimeTypeFromExtensionHelper() with your suggested changes.
PTAL
https://codereview.chromium.org/14680012/diff/11001/net/base/mime_util.cc File net/base/mime_util.cc (right): https://codereview.chromium.org/14680012/diff/11001/net/base/mime_util.cc#new... net/base/mime_util.cc:228: const string& ext_narrow_str = WideToUTF8(base::SysNativeMBToWide(ext)); Why don't you just use FilePath::AsUTF8Unsafe? There is really no need to have this piece of logic in multiple places, particularly if it's as subtle as this.
https://codereview.chromium.org/14680012/diff/11001/net/base/mime_util.cc File net/base/mime_util.cc (right): https://codereview.chromium.org/14680012/diff/11001/net/base/mime_util.cc#new... net/base/mime_util.cc:228: const string& ext_narrow_str = WideToUTF8(base::SysNativeMBToWide(ext)); On 2013/05/28 21:26:14, Bernhard Bauer wrote: > Why don't you just use FilePath::AsUTF8Unsafe? Because FilePath::AsUTF8Unsafe() is not a static function like FromUTF8Unsafe(). It's a member function. We are dealing with base::FilePath::StringType here.
https://codereview.chromium.org/14680012/diff/11001/net/base/mime_util.cc File net/base/mime_util.cc (right): https://codereview.chromium.org/14680012/diff/11001/net/base/mime_util.cc#new... net/base/mime_util.cc:228: const string& ext_narrow_str = WideToUTF8(base::SysNativeMBToWide(ext)); On 2013/05/28 21:38:47, mrunal wrote: > On 2013/05/28 21:26:14, Bernhard Bauer wrote: > > Why don't you just use FilePath::AsUTF8Unsafe? > Because FilePath::AsUTF8Unsafe() is not a static function like FromUTF8Unsafe(). > It's a member function. We are dealing with base::FilePath::StringType here. Right, just construct a new FilePath (which copies the string), then call AsUTF8Unsafe(). Having to go through a FilePath object here is somewhat unfortunate, but then so is having to call an ...Unsafe() method in the first place.
https://codereview.chromium.org/14680012/diff/11001/net/base/mime_util.cc File net/base/mime_util.cc (right): https://codereview.chromium.org/14680012/diff/11001/net/base/mime_util.cc#new... net/base/mime_util.cc:228: const string& ext_narrow_str = WideToUTF8(base::SysNativeMBToWide(ext)); > Right, just construct a new FilePath (which copies the string), then call > AsUTF8Unsafe(). Having to go through a FilePath object here is somewhat > unfortunate, but then so is having to call an ...Unsafe() method in the first > place. Yeah that will be bit ugly but I get your point now. I will upload another patch.
PTAL
bauerb is in webkit/plugins/npapi/OWNERS, removing myself
https://codereview.chromium.org/14680012/diff/20001/net/base/mime_util.cc File net/base/mime_util.cc (right): https://codereview.chromium.org/14680012/diff/20001/net/base/mime_util.cc#new... net/base/mime_util.cc:223: const string& ext_narrow_str = path_ext.AsUTF8Unsafe(); You should not take a reference here! The returned value might be a temporary, in which case it will be destroyed right after this line, so the reference will become invalid.
> You should not take a reference here! The returned value might be a temporary, > in which case it will be destroyed right after this line, so the reference will > become invalid. Good catch! I have uploaded new patch.
LGTM!
LGTM for net
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/mrunal.kapade@intel.com/14680012/26001
Message was sent while issue was closed.
Change committed as 203002 |