OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/chromeos/file_system_provider/provided_file_system.h" | 5 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "chrome/browser/chromeos/file_system_provider/operations/close_file.h" | 8 #include "chrome/browser/chromeos/file_system_provider/operations/close_file.h" |
9 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h
" | 9 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h
" |
10 #include "chrome/browser/chromeos/file_system_provider/operations/open_file.h" | 10 #include "chrome/browser/chromeos/file_system_provider/operations/open_file.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 : event_router_(event_router), | 28 : event_router_(event_router), |
29 file_system_info_(file_system_info), | 29 file_system_info_(file_system_info), |
30 weak_ptr_factory_(this) { | 30 weak_ptr_factory_(this) { |
31 } | 31 } |
32 | 32 |
33 ProvidedFileSystem::~ProvidedFileSystem() {} | 33 ProvidedFileSystem::~ProvidedFileSystem() {} |
34 | 34 |
35 void ProvidedFileSystem::RequestUnmount( | 35 void ProvidedFileSystem::RequestUnmount( |
36 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 36 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
37 if (!request_manager_.CreateRequest( | 37 if (!request_manager_.CreateRequest( |
38 RequestManager::REQUEST_UNMOUNT, | 38 REQUEST_UNMOUNT, |
39 scoped_ptr<RequestManager::HandlerInterface>(new operations::Unmount( | 39 scoped_ptr<RequestManager::HandlerInterface>(new operations::Unmount( |
40 event_router_, file_system_info_, callback)))) { | 40 event_router_, file_system_info_, callback)))) { |
41 callback.Run(base::File::FILE_ERROR_SECURITY); | 41 callback.Run(base::File::FILE_ERROR_SECURITY); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 void ProvidedFileSystem::GetMetadata( | 45 void ProvidedFileSystem::GetMetadata( |
46 const base::FilePath& entry_path, | 46 const base::FilePath& entry_path, |
47 const fileapi::AsyncFileUtil::GetFileInfoCallback& callback) { | 47 const fileapi::AsyncFileUtil::GetFileInfoCallback& callback) { |
48 if (!request_manager_.CreateRequest( | 48 if (!request_manager_.CreateRequest( |
49 RequestManager::GET_METADATA, | 49 GET_METADATA, |
50 scoped_ptr<RequestManager::HandlerInterface>( | 50 scoped_ptr<RequestManager::HandlerInterface>( |
51 new operations::GetMetadata( | 51 new operations::GetMetadata( |
52 event_router_, file_system_info_, entry_path, callback)))) { | 52 event_router_, file_system_info_, entry_path, callback)))) { |
53 callback.Run(base::File::FILE_ERROR_SECURITY, base::File::Info()); | 53 callback.Run(base::File::FILE_ERROR_SECURITY, base::File::Info()); |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 void ProvidedFileSystem::ReadDirectory( | 57 void ProvidedFileSystem::ReadDirectory( |
58 const base::FilePath& directory_path, | 58 const base::FilePath& directory_path, |
59 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) { | 59 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) { |
60 if (!request_manager_.CreateRequest( | 60 if (!request_manager_.CreateRequest( |
61 RequestManager::READ_DIRECTORY, | 61 READ_DIRECTORY, |
62 scoped_ptr< | 62 scoped_ptr< |
63 RequestManager::HandlerInterface>(new operations::ReadDirectory( | 63 RequestManager::HandlerInterface>(new operations::ReadDirectory( |
64 event_router_, file_system_info_, directory_path, callback)))) { | 64 event_router_, file_system_info_, directory_path, callback)))) { |
65 callback.Run(base::File::FILE_ERROR_SECURITY, | 65 callback.Run(base::File::FILE_ERROR_SECURITY, |
66 fileapi::AsyncFileUtil::EntryList(), | 66 fileapi::AsyncFileUtil::EntryList(), |
67 false /* has_more */); | 67 false /* has_more */); |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 void ProvidedFileSystem::ReadFile(int file_handle, | 71 void ProvidedFileSystem::ReadFile(int file_handle, |
72 net::IOBuffer* buffer, | 72 net::IOBuffer* buffer, |
73 int64 offset, | 73 int64 offset, |
74 int length, | 74 int length, |
75 const ReadChunkReceivedCallback& callback) { | 75 const ReadChunkReceivedCallback& callback) { |
76 if (!request_manager_.CreateRequest( | 76 if (!request_manager_.CreateRequest( |
77 RequestManager::READ_FILE, | 77 READ_FILE, |
78 make_scoped_ptr<RequestManager::HandlerInterface>( | 78 make_scoped_ptr<RequestManager::HandlerInterface>( |
79 new operations::ReadFile(event_router_, | 79 new operations::ReadFile(event_router_, |
80 file_system_info_, | 80 file_system_info_, |
81 file_handle, | 81 file_handle, |
82 buffer, | 82 buffer, |
83 offset, | 83 offset, |
84 length, | 84 length, |
85 callback)))) { | 85 callback)))) { |
86 callback.Run(0 /* chunk_length */, | 86 callback.Run(0 /* chunk_length */, |
87 false /* has_more */, | 87 false /* has_more */, |
88 base::File::FILE_ERROR_SECURITY); | 88 base::File::FILE_ERROR_SECURITY); |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 void ProvidedFileSystem::OpenFile(const base::FilePath& file_path, | 92 void ProvidedFileSystem::OpenFile(const base::FilePath& file_path, |
93 OpenFileMode mode, | 93 OpenFileMode mode, |
94 bool create, | 94 bool create, |
95 const OpenFileCallback& callback) { | 95 const OpenFileCallback& callback) { |
96 // Writing is not supported. Note, that this includes a situation, when a file | 96 // Writing is not supported. Note, that this includes a situation, when a file |
97 // exists, but |create| is set to true. | 97 // exists, but |create| is set to true. |
98 if (mode == OPEN_FILE_MODE_WRITE || create) { | 98 if (mode == OPEN_FILE_MODE_WRITE || create) { |
99 callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY); | 99 callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY); |
100 return; | 100 return; |
101 } | 101 } |
102 | 102 |
103 if (!request_manager_.CreateRequest( | 103 if (!request_manager_.CreateRequest( |
104 RequestManager::OPEN_FILE, | 104 OPEN_FILE, |
105 scoped_ptr<RequestManager::HandlerInterface>( | 105 scoped_ptr<RequestManager::HandlerInterface>( |
106 new operations::OpenFile(event_router_, | 106 new operations::OpenFile(event_router_, |
107 file_system_info_, | 107 file_system_info_, |
108 file_path, | 108 file_path, |
109 mode, | 109 mode, |
110 create, | 110 create, |
111 callback)))) { | 111 callback)))) { |
112 callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY); | 112 callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 void ProvidedFileSystem::CloseFile( | 116 void ProvidedFileSystem::CloseFile( |
117 int file_handle, | 117 int file_handle, |
118 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 118 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
119 if (!request_manager_.CreateRequest( | 119 if (!request_manager_.CreateRequest( |
120 RequestManager::CLOSE_FILE, | 120 CLOSE_FILE, |
121 scoped_ptr<RequestManager::HandlerInterface>( | 121 scoped_ptr<RequestManager::HandlerInterface>( |
122 new operations::CloseFile( | 122 new operations::CloseFile( |
123 event_router_, file_system_info_, file_handle, callback)))) { | 123 event_router_, file_system_info_, file_handle, callback)))) { |
124 callback.Run(base::File::FILE_ERROR_SECURITY); | 124 callback.Run(base::File::FILE_ERROR_SECURITY); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 const ProvidedFileSystemInfo& ProvidedFileSystem::GetFileSystemInfo() const { | 128 const ProvidedFileSystemInfo& ProvidedFileSystem::GetFileSystemInfo() const { |
129 return file_system_info_; | 129 return file_system_info_; |
130 } | 130 } |
131 | 131 |
132 RequestManager* ProvidedFileSystem::GetRequestManager() { | 132 RequestManager* ProvidedFileSystem::GetRequestManager() { |
133 return &request_manager_; | 133 return &request_manager_; |
134 } | 134 } |
135 | 135 |
136 base::WeakPtr<ProvidedFileSystemInterface> ProvidedFileSystem::GetWeakPtr() { | 136 base::WeakPtr<ProvidedFileSystemInterface> ProvidedFileSystem::GetWeakPtr() { |
137 return weak_ptr_factory_.GetWeakPtr(); | 137 return weak_ptr_factory_.GetWeakPtr(); |
138 } | 138 } |
139 | 139 |
140 } // namespace file_system_provider | 140 } // namespace file_system_provider |
141 } // namespace chromeos | 141 } // namespace chromeos |
OLD | NEW |