OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/fileapi/external_file_url_util.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 11 #include "chrome/common/url_constants.h" |
| 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "net/base/escape.h" |
| 14 |
| 15 using content::BrowserThread; |
| 16 |
| 17 namespace chromeos { |
| 18 |
| 19 GURL FilePathToExternalFileURL(const base::FilePath& path) { |
| 20 std::string url(base::StringPrintf( |
| 21 "%s:%s", chrome::kExternalFileScheme, path.AsUTF8Unsafe().c_str())); |
| 22 return GURL(url); |
| 23 } |
| 24 |
| 25 base::FilePath ExternalFileURLToFilePath(const GURL& url) { |
| 26 if (!url.is_valid() || url.scheme() != chrome::kExternalFileScheme) |
| 27 return base::FilePath(); |
| 28 std::string path_string = |
| 29 net::UnescapeURLComponent(url.GetContent(), net::UnescapeRule::NORMAL); |
| 30 return base::FilePath::FromUTF8Unsafe(path_string); |
| 31 } |
| 32 |
| 33 GURL CreateExternalFileURLFromPath(Profile* profile, |
| 34 const base::FilePath& path) { |
| 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 36 |
| 37 if (!drive::util::IsUnderDriveMountPoint(path)) |
| 38 return GURL(); |
| 39 |
| 40 drive::FileSystemInterface* file_system = |
| 41 drive::util::GetFileSystemByProfile(profile); |
| 42 if (!file_system) |
| 43 return GURL(); |
| 44 |
| 45 return FilePathToExternalFileURL(drive::util::ExtractDrivePath(path)); |
| 46 } |
| 47 |
| 48 } // namespace chromeos |
OLD | NEW |