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 void MaybeSetExternalFileURL(Profile* profile, | |
34 const base::FilePath& path, | |
35 GURL* url) { | |
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
37 | |
38 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.
| |
39 return; | |
40 | |
41 drive::FileSystemInterface* file_system = | |
42 drive::util::GetFileSystemByProfile(profile); | |
43 if (!file_system) | |
44 return; | |
45 | |
46 *url = FilePathToExternalFileURL(drive::util::ExtractDrivePath(path)); | |
47 } | |
48 | |
49 } // namespace chromeos | |
OLD | NEW |