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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc

Issue 1036723003: favor DCHECK_CURRENTLY_ON for better logs in chrome/browser/chromeos/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extensions/file_manager/private_api_file_syste m.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_file_syste m.h"
6 6
7 #include <sys/statvfs.h> 7 #include <sys/statvfs.h>
8 #include <set> 8 #include <set>
9 9
10 #include "base/posix/eintr_wrapper.h" 10 #include "base/posix/eintr_wrapper.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // The filesystem seems not supporting statvfs(). Assume it to be a commonly 78 // The filesystem seems not supporting statvfs(). Assume it to be a commonly
79 // used bound 255, and log the failure. 79 // used bound 255, and log the failure.
80 LOG(ERROR) << "Cannot statvfs() the name length limit for: " << path; 80 LOG(ERROR) << "Cannot statvfs() the name length limit for: " << path;
81 return 255; 81 return 255;
82 } 82 }
83 return stat.f_namemax; 83 return stat.f_namemax;
84 } 84 }
85 85
86 // Returns EventRouter for the |profile_id| if available. 86 // Returns EventRouter for the |profile_id| if available.
87 file_manager::EventRouter* GetEventRouterByProfileId(void* profile_id) { 87 file_manager::EventRouter* GetEventRouterByProfileId(void* profile_id) {
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 88 DCHECK_CURRENTLY_ON(BrowserThread::UI);
89 89
90 // |profile_id| needs to be checked with ProfileManager::IsValidProfile 90 // |profile_id| needs to be checked with ProfileManager::IsValidProfile
91 // before using it. 91 // before using it.
92 Profile* profile = reinterpret_cast<Profile*>(profile_id); 92 Profile* profile = reinterpret_cast<Profile*>(profile_id);
93 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) 93 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
94 return NULL; 94 return NULL;
95 95
96 return file_manager::EventRouterFactory::GetForProfile(profile); 96 return file_manager::EventRouterFactory::GetForProfile(profile);
97 } 97 }
98 98
99 // Notifies the copy progress to extensions via event router. 99 // Notifies the copy progress to extensions via event router.
100 void NotifyCopyProgress( 100 void NotifyCopyProgress(
101 void* profile_id, 101 void* profile_id,
102 storage::FileSystemOperationRunner::OperationID operation_id, 102 storage::FileSystemOperationRunner::OperationID operation_id,
103 storage::FileSystemOperation::CopyProgressType type, 103 storage::FileSystemOperation::CopyProgressType type,
104 const FileSystemURL& source_url, 104 const FileSystemURL& source_url,
105 const FileSystemURL& destination_url, 105 const FileSystemURL& destination_url,
106 int64 size) { 106 int64 size) {
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 107 DCHECK_CURRENTLY_ON(BrowserThread::UI);
108 108
109 file_manager::EventRouter* event_router = 109 file_manager::EventRouter* event_router =
110 GetEventRouterByProfileId(profile_id); 110 GetEventRouterByProfileId(profile_id);
111 if (event_router) { 111 if (event_router) {
112 event_router->OnCopyProgress( 112 event_router->OnCopyProgress(
113 operation_id, type, 113 operation_id, type,
114 source_url.ToGURL(), destination_url.ToGURL(), size); 114 source_url.ToGURL(), destination_url.ToGURL(), size);
115 } 115 }
116 } 116 }
117 117
118 // Callback invoked periodically on progress update of Copy(). 118 // Callback invoked periodically on progress update of Copy().
119 void OnCopyProgress( 119 void OnCopyProgress(
120 void* profile_id, 120 void* profile_id,
121 storage::FileSystemOperationRunner::OperationID* operation_id, 121 storage::FileSystemOperationRunner::OperationID* operation_id,
122 storage::FileSystemOperation::CopyProgressType type, 122 storage::FileSystemOperation::CopyProgressType type,
123 const FileSystemURL& source_url, 123 const FileSystemURL& source_url,
124 const FileSystemURL& destination_url, 124 const FileSystemURL& destination_url,
125 int64 size) { 125 int64 size) {
126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 126 DCHECK_CURRENTLY_ON(BrowserThread::IO);
127 127
128 BrowserThread::PostTask( 128 BrowserThread::PostTask(
129 BrowserThread::UI, FROM_HERE, 129 BrowserThread::UI, FROM_HERE,
130 base::Bind(&NotifyCopyProgress, 130 base::Bind(&NotifyCopyProgress,
131 profile_id, *operation_id, type, 131 profile_id, *operation_id, type,
132 source_url, destination_url, size)); 132 source_url, destination_url, size));
133 } 133 }
134 134
135 // Notifies the copy completion to extensions via event router. 135 // Notifies the copy completion to extensions via event router.
136 void NotifyCopyCompletion( 136 void NotifyCopyCompletion(
137 void* profile_id, 137 void* profile_id,
138 storage::FileSystemOperationRunner::OperationID operation_id, 138 storage::FileSystemOperationRunner::OperationID operation_id,
139 const FileSystemURL& source_url, 139 const FileSystemURL& source_url,
140 const FileSystemURL& destination_url, 140 const FileSystemURL& destination_url,
141 base::File::Error error) { 141 base::File::Error error) {
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 142 DCHECK_CURRENTLY_ON(BrowserThread::UI);
143 143
144 file_manager::EventRouter* event_router = 144 file_manager::EventRouter* event_router =
145 GetEventRouterByProfileId(profile_id); 145 GetEventRouterByProfileId(profile_id);
146 if (event_router) 146 if (event_router)
147 event_router->OnCopyCompleted( 147 event_router->OnCopyCompleted(
148 operation_id, 148 operation_id,
149 source_url.ToGURL(), destination_url.ToGURL(), error); 149 source_url.ToGURL(), destination_url.ToGURL(), error);
150 } 150 }
151 151
152 // Callback invoked upon completion of Copy() (regardless of succeeded or 152 // Callback invoked upon completion of Copy() (regardless of succeeded or
153 // failed). 153 // failed).
154 void OnCopyCompleted( 154 void OnCopyCompleted(
155 void* profile_id, 155 void* profile_id,
156 storage::FileSystemOperationRunner::OperationID* operation_id, 156 storage::FileSystemOperationRunner::OperationID* operation_id,
157 const FileSystemURL& source_url, 157 const FileSystemURL& source_url,
158 const FileSystemURL& destination_url, 158 const FileSystemURL& destination_url,
159 base::File::Error error) { 159 base::File::Error error) {
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 160 DCHECK_CURRENTLY_ON(BrowserThread::IO);
161 161
162 BrowserThread::PostTask( 162 BrowserThread::PostTask(
163 BrowserThread::UI, FROM_HERE, 163 BrowserThread::UI, FROM_HERE,
164 base::Bind(&NotifyCopyCompletion, 164 base::Bind(&NotifyCopyCompletion,
165 profile_id, *operation_id, 165 profile_id, *operation_id,
166 source_url, destination_url, error)); 166 source_url, destination_url, error));
167 } 167 }
168 168
169 // Starts the copy operation via FileSystemOperationRunner. 169 // Starts the copy operation via FileSystemOperationRunner.
170 storage::FileSystemOperationRunner::OperationID StartCopyOnIOThread( 170 storage::FileSystemOperationRunner::OperationID StartCopyOnIOThread(
171 void* profile_id, 171 void* profile_id,
172 scoped_refptr<storage::FileSystemContext> file_system_context, 172 scoped_refptr<storage::FileSystemContext> file_system_context,
173 const FileSystemURL& source_url, 173 const FileSystemURL& source_url,
174 const FileSystemURL& destination_url) { 174 const FileSystemURL& destination_url) {
175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 175 DCHECK_CURRENTLY_ON(BrowserThread::IO);
176 176
177 // Note: |operation_id| is owned by the callback for 177 // Note: |operation_id| is owned by the callback for
178 // FileSystemOperationRunner::Copy(). It is always called in the next message 178 // FileSystemOperationRunner::Copy(). It is always called in the next message
179 // loop or later, so at least during this invocation it should alive. 179 // loop or later, so at least during this invocation it should alive.
180 storage::FileSystemOperationRunner::OperationID* operation_id = 180 storage::FileSystemOperationRunner::OperationID* operation_id =
181 new storage::FileSystemOperationRunner::OperationID; 181 new storage::FileSystemOperationRunner::OperationID;
182 *operation_id = file_system_context->operation_runner()->Copy( 182 *operation_id = file_system_context->operation_runner()->Copy(
183 source_url, 183 source_url,
184 destination_url, 184 destination_url,
185 storage::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, 185 storage::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED,
186 base::Bind(&OnCopyProgress, profile_id, base::Unretained(operation_id)), 186 base::Bind(&OnCopyProgress, profile_id, base::Unretained(operation_id)),
187 base::Bind(&OnCopyCompleted, 187 base::Bind(&OnCopyCompleted,
188 profile_id, 188 profile_id,
189 base::Owned(operation_id), 189 base::Owned(operation_id),
190 source_url, 190 source_url,
191 destination_url)); 191 destination_url));
192 return *operation_id; 192 return *operation_id;
193 } 193 }
194 194
195 void OnCopyCancelled(base::File::Error error) { 195 void OnCopyCancelled(base::File::Error error) {
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 196 DCHECK_CURRENTLY_ON(BrowserThread::IO);
197 197
198 // We just ignore the status if the copy is actually cancelled or not, 198 // We just ignore the status if the copy is actually cancelled or not,
199 // because failing cancellation means the operation is not running now. 199 // because failing cancellation means the operation is not running now.
200 DLOG_IF(WARNING, error != base::File::FILE_OK) 200 DLOG_IF(WARNING, error != base::File::FILE_OK)
201 << "Failed to cancel copy: " << error; 201 << "Failed to cancel copy: " << error;
202 } 202 }
203 203
204 // Cancels the running copy operation identified by |operation_id|. 204 // Cancels the running copy operation identified by |operation_id|.
205 void CancelCopyOnIOThread( 205 void CancelCopyOnIOThread(
206 scoped_refptr<storage::FileSystemContext> file_system_context, 206 scoped_refptr<storage::FileSystemContext> file_system_context,
207 storage::FileSystemOperationRunner::OperationID operation_id) { 207 storage::FileSystemOperationRunner::OperationID operation_id) {
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 208 DCHECK_CURRENTLY_ON(BrowserThread::IO);
209 209
210 file_system_context->operation_runner()->Cancel( 210 file_system_context->operation_runner()->Cancel(
211 operation_id, base::Bind(&OnCopyCancelled)); 211 operation_id, base::Bind(&OnCopyCancelled));
212 } 212 }
213 213
214 // Converts a status code to a bool value and calls the |callback| with it. 214 // Converts a status code to a bool value and calls the |callback| with it.
215 void StatusCallbackToResponseCallback( 215 void StatusCallbackToResponseCallback(
216 const base::Callback<void(bool)>& callback, 216 const base::Callback<void(bool)>& callback,
217 base::File::Error result) { 217 base::File::Error result) {
218 callback.Run(result == base::File::FILE_OK); 218 callback.Run(result == base::File::FILE_OK);
219 } 219 }
220 220
221 // Calls a response callback (on the UI thread) with a file content hash 221 // Calls a response callback (on the UI thread) with a file content hash
222 // computed on the IO thread. 222 // computed on the IO thread.
223 void ComputeChecksumRespondOnUIThread( 223 void ComputeChecksumRespondOnUIThread(
224 const base::Callback<void(const std::string&)>& callback, 224 const base::Callback<void(const std::string&)>& callback,
225 const std::string& hash) { 225 const std::string& hash) {
226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 226 DCHECK_CURRENTLY_ON(BrowserThread::IO);
227 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 227 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
228 base::Bind(callback, hash)); 228 base::Bind(callback, hash));
229 } 229 }
230 230
231 // Calls a response callback on the UI thread. 231 // Calls a response callback on the UI thread.
232 void GetFileMetadataRespondOnUIThread( 232 void GetFileMetadataRespondOnUIThread(
233 const storage::FileSystemOperation::GetMetadataCallback& callback, 233 const storage::FileSystemOperation::GetMetadataCallback& callback,
234 base::File::Error result, 234 base::File::Error result,
235 const base::File::Info& file_info) { 235 const base::File::Info& file_info) {
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 236 DCHECK_CURRENTLY_ON(BrowserThread::IO);
237 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 237 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
238 base::Bind(callback, result, file_info)); 238 base::Bind(callback, result, file_info));
239 } 239 }
240 240
241 } // namespace 241 } // namespace
242 242
243 ExtensionFunction::ResponseAction 243 ExtensionFunction::ResponseAction
244 FileManagerPrivateEnableExternalFileSchemeFunction::Run() { 244 FileManagerPrivateEnableExternalFileSchemeFunction::Run() {
245 ChildProcessSecurityPolicy::GetInstance()->GrantScheme( 245 ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
246 render_view_host()->GetProcess()->GetID(), content::kExternalFileScheme); 246 render_view_host()->GetProcess()->GetID(), content::kExternalFileScheme);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 file_system_url.virtual_path()); 286 file_system_url.virtual_path());
287 content::ChildProcessSecurityPolicy::GetInstance() 287 content::ChildProcessSecurityPolicy::GetInstance()
288 ->GrantCreateReadWriteFile(render_view_host()->GetProcess()->GetID(), 288 ->GrantCreateReadWriteFile(render_view_host()->GetProcess()->GetID(),
289 file_system_url.path()); 289 file_system_url.path());
290 } 290 }
291 } 291 }
292 return RespondNow(NoArguments()); 292 return RespondNow(NoArguments());
293 } 293 }
294 294
295 void FileWatchFunctionBase::Respond(bool success) { 295 void FileWatchFunctionBase::Respond(bool success) {
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 296 DCHECK_CURRENTLY_ON(BrowserThread::UI);
297 297
298 SetResult(new base::FundamentalValue(success)); 298 SetResult(new base::FundamentalValue(success));
299 SendResponse(success); 299 SendResponse(success);
300 } 300 }
301 301
302 bool FileWatchFunctionBase::RunAsync() { 302 bool FileWatchFunctionBase::RunAsync() {
303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 303 DCHECK_CURRENTLY_ON(BrowserThread::UI);
304 304
305 if (!render_view_host() || !render_view_host()->GetProcess()) 305 if (!render_view_host() || !render_view_host()->GetProcess())
306 return false; 306 return false;
307 307
308 // First param is url of a file to watch. 308 // First param is url of a file to watch.
309 std::string url; 309 std::string url;
310 if (!args_->GetString(0, &url) || url.empty()) 310 if (!args_->GetString(0, &url) || url.empty())
311 return false; 311 return false;
312 312
313 scoped_refptr<storage::FileSystemContext> file_system_context = 313 scoped_refptr<storage::FileSystemContext> file_system_context =
314 file_manager::util::GetFileSystemContextForRenderViewHost( 314 file_manager::util::GetFileSystemContextForRenderViewHost(
315 GetProfile(), render_view_host()); 315 GetProfile(), render_view_host());
316 316
317 const FileSystemURL file_system_url = 317 const FileSystemURL file_system_url =
318 file_system_context->CrackURL(GURL(url)); 318 file_system_context->CrackURL(GURL(url));
319 if (file_system_url.path().empty()) { 319 if (file_system_url.path().empty()) {
320 Respond(false); 320 Respond(false);
321 return true; 321 return true;
322 } 322 }
323 323
324 PerformFileWatchOperation(file_system_context, file_system_url, 324 PerformFileWatchOperation(file_system_context, file_system_url,
325 extension_id()); 325 extension_id());
326 return true; 326 return true;
327 } 327 }
328 328
329 void FileManagerPrivateAddFileWatchFunction::PerformFileWatchOperation( 329 void FileManagerPrivateAddFileWatchFunction::PerformFileWatchOperation(
330 scoped_refptr<storage::FileSystemContext> file_system_context, 330 scoped_refptr<storage::FileSystemContext> file_system_context,
331 const storage::FileSystemURL& file_system_url, 331 const storage::FileSystemURL& file_system_url,
332 const std::string& extension_id) { 332 const std::string& extension_id) {
333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 333 DCHECK_CURRENTLY_ON(BrowserThread::UI);
334 334
335 file_manager::EventRouter* const event_router = 335 file_manager::EventRouter* const event_router =
336 file_manager::EventRouterFactory::GetForProfile(GetProfile()); 336 file_manager::EventRouterFactory::GetForProfile(GetProfile());
337 337
338 storage::WatcherManager* const watcher_manager = 338 storage::WatcherManager* const watcher_manager =
339 file_system_context->GetWatcherManager(file_system_url.type()); 339 file_system_context->GetWatcherManager(file_system_url.type());
340 if (watcher_manager) { 340 if (watcher_manager) {
341 watcher_manager->AddWatcher( 341 watcher_manager->AddWatcher(
342 file_system_url, false /* recursive */, 342 file_system_url, false /* recursive */,
343 base::Bind( 343 base::Bind(
344 &StatusCallbackToResponseCallback, 344 &StatusCallbackToResponseCallback,
345 base::Bind(&FileManagerPrivateAddFileWatchFunction::Respond, this)), 345 base::Bind(&FileManagerPrivateAddFileWatchFunction::Respond, this)),
346 base::Bind(&file_manager::EventRouter::OnWatcherManagerNotification, 346 base::Bind(&file_manager::EventRouter::OnWatcherManagerNotification,
347 event_router->GetWeakPtr(), file_system_url, extension_id)); 347 event_router->GetWeakPtr(), file_system_url, extension_id));
348 return; 348 return;
349 } 349 }
350 350
351 // Obsolete. Fallback code if storage::WatcherManager is not implemented. 351 // Obsolete. Fallback code if storage::WatcherManager is not implemented.
352 event_router->AddFileWatch( 352 event_router->AddFileWatch(
353 file_system_url.path(), file_system_url.virtual_path(), extension_id, 353 file_system_url.path(), file_system_url.virtual_path(), extension_id,
354 base::Bind(&FileManagerPrivateAddFileWatchFunction::Respond, this)); 354 base::Bind(&FileManagerPrivateAddFileWatchFunction::Respond, this));
355 } 355 }
356 356
357 void FileManagerPrivateRemoveFileWatchFunction::PerformFileWatchOperation( 357 void FileManagerPrivateRemoveFileWatchFunction::PerformFileWatchOperation(
358 scoped_refptr<storage::FileSystemContext> file_system_context, 358 scoped_refptr<storage::FileSystemContext> file_system_context,
359 const storage::FileSystemURL& file_system_url, 359 const storage::FileSystemURL& file_system_url,
360 const std::string& extension_id) { 360 const std::string& extension_id) {
361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 361 DCHECK_CURRENTLY_ON(BrowserThread::UI);
362 362
363 file_manager::EventRouter* const event_router = 363 file_manager::EventRouter* const event_router =
364 file_manager::EventRouterFactory::GetForProfile(GetProfile()); 364 file_manager::EventRouterFactory::GetForProfile(GetProfile());
365 365
366 storage::WatcherManager* const watcher_manager = 366 storage::WatcherManager* const watcher_manager =
367 file_system_context->GetWatcherManager(file_system_url.type()); 367 file_system_context->GetWatcherManager(file_system_url.type());
368 if (watcher_manager) { 368 if (watcher_manager) {
369 watcher_manager->RemoveWatcher( 369 watcher_manager->RemoveWatcher(
370 file_system_url, false /* recursive */, 370 file_system_url, false /* recursive */,
371 base::Bind(&StatusCallbackToResponseCallback, 371 base::Bind(&StatusCallbackToResponseCallback,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 volume_info.mount_path.AsUTF8Unsafe()); 511 volume_info.mount_path.AsUTF8Unsafe());
512 SendResponse(true); 512 SendResponse(true);
513 return true; 513 return true;
514 } 514 }
515 515
516 // Obtains file size of URL. 516 // Obtains file size of URL.
517 void GetFileMetadataOnIOThread( 517 void GetFileMetadataOnIOThread(
518 scoped_refptr<storage::FileSystemContext> file_system_context, 518 scoped_refptr<storage::FileSystemContext> file_system_context,
519 const FileSystemURL& url, 519 const FileSystemURL& url,
520 const storage::FileSystemOperation::GetMetadataCallback& callback) { 520 const storage::FileSystemOperation::GetMetadataCallback& callback) {
521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 521 DCHECK_CURRENTLY_ON(BrowserThread::IO);
522 file_system_context->operation_runner()->GetMetadata( 522 file_system_context->operation_runner()->GetMetadata(
523 url, base::Bind(&GetFileMetadataRespondOnUIThread, callback)); 523 url, base::Bind(&GetFileMetadataRespondOnUIThread, callback));
524 } 524 }
525 525
526 // Checks if the available space of the |path| is enough for required |bytes|. 526 // Checks if the available space of the |path| is enough for required |bytes|.
527 bool CheckLocalDiskSpaceOnIOThread(const base::FilePath& path, int64 bytes) { 527 bool CheckLocalDiskSpaceOnIOThread(const base::FilePath& path, int64 bytes) {
528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 528 DCHECK_CURRENTLY_ON(BrowserThread::IO);
529 return bytes <= base::SysInfo::AmountOfFreeDiskSpace(path) - 529 return bytes <= base::SysInfo::AmountOfFreeDiskSpace(path) -
530 cryptohome::kMinFreeSpaceInBytes; 530 cryptohome::kMinFreeSpaceInBytes;
531 } 531 }
532 532
533 bool FileManagerPrivateStartCopyFunction::RunAsync() { 533 bool FileManagerPrivateStartCopyFunction::RunAsync() {
534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 534 DCHECK_CURRENTLY_ON(BrowserThread::UI);
535 535
536 using extensions::api::file_manager_private::StartCopy::Params; 536 using extensions::api::file_manager_private::StartCopy::Params;
537 const scoped_ptr<Params> params(Params::Create(*args_)); 537 const scoped_ptr<Params> params(Params::Create(*args_));
538 EXTENSION_FUNCTION_VALIDATE(params); 538 EXTENSION_FUNCTION_VALIDATE(params);
539 539
540 if (params->source_url.empty() || params->parent.empty() || 540 if (params->source_url.empty() || params->parent.empty() ||
541 params->new_name.empty()) { 541 params->new_name.empty()) {
542 // Error code in format of DOMError.name. 542 // Error code in format of DOMError.name.
543 SetError("EncodingError"); 543 SetError("EncodingError");
544 return false; 544 return false;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 579
580 return BrowserThread::PostTask( 580 return BrowserThread::PostTask(
581 BrowserThread::UI, FROM_HERE, 581 BrowserThread::UI, FROM_HERE,
582 base::Bind(&FileManagerPrivateStartCopyFunction::RunAfterFreeDiskSpace, 582 base::Bind(&FileManagerPrivateStartCopyFunction::RunAfterFreeDiskSpace,
583 this, true)); 583 this, true));
584 } 584 }
585 585
586 void FileManagerPrivateStartCopyFunction::RunAfterGetFileMetadata( 586 void FileManagerPrivateStartCopyFunction::RunAfterGetFileMetadata(
587 base::File::Error result, 587 base::File::Error result,
588 const base::File::Info& file_info) { 588 const base::File::Info& file_info) {
589 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 589 DCHECK_CURRENTLY_ON(BrowserThread::UI);
590 590
591 if (result != base::File::FILE_OK) { 591 if (result != base::File::FILE_OK) {
592 SetError("NotFoundError"); 592 SetError("NotFoundError");
593 SendResponse(false); 593 SendResponse(false);
594 return; 594 return;
595 } 595 }
596 596
597 drive::FileSystemInterface* const drive_file_system = 597 drive::FileSystemInterface* const drive_file_system =
598 drive::util::GetFileSystemByProfile(GetProfile()); 598 drive::util::GetFileSystemByProfile(GetProfile());
599 if (drive_file_system) { 599 if (drive_file_system) {
(...skipping 10 matching lines...) Expand all
610 file_info.size), 610 file_info.size),
611 base::Bind(&FileManagerPrivateStartCopyFunction::RunAfterFreeDiskSpace, 611 base::Bind(&FileManagerPrivateStartCopyFunction::RunAfterFreeDiskSpace,
612 this)); 612 this));
613 if (!result) 613 if (!result)
614 SendResponse(false); 614 SendResponse(false);
615 } 615 }
616 } 616 }
617 617
618 void FileManagerPrivateStartCopyFunction::RunAfterFreeDiskSpace( 618 void FileManagerPrivateStartCopyFunction::RunAfterFreeDiskSpace(
619 bool available) { 619 bool available) {
620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 620 DCHECK_CURRENTLY_ON(BrowserThread::UI);
621 621
622 if (!available) { 622 if (!available) {
623 SetError("QuotaExceededError"); 623 SetError("QuotaExceededError");
624 SendResponse(false); 624 SendResponse(false);
625 return; 625 return;
626 } 626 }
627 627
628 scoped_refptr<storage::FileSystemContext> file_system_context = 628 scoped_refptr<storage::FileSystemContext> file_system_context =
629 file_manager::util::GetFileSystemContextForRenderViewHost( 629 file_manager::util::GetFileSystemContextForRenderViewHost(
630 GetProfile(), render_view_host()); 630 GetProfile(), render_view_host());
631 const bool result = BrowserThread::PostTaskAndReplyWithResult( 631 const bool result = BrowserThread::PostTaskAndReplyWithResult(
632 BrowserThread::IO, FROM_HERE, 632 BrowserThread::IO, FROM_HERE,
633 base::Bind(&StartCopyOnIOThread, GetProfile(), file_system_context, 633 base::Bind(&StartCopyOnIOThread, GetProfile(), file_system_context,
634 source_url_, destination_url_), 634 source_url_, destination_url_),
635 base::Bind(&FileManagerPrivateStartCopyFunction::RunAfterStartCopy, 635 base::Bind(&FileManagerPrivateStartCopyFunction::RunAfterStartCopy,
636 this)); 636 this));
637 if (!result) 637 if (!result)
638 SendResponse(false); 638 SendResponse(false);
639 } 639 }
640 640
641 void FileManagerPrivateStartCopyFunction::RunAfterStartCopy( 641 void FileManagerPrivateStartCopyFunction::RunAfterStartCopy(
642 int operation_id) { 642 int operation_id) {
643 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 643 DCHECK_CURRENTLY_ON(BrowserThread::UI);
644 644
645 SetResult(new base::FundamentalValue(operation_id)); 645 SetResult(new base::FundamentalValue(operation_id));
646 SendResponse(true); 646 SendResponse(true);
647 } 647 }
648 648
649 bool FileManagerPrivateCancelCopyFunction::RunAsync() { 649 bool FileManagerPrivateCancelCopyFunction::RunAsync() {
650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 650 DCHECK_CURRENTLY_ON(BrowserThread::UI);
651 651
652 using extensions::api::file_manager_private::CancelCopy::Params; 652 using extensions::api::file_manager_private::CancelCopy::Params;
653 const scoped_ptr<Params> params(Params::Create(*args_)); 653 const scoped_ptr<Params> params(Params::Create(*args_));
654 EXTENSION_FUNCTION_VALIDATE(params); 654 EXTENSION_FUNCTION_VALIDATE(params);
655 655
656 scoped_refptr<storage::FileSystemContext> file_system_context = 656 scoped_refptr<storage::FileSystemContext> file_system_context =
657 file_manager::util::GetFileSystemContextForRenderViewHost( 657 file_manager::util::GetFileSystemContextForRenderViewHost(
658 GetProfile(), render_view_host()); 658 GetProfile(), render_view_host());
659 659
660 // We don't much take care about the result of cancellation. 660 // We don't much take care about the result of cancellation.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 773 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
774 base::Bind(&FileStreamMd5Digester::GetMd5Digest, 774 base::Bind(&FileStreamMd5Digester::GetMd5Digest,
775 base::Unretained(digester_.get()), 775 base::Unretained(digester_.get()),
776 base::Passed(&reader), result_callback)); 776 base::Passed(&reader), result_callback));
777 777
778 return true; 778 return true;
779 } 779 }
780 780
781 void FileManagerPrivateComputeChecksumFunction::Respond( 781 void FileManagerPrivateComputeChecksumFunction::Respond(
782 const std::string& hash) { 782 const std::string& hash) {
783 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 783 DCHECK_CURRENTLY_ON(BrowserThread::UI);
784 SetResult(new base::StringValue(hash)); 784 SetResult(new base::StringValue(hash));
785 SendResponse(true); 785 SendResponse(true);
786 } 786 }
787 787
788 bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { 788 bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() {
789 using api::file_manager_private::SearchFilesByHashes::Params; 789 using api::file_manager_private::SearchFilesByHashes::Params;
790 const scoped_ptr<Params> params(Params::Create(*args_)); 790 const scoped_ptr<Params> params(Params::Create(*args_));
791 EXTENSION_FUNCTION_VALIDATE(params); 791 EXTENSION_FUNCTION_VALIDATE(params);
792 792
793 // TODO(hirono): Check the volume ID and fail the function for volumes other 793 // TODO(hirono): Check the volume ID and fail the function for volumes other
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 return RespondLater(); 897 return RespondLater();
898 } 898 }
899 899
900 void FileManagerPrivateSetEntryTagFunction::OnSetEntryPropertyCompleted( 900 void FileManagerPrivateSetEntryTagFunction::OnSetEntryPropertyCompleted(
901 drive::FileError result) { 901 drive::FileError result) {
902 Respond(result == drive::FILE_ERROR_OK ? NoArguments() 902 Respond(result == drive::FILE_ERROR_OK ? NoArguments()
903 : Error("Failed to set a tag.")); 903 : Error("Failed to set a tag."));
904 } 904 }
905 905
906 } // namespace extensions 906 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698