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/drive/fileapi/fileapi_worker.h" | 5 #include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
11 #include "chrome/browser/chromeos/drive/drive.pb.h" | 11 #include "chrome/browser/chromeos/drive/drive.pb.h" |
12 #include "chrome/browser/chromeos/drive/file_errors.h" | 12 #include "chrome/browser/chromeos/drive/file_errors.h" |
13 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 13 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
14 #include "chrome/browser/chromeos/drive/file_system_util.h" | 14 #include "chrome/browser/chromeos/drive/file_system_util.h" |
15 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" | 15 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "webkit/browser/fileapi/file_system_url.h" | 17 #include "storage/browser/fileapi/file_system_url.h" |
18 #include "webkit/common/fileapi/directory_entry.h" | 18 #include "storage/common/fileapi/directory_entry.h" |
19 | 19 |
20 using content::BrowserThread; | 20 using content::BrowserThread; |
21 | 21 |
22 namespace drive { | 22 namespace drive { |
23 namespace fileapi_internal { | 23 namespace storage_internal { |
24 namespace { | 24 namespace { |
25 | 25 |
26 // The summary of opening mode is: | 26 // The summary of opening mode is: |
27 // - File::FLAG_OPEN: Open the existing file. Fail if not exists. | 27 // - File::FLAG_OPEN: Open the existing file. Fail if not exists. |
28 // - File::FLAG_CREATE: Create the file if not exists. Fail if exists. | 28 // - File::FLAG_CREATE: Create the file if not exists. Fail if exists. |
29 // - File::FLAG_OPEN_ALWAYS: Open the existing file. Create a new file | 29 // - File::FLAG_OPEN_ALWAYS: Open the existing file. Create a new file |
30 // if not exists. | 30 // if not exists. |
31 // - File::FLAG_CREATE_ALWAYS: Create a new file if not exists. If exists | 31 // - File::FLAG_CREATE_ALWAYS: Create a new file if not exists. If exists |
32 // open it with truncate. | 32 // open it with truncate. |
33 // - File::FLAG_OPEN_TRUNCATE: Open the existing file with truncate. | 33 // - File::FLAG_OPEN_TRUNCATE: Open the existing file with truncate. |
(...skipping 30 matching lines...) Expand all Loading... |
64 ConvertResourceEntryToFileInfo(*entry, &file_info); | 64 ConvertResourceEntryToFileInfo(*entry, &file_info); |
65 callback.Run(base::File::FILE_OK, file_info); | 65 callback.Run(base::File::FILE_OK, file_info); |
66 } | 66 } |
67 | 67 |
68 // Runs |callback| with entries. | 68 // Runs |callback| with entries. |
69 void RunReadDirectoryCallbackWithEntries( | 69 void RunReadDirectoryCallbackWithEntries( |
70 const ReadDirectoryCallback& callback, | 70 const ReadDirectoryCallback& callback, |
71 scoped_ptr<ResourceEntryVector> resource_entries) { | 71 scoped_ptr<ResourceEntryVector> resource_entries) { |
72 DCHECK(resource_entries); | 72 DCHECK(resource_entries); |
73 | 73 |
74 std::vector<fileapi::DirectoryEntry> entries; | 74 std::vector<storage::DirectoryEntry> entries; |
75 // Convert drive files to File API's directory entry. | 75 // Convert drive files to File API's directory entry. |
76 entries.reserve(resource_entries->size()); | 76 entries.reserve(resource_entries->size()); |
77 for (size_t i = 0; i < resource_entries->size(); ++i) { | 77 for (size_t i = 0; i < resource_entries->size(); ++i) { |
78 const ResourceEntry& resource_entry = (*resource_entries)[i]; | 78 const ResourceEntry& resource_entry = (*resource_entries)[i]; |
79 fileapi::DirectoryEntry entry; | 79 storage::DirectoryEntry entry; |
80 entry.name = resource_entry.base_name(); | 80 entry.name = resource_entry.base_name(); |
81 | 81 |
82 const PlatformFileInfoProto& file_info = resource_entry.file_info(); | 82 const PlatformFileInfoProto& file_info = resource_entry.file_info(); |
83 entry.is_directory = file_info.is_directory(); | 83 entry.is_directory = file_info.is_directory(); |
84 entry.size = file_info.size(); | 84 entry.size = file_info.size(); |
85 entry.last_modified_time = | 85 entry.last_modified_time = |
86 base::Time::FromInternalValue(file_info.last_modified()); | 86 base::Time::FromInternalValue(file_info.last_modified()); |
87 entries.push_back(entry); | 87 entries.push_back(entry); |
88 } | 88 } |
89 | 89 |
90 callback.Run(base::File::FILE_OK, entries, true /*has_more*/); | 90 callback.Run(base::File::FILE_OK, entries, true /*has_more*/); |
91 } | 91 } |
92 | 92 |
93 // Runs |callback| with |error|. | 93 // Runs |callback| with |error|. |
94 void RunReadDirectoryCallbackOnCompletion(const ReadDirectoryCallback& callback, | 94 void RunReadDirectoryCallbackOnCompletion(const ReadDirectoryCallback& callback, |
95 FileError error) { | 95 FileError error) { |
96 callback.Run(FileErrorToBaseFileError(error), | 96 callback.Run(FileErrorToBaseFileError(error), |
97 std::vector<fileapi::DirectoryEntry>(), false /*has_more*/); | 97 std::vector<storage::DirectoryEntry>(), |
| 98 false /*has_more*/); |
98 } | 99 } |
99 | 100 |
100 // Runs |callback| with arguments based on |error|, |local_path| and |entry|. | 101 // Runs |callback| with arguments based on |error|, |local_path| and |entry|. |
101 void RunCreateSnapshotFileCallback(const CreateSnapshotFileCallback& callback, | 102 void RunCreateSnapshotFileCallback(const CreateSnapshotFileCallback& callback, |
102 FileError error, | 103 FileError error, |
103 const base::FilePath& local_path, | 104 const base::FilePath& local_path, |
104 scoped_ptr<ResourceEntry> entry) { | 105 scoped_ptr<ResourceEntry> entry) { |
105 if (error != FILE_ERROR_OK) { | 106 if (error != FILE_ERROR_OK) { |
106 callback.Run( | 107 callback.Run(FileErrorToBaseFileError(error), |
107 FileErrorToBaseFileError(error), | 108 base::File::Info(), |
108 base::File::Info(), base::FilePath(), | 109 base::FilePath(), |
109 webkit_blob::ScopedFile::ScopeOutPolicy()); | 110 storage::ScopedFile::ScopeOutPolicy()); |
110 return; | 111 return; |
111 } | 112 } |
112 | 113 |
113 DCHECK(entry); | 114 DCHECK(entry); |
114 | 115 |
115 // When reading file, last modified time specified in file info will be | 116 // When reading file, last modified time specified in file info will be |
116 // compared to the last modified time of the local version of the drive file. | 117 // compared to the last modified time of the local version of the drive file. |
117 // Since those two values don't generally match (last modification time on the | 118 // Since those two values don't generally match (last modification time on the |
118 // drive server vs. last modification time of the local, downloaded file), so | 119 // drive server vs. last modification time of the local, downloaded file), so |
119 // we have to opt out from this check. We do this by unsetting last_modified | 120 // we have to opt out from this check. We do this by unsetting last_modified |
120 // value in the file info passed to the CreateSnapshot caller. | 121 // value in the file info passed to the CreateSnapshot caller. |
121 base::File::Info file_info; | 122 base::File::Info file_info; |
122 ConvertResourceEntryToFileInfo(*entry, &file_info); | 123 ConvertResourceEntryToFileInfo(*entry, &file_info); |
123 file_info.last_modified = base::Time(); | 124 file_info.last_modified = base::Time(); |
124 | 125 |
125 // If the file is a hosted document, a temporary JSON file is created to | 126 // If the file is a hosted document, a temporary JSON file is created to |
126 // represent the document. The JSON file is not cached and its lifetime | 127 // represent the document. The JSON file is not cached and its lifetime |
127 // is managed by ShareableFileReference. | 128 // is managed by ShareableFileReference. |
128 webkit_blob::ScopedFile::ScopeOutPolicy scope_out_policy = | 129 storage::ScopedFile::ScopeOutPolicy scope_out_policy = |
129 entry->file_specific_info().is_hosted_document() ? | 130 entry->file_specific_info().is_hosted_document() |
130 webkit_blob::ScopedFile::DELETE_ON_SCOPE_OUT : | 131 ? storage::ScopedFile::DELETE_ON_SCOPE_OUT |
131 webkit_blob::ScopedFile::DONT_DELETE_ON_SCOPE_OUT; | 132 : storage::ScopedFile::DONT_DELETE_ON_SCOPE_OUT; |
132 | 133 |
133 callback.Run(base::File::FILE_OK, file_info, local_path, scope_out_policy); | 134 callback.Run(base::File::FILE_OK, file_info, local_path, scope_out_policy); |
134 } | 135 } |
135 | 136 |
136 // Runs |callback| with arguments converted from |error| and |local_path|. | 137 // Runs |callback| with arguments converted from |error| and |local_path|. |
137 void RunCreateWritableSnapshotFileCallback( | 138 void RunCreateWritableSnapshotFileCallback( |
138 const CreateWritableSnapshotFileCallback& callback, | 139 const CreateWritableSnapshotFileCallback& callback, |
139 FileError error, | 140 FileError error, |
140 const base::FilePath& local_path, | 141 const base::FilePath& local_path, |
141 const base::Closure& close_callback) { | 142 const base::Closure& close_callback) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // Cache file prepared for modification is available. Open it locally. | 186 // Cache file prepared for modification is available. Open it locally. |
186 bool posted = base::PostTaskAndReplyWithResult( | 187 bool posted = base::PostTaskAndReplyWithResult( |
187 BrowserThread::GetBlockingPool(), FROM_HERE, | 188 BrowserThread::GetBlockingPool(), FROM_HERE, |
188 base::Bind(&OpenFile, local_path, file_flags), | 189 base::Bind(&OpenFile, local_path, file_flags), |
189 base::Bind(&RunOpenFileCallback, callback, close_callback)); | 190 base::Bind(&RunOpenFileCallback, callback, close_callback)); |
190 DCHECK(posted); | 191 DCHECK(posted); |
191 } | 192 } |
192 | 193 |
193 } // namespace | 194 } // namespace |
194 | 195 |
195 FileSystemInterface* GetFileSystemFromUrl(const fileapi::FileSystemURL& url) { | 196 FileSystemInterface* GetFileSystemFromUrl(const storage::FileSystemURL& url) { |
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
197 | 198 |
198 Profile* profile = util::ExtractProfileFromPath(url.path()); | 199 Profile* profile = util::ExtractProfileFromPath(url.path()); |
199 return profile ? util::GetFileSystemByProfile(profile) : NULL; | 200 return profile ? util::GetFileSystemByProfile(profile) : NULL; |
200 } | 201 } |
201 | 202 |
202 void RunFileSystemCallback( | 203 void RunFileSystemCallback( |
203 const FileSystemGetter& file_system_getter, | 204 const FileSystemGetter& file_system_getter, |
204 const base::Callback<void(FileSystemInterface*)>& callback, | 205 const base::Callback<void(FileSystemInterface*)>& callback, |
205 const base::Closure& on_error_callback) { | 206 const base::Closure& on_error_callback) { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 const base::Time& last_access_time, | 358 const base::Time& last_access_time, |
358 const base::Time& last_modified_time, | 359 const base::Time& last_modified_time, |
359 const StatusCallback& callback, | 360 const StatusCallback& callback, |
360 FileSystemInterface* file_system) { | 361 FileSystemInterface* file_system) { |
361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
362 file_system->TouchFile(file_path, last_access_time, last_modified_time, | 363 file_system->TouchFile(file_path, last_access_time, last_modified_time, |
363 base::Bind(&RunStatusCallbackByFileError, callback)); | 364 base::Bind(&RunStatusCallbackByFileError, callback)); |
364 | 365 |
365 } | 366 } |
366 | 367 |
367 } // namespace fileapi_internal | 368 } // namespace storage_internal |
368 } // namespace drive | 369 } // namespace drive |
OLD | NEW |