Index: chrome/browser/chromeos/fileapi/external_file_url_util.cc |
diff --git a/chrome/browser/chromeos/fileapi/external_file_url_util.cc b/chrome/browser/chromeos/fileapi/external_file_url_util.cc |
index add21ed504ce31252406ae134c2ca9ab11c86fa2..13199ca98cee350515fe4321e7c518b4e40a198e 100644 |
--- a/chrome/browser/chromeos/fileapi/external_file_url_util.cc |
+++ b/chrome/browser/chromeos/fileapi/external_file_url_util.cc |
@@ -5,27 +5,47 @@ |
#include "chrome/browser/chromeos/fileapi/external_file_url_util.h" |
#include <string> |
+#include <vector> |
+#include "base/strings/string_util.h" |
#include "base/strings/stringprintf.h" |
-#include "chrome/browser/chromeos/drive/file_system_util.h" |
+#include "chrome/browser/chromeos/file_manager/app_id.h" |
+#include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
+#include "chrome/browser/extensions/extension_util.h" |
+#include "chrome/browser/profiles/profile.h" |
#include "chrome/common/url_constants.h" |
+#include "content/public/browser/browser_context.h" |
#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/storage_partition.h" |
#include "net/base/escape.h" |
+#include "storage/browser/fileapi/file_system_url.h" |
using content::BrowserThread; |
namespace chromeos { |
-GURL FilePathToExternalFileURL(const base::FilePath& path) { |
- std::string url(base::StringPrintf( |
- "%s:%s", chrome::kExternalFileScheme, path.AsUTF8Unsafe().c_str())); |
- return GURL(url); |
+GURL FileSystemURLToExternalFileURL( |
+ const storage::FileSystemURL& file_system_url) { |
+ DCHECK(file_system_url.mount_type() == storage::kFileSystemTypeExternal); |
+ |
+ switch (file_system_url.type()) { |
+ case storage::kFileSystemTypeDrive: |
+ case storage::kFileSystemTypeDeviceMediaAsFileStorage: |
+ case storage::kFileSystemTypeProvided: |
+ return GURL(base::StringPrintf( |
+ "%s:%s", |
+ chrome::kExternalFileScheme, |
+ file_system_url.virtual_path().AsUTF8Unsafe().c_str())); |
+ |
+ default: |
+ return GURL(); |
+ } |
} |
-base::FilePath ExternalFileURLToFilePath(const GURL& url) { |
+base::FilePath ExternalFileURLToVirtualPath(const GURL& url) { |
if (!url.is_valid() || url.scheme() != chrome::kExternalFileScheme) |
return base::FilePath(); |
- std::string path_string = |
+ const std::string path_string = |
net::UnescapeURLComponent(url.GetContent(), net::UnescapeRule::NORMAL); |
return base::FilePath::FromUTF8Unsafe(path_string); |
} |
@@ -34,15 +54,23 @@ GURL CreateExternalFileURLFromPath(Profile* profile, |
const base::FilePath& path) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- if (!drive::util::IsUnderDriveMountPoint(path)) |
+ GURL raw_file_system_url; |
+ if (!file_manager::util::ConvertAbsoluteFilePathToFileSystemUrl( |
mtomasz
2014/09/25 09:53:11
Why do we return the file system url as GURL inste
hirono
2014/09/25 11:01:53
Not sure, but in other usages, FileSystemURL is no
mtomasz
2014/09/26 00:27:13
Ah got it. In general I think we should avoid crea
|
+ profile, |
+ path, |
+ file_manager::kFileManagerAppId, |
+ &raw_file_system_url)) { |
return GURL(); |
+ } |
- drive::FileSystemInterface* file_system = |
- drive::util::GetFileSystemByProfile(profile); |
- if (!file_system) |
- return GURL(); |
+ const GURL site = extensions::util::GetSiteForExtensionId( |
+ file_manager::kFileManagerAppId, profile); |
+ const storage::FileSystemURL file_system_url = |
+ content::BrowserContext::GetStoragePartitionForSite(profile, site) |
+ ->GetFileSystemContext() |
+ ->CrackURL(raw_file_system_url); |
- return FilePathToExternalFileURL(drive::util::ExtractDrivePath(path)); |
+ return FileSystemURLToExternalFileURL(file_system_url); |
} |
} // namespace chromeos |