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

Side by Side Diff: chrome/browser/chromeos/file_manager/filesystem_api_util.cc

Issue 603373002: Files.app: Always do fallback guessing mime type from file extensions when obtaining empty metadata… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" 5 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 17 matching lines...) Expand all
28 namespace { 28 namespace {
29 29
30 // Helper function used to implement GetNonNativeLocalPathMimeType. It extracts 30 // Helper function used to implement GetNonNativeLocalPathMimeType. It extracts
31 // the mime type from the passed Drive resource entry. 31 // the mime type from the passed Drive resource entry.
32 void GetMimeTypeAfterGetResourceEntryForDrive( 32 void GetMimeTypeAfterGetResourceEntryForDrive(
33 const base::Callback<void(bool, const std::string&)>& callback, 33 const base::Callback<void(bool, const std::string&)>& callback,
34 drive::FileError error, 34 drive::FileError error,
35 scoped_ptr<drive::ResourceEntry> entry) { 35 scoped_ptr<drive::ResourceEntry> entry) {
36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
37 37
38 if (error != drive::FILE_ERROR_OK || !entry->has_file_specific_info()) { 38 if (error != drive::FILE_ERROR_OK || !entry->has_file_specific_info() ||
39 entry->file_specific_info().content_mime_type().empty()) {
39 callback.Run(false, std::string()); 40 callback.Run(false, std::string());
40 return; 41 return;
41 } 42 }
42 callback.Run(true, entry->file_specific_info().content_mime_type()); 43 callback.Run(true, entry->file_specific_info().content_mime_type());
43 } 44 }
44 45
45 // Helper function used to implement GetNonNativeLocalPathMimeType. It extracts 46 // Helper function used to implement GetNonNativeLocalPathMimeType. It extracts
46 // the mime type from the passed metadata from a providing extension. 47 // the mime type from the passed metadata from a providing extension.
47 void GetMimeTypeAfterGetMetadataForProvidedFileSystem( 48 void GetMimeTypeAfterGetMetadataForProvidedFileSystem(
48 const base::Callback<void(bool, const std::string&)>& callback, 49 const base::Callback<void(bool, const std::string&)>& callback,
49 scoped_ptr<chromeos::file_system_provider::EntryMetadata> metadata, 50 scoped_ptr<chromeos::file_system_provider::EntryMetadata> metadata,
50 base::File::Error result) { 51 base::File::Error result) {
51 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 52 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
52 53
53 if (result != base::File::FILE_OK) { 54 if (result != base::File::FILE_OK || metadata->mime_type.empty()) {
54 callback.Run(false, std::string()); 55 callback.Run(false, std::string());
55 return; 56 return;
56 } 57 }
57 callback.Run(true, metadata->mime_type); 58 callback.Run(true, metadata->mime_type);
58 } 59 }
59 60
60 // Helper function to converts a callback that takes boolean value to that takes 61 // Helper function to converts a callback that takes boolean value to that takes
61 // File::Error, by regarding FILE_OK as the only successful value. 62 // File::Error, by regarding FILE_OK as the only successful value.
62 void BoolCallbackAsFileErrorCallback( 63 void BoolCallbackAsFileErrorCallback(
63 const base::Callback<void(bool)>& callback, 64 const base::Callback<void(bool)>& callback,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 171
171 parser.file_system()->GetMetadata( 172 parser.file_system()->GetMetadata(
172 parser.file_path(), 173 parser.file_path(),
173 chromeos::file_system_provider::ProvidedFileSystemInterface:: 174 chromeos::file_system_provider::ProvidedFileSystemInterface::
174 METADATA_FIELD_DEFAULT, 175 METADATA_FIELD_DEFAULT,
175 base::Bind(&GetMimeTypeAfterGetMetadataForProvidedFileSystem, 176 base::Bind(&GetMimeTypeAfterGetMetadataForProvidedFileSystem,
176 callback)); 177 callback));
177 return; 178 return;
178 } 179 }
179 180
180 // As a fallback just return success with an empty mime type value. 181 // We don't have a way to obtain metadata other than drive and FSP. Returns an
182 // error with empty MIME type, that leads fallback guessing mime type from
183 // file extensions.
181 content::BrowserThread::PostTask( 184 content::BrowserThread::PostTask(
182 content::BrowserThread::UI, 185 content::BrowserThread::UI,
183 FROM_HERE, 186 FROM_HERE,
184 base::Bind(callback, true /* success */, std::string())); 187 base::Bind(callback, false /* failure */, std::string()));
185 } 188 }
186 189
187 void IsNonNativeLocalPathDirectory( 190 void IsNonNativeLocalPathDirectory(
188 Profile* profile, 191 Profile* profile,
189 const base::FilePath& path, 192 const base::FilePath& path,
190 const base::Callback<void(bool)>& callback) { 193 const base::Callback<void(bool)>& callback) {
191 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 194 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
192 DCHECK(IsUnderNonNativeLocalPath(profile, path)); 195 DCHECK(IsUnderNonNativeLocalPath(profile, path));
193 196
194 GURL url; 197 GURL url;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 content::BrowserThread::IO, 241 content::BrowserThread::IO,
239 FROM_HERE, 242 FROM_HERE,
240 base::Bind(&PrepareFileOnIOThread, 243 base::Bind(&PrepareFileOnIOThread,
241 make_scoped_refptr(context), 244 make_scoped_refptr(context),
242 context->CrackURL(url), 245 context->CrackURL(url),
243 google_apis::CreateRelayCallback(callback))); 246 google_apis::CreateRelayCallback(callback)));
244 } 247 }
245 248
246 } // namespace util 249 } // namespace util
247 } // namespace file_manager 250 } // namespace file_manager
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698