Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc

Issue 294163010: Refactor "IsUnderDriveMountPoint" in v2 app code for generalization to non-Drive volumes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/child_process_security_policy.h" 12 #include "content/public/browser/child_process_security_policy.h"
13 #include "content/public/browser/render_process_host.h" 13 #include "content/public/browser/render_process_host.h"
14 #include "extensions/browser/extension_prefs.h" 14 #include "extensions/browser/extension_prefs.h"
15 #include "net/base/mime_util.h" 15 #include "net/base/mime_util.h"
16 #include "webkit/browser/fileapi/isolated_context.h" 16 #include "webkit/browser/fileapi/isolated_context.h"
17 #include "webkit/common/fileapi/file_system_mount_option.h" 17 #include "webkit/common/fileapi/file_system_mount_option.h"
18 #include "webkit/common/fileapi/file_system_types.h" 18 #include "webkit/common/fileapi/file_system_types.h"
19 19
20 #if defined(OS_CHROMEOS) 20 #if defined(OS_CHROMEOS)
21 #include "chrome/browser/chromeos/drive/file_system_util.h" 21 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h"
22 #endif 22 #endif
23 23
24 using apps::file_handler_util::GrantedFileEntry; 24 using apps::file_handler_util::GrantedFileEntry;
25 25
26 namespace extensions { 26 namespace extensions {
27 27
28 namespace app_file_handler_util { 28 namespace app_file_handler_util {
29 29
30 const char kInvalidParameters[] = "Invalid parameters"; 30 const char kInvalidParameters[] = "Invalid parameters";
31 const char kSecurityError[] = "Security error"; 31 const char kSecurityError[] = "Security error";
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // calls the success or failure callback. 109 // calls the success or failure callback.
110 void TaskDone(); 110 void TaskDone();
111 111
112 // Reports an error in completing a work item. This may be called more than 112 // Reports an error in completing a work item. This may be called more than
113 // once, but only the last message will be retained. 113 // once, but only the last message will be retained.
114 void Error(const base::FilePath& error_path); 114 void Error(const base::FilePath& error_path);
115 115
116 void CheckLocalWritableFiles(); 116 void CheckLocalWritableFiles();
117 117
118 #if defined(OS_CHROMEOS) 118 #if defined(OS_CHROMEOS)
119 void CheckRemoteWritableFile(const base::FilePath& remote_path, 119 void NonNativeLocalPathCheckDone(const base::FilePath& path, bool success);
120 drive::FileError error,
121 const base::FilePath& local_path);
122 void RemoteCheckDone(const base::FilePath& remote_path,
123 drive::FileError error);
124 #endif 120 #endif
125 121
126 const std::vector<base::FilePath> paths_; 122 const std::vector<base::FilePath> paths_;
127 Profile* profile_; 123 Profile* profile_;
128 const bool is_directory_; 124 const bool is_directory_;
129 int outstanding_tasks_; 125 int outstanding_tasks_;
130 base::FilePath error_path_; 126 base::FilePath error_path_;
131 base::Closure on_success_; 127 base::Closure on_success_;
132 base::Callback<void(const base::FilePath&)> on_failure_; 128 base::Callback<void(const base::FilePath&)> on_failure_;
133 }; 129 };
134 130
135 WritableFileChecker::WritableFileChecker( 131 WritableFileChecker::WritableFileChecker(
136 const std::vector<base::FilePath>& paths, 132 const std::vector<base::FilePath>& paths,
137 Profile* profile, 133 Profile* profile,
138 bool is_directory, 134 bool is_directory,
139 const base::Closure& on_success, 135 const base::Closure& on_success,
140 const base::Callback<void(const base::FilePath&)>& on_failure) 136 const base::Callback<void(const base::FilePath&)>& on_failure)
141 : paths_(paths), 137 : paths_(paths),
142 profile_(profile), 138 profile_(profile),
143 is_directory_(is_directory), 139 is_directory_(is_directory),
144 outstanding_tasks_(1), 140 outstanding_tasks_(1),
145 on_success_(on_success), 141 on_success_(on_success),
146 on_failure_(on_failure) {} 142 on_failure_(on_failure) {}
147 143
148 void WritableFileChecker::Check() { 144 void WritableFileChecker::Check() {
149 #if defined(OS_CHROMEOS) 145 #if defined(OS_CHROMEOS)
150 if (drive::util::IsUnderDriveMountPoint(paths_[0])) { 146 if (file_manager::util::IsUnderNonNativeLocalPath(profile_, paths_[0])) {
151 outstanding_tasks_ = paths_.size(); 147 outstanding_tasks_ = paths_.size();
152 for (std::vector<base::FilePath>::const_iterator it = paths_.begin(); 148 for (std::vector<base::FilePath>::const_iterator it = paths_.begin();
153 it != paths_.end(); 149 it != paths_.end();
154 ++it) { 150 ++it) {
155 DCHECK(drive::util::IsUnderDriveMountPoint(*it));
156 if (is_directory_) { 151 if (is_directory_) {
157 drive::util::CheckDirectoryExists( 152 file_manager::util::IsNonNativeLocalPathDirectory(
158 profile_, 153 profile_,
159 *it, 154 *it,
160 base::Bind(&WritableFileChecker::RemoteCheckDone, this, *it)); 155 base::Bind(&WritableFileChecker::NonNativeLocalPathCheckDone,
156 this, *it));
161 } else { 157 } else {
162 drive::util::PrepareWritableFileAndRun( 158 file_manager::util::PrepareNonNativeLocalPathWritableFile(
163 profile_, 159 profile_,
164 *it, 160 *it,
165 base::Bind(&WritableFileChecker::CheckRemoteWritableFile, this, 161 base::Bind(&WritableFileChecker::NonNativeLocalPathCheckDone,
166 *it)); 162 this, *it));
167 } 163 }
168 } 164 }
169 return; 165 return;
170 } 166 }
171 #endif 167 #endif
172 content::BrowserThread::PostTask( 168 content::BrowserThread::PostTask(
173 content::BrowserThread::FILE, 169 content::BrowserThread::FILE,
174 FROM_HERE, 170 FROM_HERE,
175 base::Bind(&WritableFileChecker::CheckLocalWritableFiles, this)); 171 base::Bind(&WritableFileChecker::CheckLocalWritableFiles, this));
176 } 172 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 return; 205 return;
210 } 206 }
211 } 207 }
212 content::BrowserThread::PostTask( 208 content::BrowserThread::PostTask(
213 content::BrowserThread::UI, 209 content::BrowserThread::UI,
214 FROM_HERE, 210 FROM_HERE,
215 base::Bind(&WritableFileChecker::TaskDone, this)); 211 base::Bind(&WritableFileChecker::TaskDone, this));
216 } 212 }
217 213
218 #if defined(OS_CHROMEOS) 214 #if defined(OS_CHROMEOS)
219 void WritableFileChecker::CheckRemoteWritableFile( 215 void WritableFileChecker::NonNativeLocalPathCheckDone(
220 const base::FilePath& remote_path, 216 const base::FilePath& path,
221 drive::FileError error, 217 bool success) {
222 const base::FilePath& /* local_path */) { 218 if (success)
223 RemoteCheckDone(remote_path, error); 219 TaskDone();
224 } 220 else
225 221 Error(path);
226 void WritableFileChecker::RemoteCheckDone(
227 const base::FilePath& remote_path,
228 drive::FileError error) {
229 if (error == drive::FILE_ERROR_OK) {
230 content::BrowserThread::PostTask(
231 content::BrowserThread::UI,
232 FROM_HERE,
233 base::Bind(&WritableFileChecker::TaskDone, this));
234 } else {
235 content::BrowserThread::PostTask(
236 content::BrowserThread::UI,
237 FROM_HERE,
238 base::Bind(&WritableFileChecker::Error, this, remote_path));
239 }
240 } 222 }
241 #endif 223 #endif
242 224
243 } // namespace 225 } // namespace
244 226
245 const FileHandlerInfo* FileHandlerForId(const Extension& app, 227 const FileHandlerInfo* FileHandlerForId(const Extension& app,
246 const std::string& handler_id) { 228 const std::string& handler_id) {
247 const FileHandlersInfo* file_handlers = FileHandlers::GetFileHandlers(&app); 229 const FileHandlersInfo* file_handlers = FileHandlers::GetFileHandlers(&app);
248 if (!file_handlers) 230 if (!file_handlers)
249 return NULL; 231 return NULL;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 *error = kInvalidParameters; 383 *error = kInvalidParameters;
402 return false; 384 return false;
403 } 385 }
404 386
405 return true; 387 return true;
406 } 388 }
407 389
408 } // namespace app_file_handler_util 390 } // namespace app_file_handler_util
409 391
410 } // namespace extensions 392 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698