Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9ec10794c8add0f070f7eff12fb3aab631142d29 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/fileapi/external_file_url_util.cc |
| @@ -0,0 +1,49 @@ |
| +// Copyright 2014 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. |
| + |
| +#include "chrome/browser/chromeos/fileapi/external_file_url_util.h" |
| + |
| +#include <string> |
| + |
| +#include "base/strings/stringprintf.h" |
| +#include "chrome/browser/chromeos/drive/file_system_util.h" |
| +#include "chrome/common/url_constants.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "net/base/escape.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); |
| +} |
| + |
| +base::FilePath ExternalFileURLToFilePath(const GURL& url) { |
| + if (!url.is_valid() || url.scheme() != chrome::kExternalFileScheme) |
| + return base::FilePath(); |
| + std::string path_string = |
| + net::UnescapeURLComponent(url.GetContent(), net::UnescapeRule::NORMAL); |
| + return base::FilePath::FromUTF8Unsafe(path_string); |
| +} |
| + |
| +void MaybeSetExternalFileURL(Profile* profile, |
| + const base::FilePath& path, |
| + GURL* url) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + if (!drive::util::IsUnderDriveMountPoint(path)) |
|
mtomasz
2014/09/22 01:58:48
I'm wondering if we should have a dependency to dr
hirono
2014/09/22 03:32:19
I'll update the function at the next patch, but I'
mtomasz
2014/09/22 05:03:31
Got it.
|
| + return; |
| + |
| + drive::FileSystemInterface* file_system = |
| + drive::util::GetFileSystemByProfile(profile); |
| + if (!file_system) |
| + return; |
| + |
| + *url = FilePathToExternalFileURL(drive::util::ExtractDrivePath(path)); |
| +} |
| + |
| +} // namespace chromeos |