OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/chromeos/fileapi/cros_mount_point_provider.h" | 5 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" |
6 | 6 |
7 #include "base/chromeos/chromeos_version.h" | 7 #include "base/chromeos/chromeos_version.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/path_service.h" |
11 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
12 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste
m.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste
m.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
18 #include "webkit/chromeos/fileapi/file_access_permissions.h" | 19 #include "webkit/chromeos/fileapi/file_access_permissions.h" |
19 #include "webkit/chromeos/fileapi/remote_file_stream_writer.h" | 20 #include "webkit/chromeos/fileapi/remote_file_stream_writer.h" |
20 #include "webkit/chromeos/fileapi/remote_file_system_operation.h" | 21 #include "webkit/chromeos/fileapi/remote_file_system_operation.h" |
21 #include "webkit/fileapi/file_system_file_stream_reader.h" | 22 #include "webkit/fileapi/file_system_file_stream_reader.h" |
22 #include "webkit/fileapi/file_system_operation_context.h" | 23 #include "webkit/fileapi/file_system_operation_context.h" |
23 #include "webkit/fileapi/file_system_url.h" | 24 #include "webkit/fileapi/file_system_url.h" |
24 #include "webkit/fileapi/file_system_util.h" | 25 #include "webkit/fileapi/file_system_util.h" |
25 #include "webkit/fileapi/local_file_stream_writer.h" | 26 #include "webkit/fileapi/local_file_stream_writer.h" |
26 #include "webkit/fileapi/local_file_system_operation.h" | 27 #include "webkit/fileapi/local_file_system_operation.h" |
27 #include "webkit/glue/webkit_glue.h" | 28 #include "webkit/glue/webkit_glue.h" |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 const char kChromeUIScheme[] = "chrome"; | 32 const char kChromeUIScheme[] = "chrome"; |
32 | 33 |
33 // Returns the home directory path, or an empty string if the home directory | |
34 // is not found. | |
35 std::string GetHomeDirectory() { | |
36 if (base::chromeos::IsRunningOnChromeOS()) | |
37 return "/home/chronos/user"; | |
38 | |
39 const char* home = getenv("HOME"); | |
40 if (home) | |
41 return home; | |
42 return ""; | |
43 } | |
44 | |
45 } // namespace | 34 } // namespace |
46 | 35 |
47 namespace chromeos { | 36 namespace chromeos { |
48 | 37 |
49 CrosMountPointProvider::MountPoint::MountPoint( | 38 CrosMountPointProvider::MountPoint::MountPoint( |
50 const FilePath& in_web_root_path, | 39 const FilePath& in_web_root_path, |
51 const FilePath& in_local_root_path, | 40 const FilePath& in_local_root_path, |
52 FileSystemLocation in_location, | 41 FileSystemLocation in_location, |
53 fileapi::RemoteFileSystemProxyInterface* in_proxy) | 42 fileapi::RemoteFileSystemProxyInterface* in_proxy) |
54 : web_root_path(in_web_root_path), local_root_path(in_local_root_path), | 43 : web_root_path(in_web_root_path), local_root_path(in_local_root_path), |
55 location(in_location), remote_proxy(in_proxy) { | 44 location(in_location), remote_proxy(in_proxy) { |
56 } | 45 } |
57 | 46 |
58 CrosMountPointProvider::MountPoint::~MountPoint() { | 47 CrosMountPointProvider::MountPoint::~MountPoint() { |
59 } | 48 } |
60 | 49 |
61 CrosMountPointProvider::CrosMountPointProvider( | 50 CrosMountPointProvider::CrosMountPointProvider( |
62 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) | 51 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) |
63 : special_storage_policy_(special_storage_policy), | 52 : special_storage_policy_(special_storage_policy), |
64 file_access_permissions_(new FileAccessPermissions()), | 53 file_access_permissions_(new FileAccessPermissions()), |
65 local_file_util_(new fileapi::LocalFileUtil()) { | 54 local_file_util_(new fileapi::LocalFileUtil()) { |
66 const std::string home = GetHomeDirectory(); | 55 FilePath home_path; |
67 if (!home.empty()) { | 56 if (PathService::Get(base::DIR_HOME, &home_path)) |
68 AddLocalMountPoint( | 57 AddLocalMountPoint(home_path.AppendASCII("Downloads")); |
69 FilePath::FromUTF8Unsafe(home).AppendASCII("Downloads")); | |
70 } | |
71 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/archive"))); | 58 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/archive"))); |
72 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/removable"))); | 59 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/removable"))); |
73 } | 60 } |
74 | 61 |
75 CrosMountPointProvider::~CrosMountPointProvider() { | 62 CrosMountPointProvider::~CrosMountPointProvider() { |
76 } | 63 } |
77 | 64 |
78 bool CrosMountPointProvider::GetRootForVirtualPath( | 65 bool CrosMountPointProvider::GetRootForVirtualPath( |
79 const FilePath& virtual_path, FilePath* root_path) { | 66 const FilePath& virtual_path, FilePath* root_path) { |
80 const MountPoint* mount_point = GetMountPoint(virtual_path); | 67 const MountPoint* mount_point = GetMountPoint(virtual_path); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 if (mount_prefix == filesystem_path) { | 295 if (mount_prefix == filesystem_path) { |
309 return true; | 296 return true; |
310 } else if (mount_prefix.AppendRelativePath(filesystem_path, virtual_path)) { | 297 } else if (mount_prefix.AppendRelativePath(filesystem_path, virtual_path)) { |
311 return true; | 298 return true; |
312 } | 299 } |
313 } | 300 } |
314 return false; | 301 return false; |
315 } | 302 } |
316 | 303 |
317 } // namespace chromeos | 304 } // namespace chromeos |
OLD | NEW |