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 "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" | 5 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
6 | 6 |
7 #include "apps/browser/file_handler_util.h" | 7 #include "apps/browser/file_handler_util.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 bool DoCheckWritableFile(const base::FilePath& path, bool is_directory) { | 71 bool DoCheckWritableFile(const base::FilePath& path, bool is_directory) { |
72 // Don't allow links. | 72 // Don't allow links. |
73 if (base::PathExists(path) && base::IsLink(path)) | 73 if (base::PathExists(path) && base::IsLink(path)) |
74 return false; | 74 return false; |
75 | 75 |
76 if (is_directory) | 76 if (is_directory) |
77 return base::DirectoryExists(path); | 77 return base::DirectoryExists(path); |
78 | 78 |
79 // Create the file if it doesn't already exist. | 79 // Create the file if it doesn't already exist. |
80 int creation_flags = base::File::FLAG_CREATE | base::File::FLAG_READ | | 80 int creation_flags = base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ; |
81 base::File::FLAG_WRITE; | |
82 base::File file(path, creation_flags); | 81 base::File file(path, creation_flags); |
83 if (file.IsValid()) | 82 return file.IsValid(); |
84 return true; | |
85 return file.error_details() == base::File::FILE_ERROR_EXISTS; | |
86 } | 83 } |
87 | 84 |
88 // Checks whether a list of paths are all OK for writing and calls a provided | 85 // Checks whether a list of paths are all OK for writing and calls a provided |
89 // on_success or on_failure callback when done. A file is OK for writing if it | 86 // on_success or on_failure callback when done. A file is OK for writing if it |
90 // is not a symlink, is not in a blacklisted path and can be opened for writing; | 87 // is not a symlink, is not in a blacklisted path and can be opened for writing; |
91 // files are created if they do not exist. | 88 // files are created if they do not exist. |
92 class WritableFileChecker | 89 class WritableFileChecker |
93 : public base::RefCountedThreadSafe<WritableFileChecker> { | 90 : public base::RefCountedThreadSafe<WritableFileChecker> { |
94 public: | 91 public: |
95 WritableFileChecker( | 92 WritableFileChecker( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 for (std::vector<base::FilePath>::const_iterator it = paths_.begin(); | 145 for (std::vector<base::FilePath>::const_iterator it = paths_.begin(); |
149 it != paths_.end(); | 146 it != paths_.end(); |
150 ++it) { | 147 ++it) { |
151 if (is_directory_) { | 148 if (is_directory_) { |
152 file_manager::util::IsNonNativeLocalPathDirectory( | 149 file_manager::util::IsNonNativeLocalPathDirectory( |
153 profile_, | 150 profile_, |
154 *it, | 151 *it, |
155 base::Bind(&WritableFileChecker::NonNativeLocalPathCheckDone, | 152 base::Bind(&WritableFileChecker::NonNativeLocalPathCheckDone, |
156 this, *it)); | 153 this, *it)); |
157 } else { | 154 } else { |
158 file_manager::util::PrepareNonNativeLocalPathWritableFile( | 155 file_manager::util::PrepareNonNativeLocalFileForWritableApp( |
159 profile_, | 156 profile_, |
160 *it, | 157 *it, |
161 base::Bind(&WritableFileChecker::NonNativeLocalPathCheckDone, | 158 base::Bind(&WritableFileChecker::NonNativeLocalPathCheckDone, |
162 this, *it)); | 159 this, *it)); |
163 } | 160 } |
164 } | 161 } |
165 return; | 162 return; |
166 } | 163 } |
167 #endif | 164 #endif |
168 content::BrowserThread::PostTask( | 165 content::BrowserThread::PostTask( |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 } else { | 310 } else { |
314 policy->GrantWriteFileSystem(renderer_id, result.filesystem_id); | 311 policy->GrantWriteFileSystem(renderer_id, result.filesystem_id); |
315 policy->GrantDeleteFromFileSystem(renderer_id, result.filesystem_id); | 312 policy->GrantDeleteFromFileSystem(renderer_id, result.filesystem_id); |
316 } | 313 } |
317 } | 314 } |
318 | 315 |
319 result.id = result.filesystem_id + ":" + result.registered_name; | 316 result.id = result.filesystem_id + ":" + result.registered_name; |
320 return result; | 317 return result; |
321 } | 318 } |
322 | 319 |
323 void CheckWritableFiles( | 320 void PrepareFilesForWritableApp( |
324 const std::vector<base::FilePath>& paths, | 321 const std::vector<base::FilePath>& paths, |
325 Profile* profile, | 322 Profile* profile, |
326 bool is_directory, | 323 bool is_directory, |
327 const base::Closure& on_success, | 324 const base::Closure& on_success, |
328 const base::Callback<void(const base::FilePath&)>& on_failure) { | 325 const base::Callback<void(const base::FilePath&)>& on_failure) { |
329 scoped_refptr<WritableFileChecker> checker(new WritableFileChecker( | 326 scoped_refptr<WritableFileChecker> checker(new WritableFileChecker( |
330 paths, profile, is_directory, on_success, on_failure)); | 327 paths, profile, is_directory, on_success, on_failure)); |
331 checker->Check(); | 328 checker->Check(); |
332 } | 329 } |
333 | 330 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 *error = kInvalidParameters; | 380 *error = kInvalidParameters; |
384 return false; | 381 return false; |
385 } | 382 } |
386 | 383 |
387 return true; | 384 return true; |
388 } | 385 } |
389 | 386 |
390 } // namespace app_file_handler_util | 387 } // namespace app_file_handler_util |
391 | 388 |
392 } // namespace extensions | 389 } // namespace extensions |
OLD | NEW |