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/chromeos/gdata/gdata_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/drive_file_system.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/json/json_file_value_serializer.h" | 12 #include "base/json/json_file_value_serializer.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/message_loop_proxy.h" | 14 #include "base/message_loop_proxy.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 void OnAddUploadFileCompleted( | 96 void OnAddUploadFileCompleted( |
97 const FileOperationCallback& callback, | 97 const FileOperationCallback& callback, |
98 DriveFileError error) { | 98 DriveFileError error) { |
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
100 if (!callback.is_null()) | 100 if (!callback.is_null()) |
101 callback.Run(error); | 101 callback.Run(error); |
102 } | 102 } |
103 | 103 |
104 // The class to wait for the initial load of root feed and runs the callback | 104 // The class to wait for the initial load of root feed and runs the callback |
105 // after the initialization. | 105 // after the initialization. |
106 class InitialLoadObserver : public GDataFileSystemInterface::Observer { | 106 class InitialLoadObserver : public DriveFileSystemInterface::Observer { |
107 public: | 107 public: |
108 InitialLoadObserver(GDataFileSystemInterface* file_system, | 108 InitialLoadObserver(DriveFileSystemInterface* file_system, |
109 const base::Closure& callback) | 109 const base::Closure& callback) |
110 : file_system_(file_system), callback_(callback) {} | 110 : file_system_(file_system), callback_(callback) {} |
111 | 111 |
112 virtual void OnInitialLoadFinished() OVERRIDE { | 112 virtual void OnInitialLoadFinished() OVERRIDE { |
113 if (!callback_.is_null()) | 113 if (!callback_.is_null()) |
114 base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback_); | 114 base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback_); |
115 file_system_->RemoveObserver(this); | 115 file_system_->RemoveObserver(this); |
116 base::MessageLoopProxy::current()->DeleteSoon(FROM_HERE, this); | 116 base::MessageLoopProxy::current()->DeleteSoon(FROM_HERE, this); |
117 } | 117 } |
118 | 118 |
119 private: | 119 private: |
120 GDataFileSystemInterface* file_system_; | 120 DriveFileSystemInterface* file_system_; |
121 base::Closure callback_; | 121 base::Closure callback_; |
122 }; | 122 }; |
123 | 123 |
124 // Gets the file size of |local_file|. | 124 // Gets the file size of |local_file|. |
125 void GetLocalFileSizeOnBlockingPool(const FilePath& local_file, | 125 void GetLocalFileSizeOnBlockingPool(const FilePath& local_file, |
126 DriveFileError* error, | 126 DriveFileError* error, |
127 int64* file_size) { | 127 int64* file_size) { |
128 DCHECK(error); | 128 DCHECK(error); |
129 DCHECK(file_size); | 129 DCHECK(file_size); |
130 | 130 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 const GetEntryInfoWithFilePathCallback& callback, | 265 const GetEntryInfoWithFilePathCallback& callback, |
266 const FilePath& path, | 266 const FilePath& path, |
267 DriveFileError error, | 267 DriveFileError error, |
268 scoped_ptr<DriveEntryProto> entry_proto) { | 268 scoped_ptr<DriveEntryProto> entry_proto) { |
269 if (!callback.is_null()) | 269 if (!callback.is_null()) |
270 callback.Run(error, path, entry_proto.Pass()); | 270 callback.Run(error, path, entry_proto.Pass()); |
271 } | 271 } |
272 | 272 |
273 } // namespace | 273 } // namespace |
274 | 274 |
275 // GDataFileSystem::CreateDirectoryParams struct implementation. | 275 // DriveFileSystem::CreateDirectoryParams struct implementation. |
276 struct GDataFileSystem::CreateDirectoryParams { | 276 struct DriveFileSystem::CreateDirectoryParams { |
277 CreateDirectoryParams(const FilePath& created_directory_path, | 277 CreateDirectoryParams(const FilePath& created_directory_path, |
278 const FilePath& target_directory_path, | 278 const FilePath& target_directory_path, |
279 bool is_exclusive, | 279 bool is_exclusive, |
280 bool is_recursive, | 280 bool is_recursive, |
281 const FileOperationCallback& callback); | 281 const FileOperationCallback& callback); |
282 ~CreateDirectoryParams(); | 282 ~CreateDirectoryParams(); |
283 | 283 |
284 const FilePath created_directory_path; | 284 const FilePath created_directory_path; |
285 const FilePath target_directory_path; | 285 const FilePath target_directory_path; |
286 const bool is_exclusive; | 286 const bool is_exclusive; |
287 const bool is_recursive; | 287 const bool is_recursive; |
288 FileOperationCallback callback; | 288 FileOperationCallback callback; |
289 }; | 289 }; |
290 | 290 |
291 GDataFileSystem::CreateDirectoryParams::CreateDirectoryParams( | 291 DriveFileSystem::CreateDirectoryParams::CreateDirectoryParams( |
292 const FilePath& created_directory_path, | 292 const FilePath& created_directory_path, |
293 const FilePath& target_directory_path, | 293 const FilePath& target_directory_path, |
294 bool is_exclusive, | 294 bool is_exclusive, |
295 bool is_recursive, | 295 bool is_recursive, |
296 const FileOperationCallback& callback) | 296 const FileOperationCallback& callback) |
297 : created_directory_path(created_directory_path), | 297 : created_directory_path(created_directory_path), |
298 target_directory_path(target_directory_path), | 298 target_directory_path(target_directory_path), |
299 is_exclusive(is_exclusive), | 299 is_exclusive(is_exclusive), |
300 is_recursive(is_recursive), | 300 is_recursive(is_recursive), |
301 callback(callback) { | 301 callback(callback) { |
302 } | 302 } |
303 | 303 |
304 GDataFileSystem::CreateDirectoryParams::~CreateDirectoryParams() { | 304 DriveFileSystem::CreateDirectoryParams::~CreateDirectoryParams() { |
305 } | 305 } |
306 | 306 |
307 // GDataFileSystem::GetFileCompleteForOpenParams struct implementation. | 307 // DriveFileSystem::GetFileCompleteForOpenParams struct implementation. |
308 struct GDataFileSystem::GetFileCompleteForOpenParams { | 308 struct DriveFileSystem::GetFileCompleteForOpenParams { |
309 GetFileCompleteForOpenParams(const std::string& resource_id, | 309 GetFileCompleteForOpenParams(const std::string& resource_id, |
310 const std::string& md5); | 310 const std::string& md5); |
311 ~GetFileCompleteForOpenParams(); | 311 ~GetFileCompleteForOpenParams(); |
312 std::string resource_id; | 312 std::string resource_id; |
313 std::string md5; | 313 std::string md5; |
314 }; | 314 }; |
315 | 315 |
316 GDataFileSystem::GetFileCompleteForOpenParams::GetFileCompleteForOpenParams( | 316 DriveFileSystem::GetFileCompleteForOpenParams::GetFileCompleteForOpenParams( |
317 const std::string& resource_id, | 317 const std::string& resource_id, |
318 const std::string& md5) | 318 const std::string& md5) |
319 : resource_id(resource_id), | 319 : resource_id(resource_id), |
320 md5(md5) { | 320 md5(md5) { |
321 } | 321 } |
322 | 322 |
323 GDataFileSystem::GetFileCompleteForOpenParams::~GetFileCompleteForOpenParams() { | 323 DriveFileSystem::GetFileCompleteForOpenParams::~GetFileCompleteForOpenParams() { |
324 } | 324 } |
325 | 325 |
326 // GDataFileSystem::GetFileFromCacheParams struct implementation. | 326 // DriveFileSystem::GetFileFromCacheParams struct implementation. |
327 struct GDataFileSystem::GetFileFromCacheParams { | 327 struct DriveFileSystem::GetFileFromCacheParams { |
328 GetFileFromCacheParams( | 328 GetFileFromCacheParams( |
329 const FilePath& virtual_file_path, | 329 const FilePath& virtual_file_path, |
330 const FilePath& local_tmp_path, | 330 const FilePath& local_tmp_path, |
331 const GURL& content_url, | 331 const GURL& content_url, |
332 const std::string& resource_id, | 332 const std::string& resource_id, |
333 const std::string& md5, | 333 const std::string& md5, |
334 const std::string& mime_type, | 334 const std::string& mime_type, |
335 const GetFileCallback& get_file_callback, | 335 const GetFileCallback& get_file_callback, |
336 const GetContentCallback& get_content_callback); | 336 const GetContentCallback& get_content_callback); |
337 ~GetFileFromCacheParams(); | 337 ~GetFileFromCacheParams(); |
338 | 338 |
339 FilePath virtual_file_path; | 339 FilePath virtual_file_path; |
340 FilePath local_tmp_path; | 340 FilePath local_tmp_path; |
341 GURL content_url; | 341 GURL content_url; |
342 std::string resource_id; | 342 std::string resource_id; |
343 std::string md5; | 343 std::string md5; |
344 std::string mime_type; | 344 std::string mime_type; |
345 const GetFileCallback get_file_callback; | 345 const GetFileCallback get_file_callback; |
346 const GetContentCallback get_content_callback; | 346 const GetContentCallback get_content_callback; |
347 }; | 347 }; |
348 | 348 |
349 GDataFileSystem::GetFileFromCacheParams::GetFileFromCacheParams( | 349 DriveFileSystem::GetFileFromCacheParams::GetFileFromCacheParams( |
350 const FilePath& virtual_file_path, | 350 const FilePath& virtual_file_path, |
351 const FilePath& local_tmp_path, | 351 const FilePath& local_tmp_path, |
352 const GURL& content_url, | 352 const GURL& content_url, |
353 const std::string& resource_id, | 353 const std::string& resource_id, |
354 const std::string& md5, | 354 const std::string& md5, |
355 const std::string& mime_type, | 355 const std::string& mime_type, |
356 const GetFileCallback& get_file_callback, | 356 const GetFileCallback& get_file_callback, |
357 const GetContentCallback& get_content_callback) | 357 const GetContentCallback& get_content_callback) |
358 : virtual_file_path(virtual_file_path), | 358 : virtual_file_path(virtual_file_path), |
359 local_tmp_path(local_tmp_path), | 359 local_tmp_path(local_tmp_path), |
360 content_url(content_url), | 360 content_url(content_url), |
361 resource_id(resource_id), | 361 resource_id(resource_id), |
362 md5(md5), | 362 md5(md5), |
363 mime_type(mime_type), | 363 mime_type(mime_type), |
364 get_file_callback(get_file_callback), | 364 get_file_callback(get_file_callback), |
365 get_content_callback(get_content_callback) { | 365 get_content_callback(get_content_callback) { |
366 } | 366 } |
367 | 367 |
368 GDataFileSystem::GetFileFromCacheParams::~GetFileFromCacheParams() { | 368 DriveFileSystem::GetFileFromCacheParams::~GetFileFromCacheParams() { |
369 } | 369 } |
370 | 370 |
371 // GDataFileSystem::StartFileUploadParams implementation. | 371 // DriveFileSystem::StartFileUploadParams implementation. |
372 struct GDataFileSystem::StartFileUploadParams { | 372 struct DriveFileSystem::StartFileUploadParams { |
373 StartFileUploadParams(const FilePath& in_local_file_path, | 373 StartFileUploadParams(const FilePath& in_local_file_path, |
374 const FilePath& in_remote_file_path, | 374 const FilePath& in_remote_file_path, |
375 const FileOperationCallback& in_callback) | 375 const FileOperationCallback& in_callback) |
376 : local_file_path(in_local_file_path), | 376 : local_file_path(in_local_file_path), |
377 remote_file_path(in_remote_file_path), | 377 remote_file_path(in_remote_file_path), |
378 callback(in_callback) {} | 378 callback(in_callback) {} |
379 | 379 |
380 const FilePath local_file_path; | 380 const FilePath local_file_path; |
381 const FilePath remote_file_path; | 381 const FilePath remote_file_path; |
382 const FileOperationCallback callback; | 382 const FileOperationCallback callback; |
383 }; | 383 }; |
384 | 384 |
385 // GDataFileSystem::AddUploadedFileParams implementation. | 385 // DriveFileSystem::AddUploadedFileParams implementation. |
386 struct GDataFileSystem::AddUploadedFileParams { | 386 struct DriveFileSystem::AddUploadedFileParams { |
387 AddUploadedFileParams(UploadMode upload_mode, | 387 AddUploadedFileParams(UploadMode upload_mode, |
388 DriveDirectory* parent_dir, | 388 DriveDirectory* parent_dir, |
389 scoped_ptr<DriveEntry> new_entry, | 389 scoped_ptr<DriveEntry> new_entry, |
390 const FilePath& file_content_path, | 390 const FilePath& file_content_path, |
391 DriveCache::FileOperationType cache_operation, | 391 DriveCache::FileOperationType cache_operation, |
392 const base::Closure& callback) | 392 const base::Closure& callback) |
393 : upload_mode(upload_mode), | 393 : upload_mode(upload_mode), |
394 parent_dir(parent_dir), | 394 parent_dir(parent_dir), |
395 new_entry(new_entry.Pass()), | 395 new_entry(new_entry.Pass()), |
396 file_content_path(file_content_path), | 396 file_content_path(file_content_path), |
397 cache_operation(cache_operation), | 397 cache_operation(cache_operation), |
398 callback(callback) { | 398 callback(callback) { |
399 } | 399 } |
400 | 400 |
401 UploadMode upload_mode; | 401 UploadMode upload_mode; |
402 DriveDirectory* parent_dir; | 402 DriveDirectory* parent_dir; |
403 scoped_ptr<DriveEntry> new_entry; | 403 scoped_ptr<DriveEntry> new_entry; |
404 FilePath file_content_path; | 404 FilePath file_content_path; |
405 DriveCache::FileOperationType cache_operation; | 405 DriveCache::FileOperationType cache_operation; |
406 base::Closure callback; | 406 base::Closure callback; |
407 std::string resource_id; | 407 std::string resource_id; |
408 std::string md5; | 408 std::string md5; |
409 }; | 409 }; |
410 | 410 |
411 | 411 |
412 // GDataFileSystem class implementation. | 412 // DriveFileSystem class implementation. |
413 | 413 |
414 GDataFileSystem::GDataFileSystem( | 414 DriveFileSystem::DriveFileSystem( |
415 Profile* profile, | 415 Profile* profile, |
416 DriveCache* cache, | 416 DriveCache* cache, |
417 DriveServiceInterface* drive_service, | 417 DriveServiceInterface* drive_service, |
418 GDataUploaderInterface* uploader, | 418 GDataUploaderInterface* uploader, |
419 DriveWebAppsRegistryInterface* webapps_registry, | 419 DriveWebAppsRegistryInterface* webapps_registry, |
420 base::SequencedTaskRunner* blocking_task_runner) | 420 base::SequencedTaskRunner* blocking_task_runner) |
421 : profile_(profile), | 421 : profile_(profile), |
422 cache_(cache), | 422 cache_(cache), |
423 uploader_(uploader), | 423 uploader_(uploader), |
424 drive_service_(drive_service), | 424 drive_service_(drive_service), |
425 webapps_registry_(webapps_registry), | 425 webapps_registry_(webapps_registry), |
426 update_timer_(true /* retain_user_task */, true /* is_repeating */), | 426 update_timer_(true /* retain_user_task */, true /* is_repeating */), |
427 hide_hosted_docs_(false), | 427 hide_hosted_docs_(false), |
428 blocking_task_runner_(blocking_task_runner), | 428 blocking_task_runner_(blocking_task_runner), |
429 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 429 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
430 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()) { | 430 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()) { |
431 // Should be created from the file browser extension API on UI thread. | 431 // Should be created from the file browser extension API on UI thread. |
432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
433 } | 433 } |
434 | 434 |
435 void GDataFileSystem::Initialize() { | 435 void DriveFileSystem::Initialize() { |
436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
437 | 437 |
438 drive_service_->Initialize(profile_); | 438 drive_service_->Initialize(profile_); |
439 | 439 |
440 resource_metadata_.reset(new DriveResourceMetadata); | 440 resource_metadata_.reset(new DriveResourceMetadata); |
441 feed_loader_.reset(new GDataWapiFeedLoader(resource_metadata_.get(), | 441 feed_loader_.reset(new GDataWapiFeedLoader(resource_metadata_.get(), |
442 drive_service_, | 442 drive_service_, |
443 webapps_registry_, | 443 webapps_registry_, |
444 cache_, | 444 cache_, |
445 blocking_task_runner_)); | 445 blocking_task_runner_)); |
446 feed_loader_->AddObserver(this); | 446 feed_loader_->AddObserver(this); |
447 | 447 |
448 PrefService* pref_service = profile_->GetPrefs(); | 448 PrefService* pref_service = profile_->GetPrefs(); |
449 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); | 449 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); |
450 | 450 |
451 InitializePreferenceObserver(); | 451 InitializePreferenceObserver(); |
452 } | 452 } |
453 | 453 |
454 void GDataFileSystem::CheckForUpdates() { | 454 void DriveFileSystem::CheckForUpdates() { |
455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
456 ContentOrigin initial_origin = resource_metadata_->origin(); | 456 ContentOrigin initial_origin = resource_metadata_->origin(); |
457 if (initial_origin == FROM_SERVER) { | 457 if (initial_origin == FROM_SERVER) { |
458 resource_metadata_->set_origin(REFRESHING); | 458 resource_metadata_->set_origin(REFRESHING); |
459 feed_loader_->ReloadFromServerIfNeeded( | 459 feed_loader_->ReloadFromServerIfNeeded( |
460 initial_origin, | 460 initial_origin, |
461 resource_metadata_->largest_changestamp(), | 461 resource_metadata_->largest_changestamp(), |
462 base::Bind(&GDataFileSystem::OnUpdateChecked, | 462 base::Bind(&DriveFileSystem::OnUpdateChecked, |
463 ui_weak_ptr_, | 463 ui_weak_ptr_, |
464 initial_origin)); | 464 initial_origin)); |
465 } | 465 } |
466 } | 466 } |
467 | 467 |
468 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin, | 468 void DriveFileSystem::OnUpdateChecked(ContentOrigin initial_origin, |
469 DriveFileError error) { | 469 DriveFileError error) { |
470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
471 | 471 |
472 if (error != DRIVE_FILE_OK) | 472 if (error != DRIVE_FILE_OK) |
473 resource_metadata_->set_origin(initial_origin); | 473 resource_metadata_->set_origin(initial_origin); |
474 } | 474 } |
475 | 475 |
476 GDataFileSystem::~GDataFileSystem() { | 476 DriveFileSystem::~DriveFileSystem() { |
477 // This should be called from UI thread, from GDataSystemService shutdown. | 477 // This should be called from UI thread, from GDataSystemService shutdown. |
478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
479 | 479 |
480 feed_loader_->RemoveObserver(this); | 480 feed_loader_->RemoveObserver(this); |
481 | 481 |
482 // Cancel all the in-flight operations. | 482 // Cancel all the in-flight operations. |
483 // This asynchronously cancels the URL fetch operations. | 483 // This asynchronously cancels the URL fetch operations. |
484 drive_service_->CancelAll(); | 484 drive_service_->CancelAll(); |
485 } | 485 } |
486 | 486 |
487 void GDataFileSystem::AddObserver( | 487 void DriveFileSystem::AddObserver( |
488 GDataFileSystemInterface::Observer* observer) { | 488 DriveFileSystemInterface::Observer* observer) { |
489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
490 observers_.AddObserver(observer); | 490 observers_.AddObserver(observer); |
491 } | 491 } |
492 | 492 |
493 void GDataFileSystem::RemoveObserver( | 493 void DriveFileSystem::RemoveObserver( |
494 GDataFileSystemInterface::Observer* observer) { | 494 DriveFileSystemInterface::Observer* observer) { |
495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
496 observers_.RemoveObserver(observer); | 496 observers_.RemoveObserver(observer); |
497 } | 497 } |
498 | 498 |
499 void GDataFileSystem::StartUpdates() { | 499 void DriveFileSystem::StartUpdates() { |
500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
501 | 501 |
502 DCHECK(!update_timer_.IsRunning()); | 502 DCHECK(!update_timer_.IsRunning()); |
503 update_timer_.Start(FROM_HERE, | 503 update_timer_.Start(FROM_HERE, |
504 base::TimeDelta::FromSeconds( | 504 base::TimeDelta::FromSeconds( |
505 kGDataUpdateCheckIntervalInSec), | 505 kGDataUpdateCheckIntervalInSec), |
506 base::Bind(&GDataFileSystem::CheckForUpdates, | 506 base::Bind(&DriveFileSystem::CheckForUpdates, |
507 ui_weak_ptr_)); | 507 ui_weak_ptr_)); |
508 } | 508 } |
509 | 509 |
510 void GDataFileSystem::StopUpdates() { | 510 void DriveFileSystem::StopUpdates() { |
511 // If unmount request comes from filesystem side, this method may be called | 511 // If unmount request comes from filesystem side, this method may be called |
512 // twice. First is just after unmounting on filesystem, second is after | 512 // twice. First is just after unmounting on filesystem, second is after |
513 // unmounting on filemanager on JS. In other words, if this is called from | 513 // unmounting on filemanager on JS. In other words, if this is called from |
514 // GDataSystemService::RemoveDriveMountPoint(), this will be called again from | 514 // GDataSystemService::RemoveDriveMountPoint(), this will be called again from |
515 // FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(). | 515 // FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(). |
516 // We choose to stopping updates asynchronous without waiting for filemanager, | 516 // We choose to stopping updates asynchronous without waiting for filemanager, |
517 // rather than waiting for completion of unmounting on filemanager. | 517 // rather than waiting for completion of unmounting on filemanager. |
518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
519 if (update_timer_.IsRunning()) | 519 if (update_timer_.IsRunning()) |
520 update_timer_.Stop(); | 520 update_timer_.Stop(); |
521 } | 521 } |
522 | 522 |
523 void GDataFileSystem::GetEntryInfoByResourceId( | 523 void DriveFileSystem::GetEntryInfoByResourceId( |
524 const std::string& resource_id, | 524 const std::string& resource_id, |
525 const GetEntryInfoWithFilePathCallback& callback) { | 525 const GetEntryInfoWithFilePathCallback& callback) { |
526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
527 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 527 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
528 DCHECK(!callback.is_null()); | 528 DCHECK(!callback.is_null()); |
529 | 529 |
530 RunTaskOnUIThread( | 530 RunTaskOnUIThread( |
531 base::Bind(&GDataFileSystem::GetEntryInfoByResourceIdOnUIThread, | 531 base::Bind(&DriveFileSystem::GetEntryInfoByResourceIdOnUIThread, |
532 ui_weak_ptr_, | 532 ui_weak_ptr_, |
533 resource_id, | 533 resource_id, |
534 CreateRelayCallback(callback))); | 534 CreateRelayCallback(callback))); |
535 } | 535 } |
536 | 536 |
537 void GDataFileSystem::GetEntryInfoByResourceIdOnUIThread( | 537 void DriveFileSystem::GetEntryInfoByResourceIdOnUIThread( |
538 const std::string& resource_id, | 538 const std::string& resource_id, |
539 const GetEntryInfoWithFilePathCallback& callback) { | 539 const GetEntryInfoWithFilePathCallback& callback) { |
540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
541 DCHECK(!callback.is_null()); | 541 DCHECK(!callback.is_null()); |
542 | 542 |
543 resource_metadata_->GetEntryByResourceIdAsync(resource_id, | 543 resource_metadata_->GetEntryByResourceIdAsync(resource_id, |
544 base::Bind(&GDataFileSystem::GetEntryInfoByEntryOnUIThread, | 544 base::Bind(&DriveFileSystem::GetEntryInfoByEntryOnUIThread, |
545 ui_weak_ptr_, | 545 ui_weak_ptr_, |
546 callback)); | 546 callback)); |
547 } | 547 } |
548 | 548 |
549 void GDataFileSystem::GetEntryInfoByEntryOnUIThread( | 549 void DriveFileSystem::GetEntryInfoByEntryOnUIThread( |
550 const GetEntryInfoWithFilePathCallback& callback, | 550 const GetEntryInfoWithFilePathCallback& callback, |
551 DriveEntry* entry) { | 551 DriveEntry* entry) { |
552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
553 DCHECK(!callback.is_null()); | 553 DCHECK(!callback.is_null()); |
554 | 554 |
555 if (entry) { | 555 if (entry) { |
556 scoped_ptr<DriveEntryProto> entry_proto(new DriveEntryProto); | 556 scoped_ptr<DriveEntryProto> entry_proto(new DriveEntryProto); |
557 entry->ToProtoFull(entry_proto.get()); | 557 entry->ToProtoFull(entry_proto.get()); |
558 CheckLocalModificationAndRun( | 558 CheckLocalModificationAndRun( |
559 entry_proto.Pass(), | 559 entry_proto.Pass(), |
560 base::Bind(&RunGetEntryInfoWithFilePathCallback, | 560 base::Bind(&RunGetEntryInfoWithFilePathCallback, |
561 callback, entry->GetFilePath())); | 561 callback, entry->GetFilePath())); |
562 } else { | 562 } else { |
563 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, | 563 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, |
564 FilePath(), | 564 FilePath(), |
565 scoped_ptr<DriveEntryProto>()); | 565 scoped_ptr<DriveEntryProto>()); |
566 } | 566 } |
567 } | 567 } |
568 | 568 |
569 void GDataFileSystem::LoadFeedIfNeeded(const FileOperationCallback& callback) { | 569 void DriveFileSystem::LoadFeedIfNeeded(const FileOperationCallback& callback) { |
570 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 570 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
571 DCHECK(!callback.is_null()); | 571 DCHECK(!callback.is_null()); |
572 | 572 |
573 if (resource_metadata_->origin() == INITIALIZING) { | 573 if (resource_metadata_->origin() == INITIALIZING) { |
574 // If root feed is not initialized but the initialization process has | 574 // If root feed is not initialized but the initialization process has |
575 // already started, add an observer to execute the remaining task after | 575 // already started, add an observer to execute the remaining task after |
576 // the end of the initialization. | 576 // the end of the initialization. |
577 AddObserver(new InitialLoadObserver(this, | 577 AddObserver(new InitialLoadObserver(this, |
578 base::Bind(callback, DRIVE_FILE_OK))); | 578 base::Bind(callback, DRIVE_FILE_OK))); |
579 return; | 579 return; |
580 } else if (resource_metadata_->origin() == UNINITIALIZED) { | 580 } else if (resource_metadata_->origin() == UNINITIALIZED) { |
581 // Load root feed from this disk cache. Upon completion, kick off server | 581 // Load root feed from this disk cache. Upon completion, kick off server |
582 // fetching. | 582 // fetching. |
583 resource_metadata_->set_origin(INITIALIZING); | 583 resource_metadata_->set_origin(INITIALIZING); |
584 feed_loader_->LoadFromCache( | 584 feed_loader_->LoadFromCache( |
585 true, // should_load_from_server | 585 true, // should_load_from_server |
586 base::Bind(&GDataFileSystem::NotifyInitialLoadFinishedAndRun, | 586 base::Bind(&DriveFileSystem::NotifyInitialLoadFinishedAndRun, |
587 ui_weak_ptr_, | 587 ui_weak_ptr_, |
588 callback)); | 588 callback)); |
589 return; | 589 return; |
590 } | 590 } |
591 | 591 |
592 // The feed has already been loaded, so we have nothing to do, but post a | 592 // The feed has already been loaded, so we have nothing to do, but post a |
593 // task to the same thread, rather than calling it here, as | 593 // task to the same thread, rather than calling it here, as |
594 // LoadFeedIfNeeded() is asynchronous. | 594 // LoadFeedIfNeeded() is asynchronous. |
595 base::MessageLoopProxy::current()->PostTask( | 595 base::MessageLoopProxy::current()->PostTask( |
596 FROM_HERE, | 596 FROM_HERE, |
597 base::Bind(callback, DRIVE_FILE_OK)); | 597 base::Bind(callback, DRIVE_FILE_OK)); |
598 } | 598 } |
599 | 599 |
600 void GDataFileSystem::TransferFileFromRemoteToLocal( | 600 void DriveFileSystem::TransferFileFromRemoteToLocal( |
601 const FilePath& remote_src_file_path, | 601 const FilePath& remote_src_file_path, |
602 const FilePath& local_dest_file_path, | 602 const FilePath& local_dest_file_path, |
603 const FileOperationCallback& callback) { | 603 const FileOperationCallback& callback) { |
604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
605 DCHECK(!callback.is_null()); | 605 DCHECK(!callback.is_null()); |
606 | 606 |
607 GetFileByPath(remote_src_file_path, | 607 GetFileByPath(remote_src_file_path, |
608 base::Bind(&GDataFileSystem::OnGetFileCompleteForTransferFile, | 608 base::Bind(&DriveFileSystem::OnGetFileCompleteForTransferFile, |
609 ui_weak_ptr_, | 609 ui_weak_ptr_, |
610 local_dest_file_path, | 610 local_dest_file_path, |
611 callback), | 611 callback), |
612 GetContentCallback()); | 612 GetContentCallback()); |
613 } | 613 } |
614 | 614 |
615 void GDataFileSystem::TransferFileFromLocalToRemote( | 615 void DriveFileSystem::TransferFileFromLocalToRemote( |
616 const FilePath& local_src_file_path, | 616 const FilePath& local_src_file_path, |
617 const FilePath& remote_dest_file_path, | 617 const FilePath& remote_dest_file_path, |
618 const FileOperationCallback& callback) { | 618 const FileOperationCallback& callback) { |
619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
620 DCHECK(!callback.is_null()); | 620 DCHECK(!callback.is_null()); |
621 | 621 |
622 // Make sure the destination directory exists. | 622 // Make sure the destination directory exists. |
623 resource_metadata_->GetEntryInfoByPath( | 623 resource_metadata_->GetEntryInfoByPath( |
624 remote_dest_file_path.DirName(), | 624 remote_dest_file_path.DirName(), |
625 base::Bind( | 625 base::Bind( |
626 &GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo, | 626 &DriveFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo, |
627 ui_weak_ptr_, | 627 ui_weak_ptr_, |
628 local_src_file_path, | 628 local_src_file_path, |
629 remote_dest_file_path, | 629 remote_dest_file_path, |
630 callback)); | 630 callback)); |
631 } | 631 } |
632 | 632 |
633 void GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo( | 633 void DriveFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo( |
634 const FilePath& local_src_file_path, | 634 const FilePath& local_src_file_path, |
635 const FilePath& remote_dest_file_path, | 635 const FilePath& remote_dest_file_path, |
636 const FileOperationCallback& callback, | 636 const FileOperationCallback& callback, |
637 DriveFileError error, | 637 DriveFileError error, |
638 scoped_ptr<DriveEntryProto> entry_proto) { | 638 scoped_ptr<DriveEntryProto> entry_proto) { |
639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
640 DCHECK(!callback.is_null()); | 640 DCHECK(!callback.is_null()); |
641 | 641 |
642 if (error != DRIVE_FILE_OK) { | 642 if (error != DRIVE_FILE_OK) { |
643 callback.Run(error); | 643 callback.Run(error); |
644 return; | 644 return; |
645 } | 645 } |
646 | 646 |
647 DCHECK(entry_proto.get()); | 647 DCHECK(entry_proto.get()); |
648 if (!entry_proto->file_info().is_directory()) { | 648 if (!entry_proto->file_info().is_directory()) { |
649 // The parent of |remote_dest_file_path| is not a directory. | 649 // The parent of |remote_dest_file_path| is not a directory. |
650 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); | 650 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); |
651 return; | 651 return; |
652 } | 652 } |
653 | 653 |
654 std::string* resource_id = new std::string; | 654 std::string* resource_id = new std::string; |
655 util::PostBlockingPoolSequencedTaskAndReply( | 655 util::PostBlockingPoolSequencedTaskAndReply( |
656 FROM_HERE, | 656 FROM_HERE, |
657 blocking_task_runner_, | 657 blocking_task_runner_, |
658 base::Bind(&GetDocumentResourceIdOnBlockingPool, | 658 base::Bind(&GetDocumentResourceIdOnBlockingPool, |
659 local_src_file_path, | 659 local_src_file_path, |
660 resource_id), | 660 resource_id), |
661 base::Bind(&GDataFileSystem::TransferFileForResourceId, | 661 base::Bind(&DriveFileSystem::TransferFileForResourceId, |
662 ui_weak_ptr_, | 662 ui_weak_ptr_, |
663 local_src_file_path, | 663 local_src_file_path, |
664 remote_dest_file_path, | 664 remote_dest_file_path, |
665 callback, | 665 callback, |
666 base::Owned(resource_id))); | 666 base::Owned(resource_id))); |
667 } | 667 } |
668 | 668 |
669 void GDataFileSystem::TransferFileForResourceId( | 669 void DriveFileSystem::TransferFileForResourceId( |
670 const FilePath& local_file_path, | 670 const FilePath& local_file_path, |
671 const FilePath& remote_dest_file_path, | 671 const FilePath& remote_dest_file_path, |
672 const FileOperationCallback& callback, | 672 const FileOperationCallback& callback, |
673 std::string* resource_id) { | 673 std::string* resource_id) { |
674 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 674 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
675 DCHECK(resource_id); | 675 DCHECK(resource_id); |
676 DCHECK(!callback.is_null()); | 676 DCHECK(!callback.is_null()); |
677 | 677 |
678 if (resource_id->empty()) { | 678 if (resource_id->empty()) { |
679 // If |resource_id| is empty, upload the local file as a regular file. | 679 // If |resource_id| is empty, upload the local file as a regular file. |
680 TransferRegularFile(local_file_path, remote_dest_file_path, callback); | 680 TransferRegularFile(local_file_path, remote_dest_file_path, callback); |
681 return; | 681 return; |
682 } | 682 } |
683 | 683 |
684 // Otherwise, copy the document on the server side and add the new copy | 684 // Otherwise, copy the document on the server side and add the new copy |
685 // to the destination directory (collection). | 685 // to the destination directory (collection). |
686 CopyDocumentToDirectory( | 686 CopyDocumentToDirectory( |
687 remote_dest_file_path.DirName(), | 687 remote_dest_file_path.DirName(), |
688 *resource_id, | 688 *resource_id, |
689 // Drop the document extension, which should not be | 689 // Drop the document extension, which should not be |
690 // in the document title. | 690 // in the document title. |
691 remote_dest_file_path.BaseName().RemoveExtension().value(), | 691 remote_dest_file_path.BaseName().RemoveExtension().value(), |
692 callback); | 692 callback); |
693 } | 693 } |
694 | 694 |
695 void GDataFileSystem::TransferRegularFile( | 695 void DriveFileSystem::TransferRegularFile( |
696 const FilePath& local_file_path, | 696 const FilePath& local_file_path, |
697 const FilePath& remote_dest_file_path, | 697 const FilePath& remote_dest_file_path, |
698 const FileOperationCallback& callback) { | 698 const FileOperationCallback& callback) { |
699 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 699 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
700 | 700 |
701 DriveFileError* error = | 701 DriveFileError* error = |
702 new DriveFileError(DRIVE_FILE_OK); | 702 new DriveFileError(DRIVE_FILE_OK); |
703 int64* file_size = new int64; | 703 int64* file_size = new int64; |
704 std::string* content_type = new std::string; | 704 std::string* content_type = new std::string; |
705 util::PostBlockingPoolSequencedTaskAndReply( | 705 util::PostBlockingPoolSequencedTaskAndReply( |
706 FROM_HERE, | 706 FROM_HERE, |
707 blocking_task_runner_, | 707 blocking_task_runner_, |
708 base::Bind(&GetLocalFileInfoOnBlockingPool, | 708 base::Bind(&GetLocalFileInfoOnBlockingPool, |
709 local_file_path, | 709 local_file_path, |
710 error, | 710 error, |
711 file_size, | 711 file_size, |
712 content_type), | 712 content_type), |
713 base::Bind(&GDataFileSystem::StartFileUploadOnUIThread, | 713 base::Bind(&DriveFileSystem::StartFileUploadOnUIThread, |
714 ui_weak_ptr_, | 714 ui_weak_ptr_, |
715 StartFileUploadParams(local_file_path, | 715 StartFileUploadParams(local_file_path, |
716 remote_dest_file_path, | 716 remote_dest_file_path, |
717 callback), | 717 callback), |
718 base::Owned(error), | 718 base::Owned(error), |
719 base::Owned(file_size), | 719 base::Owned(file_size), |
720 base::Owned(content_type))); | 720 base::Owned(content_type))); |
721 } | 721 } |
722 | 722 |
723 void GDataFileSystem::StartFileUploadOnUIThread( | 723 void DriveFileSystem::StartFileUploadOnUIThread( |
724 const StartFileUploadParams& params, | 724 const StartFileUploadParams& params, |
725 DriveFileError* error, | 725 DriveFileError* error, |
726 int64* file_size, | 726 int64* file_size, |
727 std::string* content_type) { | 727 std::string* content_type) { |
728 // This method needs to run on the UI thread as required by | 728 // This method needs to run on the UI thread as required by |
729 // GDataUploader::UploadNewFile(). | 729 // GDataUploader::UploadNewFile(). |
730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
731 DCHECK(error); | 731 DCHECK(error); |
732 DCHECK(file_size); | 732 DCHECK(file_size); |
733 DCHECK(content_type); | 733 DCHECK(content_type); |
734 | 734 |
735 if (*error != DRIVE_FILE_OK) { | 735 if (*error != DRIVE_FILE_OK) { |
736 if (!params.callback.is_null()) | 736 if (!params.callback.is_null()) |
737 params.callback.Run(*error); | 737 params.callback.Run(*error); |
738 | 738 |
739 return; | 739 return; |
740 } | 740 } |
741 | 741 |
742 // Make sure the destination directory exists. | 742 // Make sure the destination directory exists. |
743 resource_metadata_->GetEntryInfoByPath( | 743 resource_metadata_->GetEntryInfoByPath( |
744 params.remote_file_path.DirName(), | 744 params.remote_file_path.DirName(), |
745 base::Bind( | 745 base::Bind( |
746 &GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo, | 746 &DriveFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo, |
747 ui_weak_ptr_, | 747 ui_weak_ptr_, |
748 params, | 748 params, |
749 *file_size, | 749 *file_size, |
750 *content_type)); | 750 *content_type)); |
751 } | 751 } |
752 | 752 |
753 void GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo( | 753 void DriveFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo( |
754 const StartFileUploadParams& params, | 754 const StartFileUploadParams& params, |
755 int64 file_size, | 755 int64 file_size, |
756 std::string content_type, | 756 std::string content_type, |
757 DriveFileError error, | 757 DriveFileError error, |
758 scoped_ptr<DriveEntryProto> entry_proto) { | 758 scoped_ptr<DriveEntryProto> entry_proto) { |
759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
760 | 760 |
761 if (entry_proto.get() && !entry_proto->file_info().is_directory()) | 761 if (entry_proto.get() && !entry_proto->file_info().is_directory()) |
762 error = DRIVE_FILE_ERROR_NOT_A_DIRECTORY; | 762 error = DRIVE_FILE_ERROR_NOT_A_DIRECTORY; |
763 | 763 |
(...skipping 11 matching lines...) Expand all Loading... |
775 upload_file_info->gdata_path = params.remote_file_path; | 775 upload_file_info->gdata_path = params.remote_file_path; |
776 // Use the file name as the title. | 776 // Use the file name as the title. |
777 upload_file_info->title = params.remote_file_path.BaseName().value(); | 777 upload_file_info->title = params.remote_file_path.BaseName().value(); |
778 upload_file_info->content_length = file_size; | 778 upload_file_info->content_length = file_size; |
779 upload_file_info->all_bytes_present = true; | 779 upload_file_info->all_bytes_present = true; |
780 upload_file_info->content_type = content_type; | 780 upload_file_info->content_type = content_type; |
781 upload_file_info->initial_upload_location = GURL(entry_proto->upload_url()); | 781 upload_file_info->initial_upload_location = GURL(entry_proto->upload_url()); |
782 upload_file_info->upload_mode = UPLOAD_NEW_FILE; | 782 upload_file_info->upload_mode = UPLOAD_NEW_FILE; |
783 | 783 |
784 upload_file_info->completion_callback = | 784 upload_file_info->completion_callback = |
785 base::Bind(&GDataFileSystem::OnTransferCompleted, | 785 base::Bind(&DriveFileSystem::OnTransferCompleted, |
786 ui_weak_ptr_, | 786 ui_weak_ptr_, |
787 params.callback); | 787 params.callback); |
788 | 788 |
789 uploader_->UploadNewFile(upload_file_info.Pass()); | 789 uploader_->UploadNewFile(upload_file_info.Pass()); |
790 } | 790 } |
791 | 791 |
792 void GDataFileSystem::OnTransferCompleted( | 792 void DriveFileSystem::OnTransferCompleted( |
793 const FileOperationCallback& callback, | 793 const FileOperationCallback& callback, |
794 DriveFileError error, | 794 DriveFileError error, |
795 scoped_ptr<UploadFileInfo> upload_file_info) { | 795 scoped_ptr<UploadFileInfo> upload_file_info) { |
796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
797 DCHECK(upload_file_info.get()); | 797 DCHECK(upload_file_info.get()); |
798 | 798 |
799 if (error == DRIVE_FILE_OK && upload_file_info->entry.get()) { | 799 if (error == DRIVE_FILE_OK && upload_file_info->entry.get()) { |
800 AddUploadedFile(UPLOAD_NEW_FILE, | 800 AddUploadedFile(UPLOAD_NEW_FILE, |
801 upload_file_info->gdata_path.DirName(), | 801 upload_file_info->gdata_path.DirName(), |
802 upload_file_info->entry.Pass(), | 802 upload_file_info->entry.Pass(), |
803 upload_file_info->file_path, | 803 upload_file_info->file_path, |
804 DriveCache::FILE_OPERATION_COPY, | 804 DriveCache::FILE_OPERATION_COPY, |
805 base::Bind(&OnAddUploadFileCompleted, callback, error)); | 805 base::Bind(&OnAddUploadFileCompleted, callback, error)); |
806 } else if (!callback.is_null()) { | 806 } else if (!callback.is_null()) { |
807 callback.Run(error); | 807 callback.Run(error); |
808 } | 808 } |
809 } | 809 } |
810 | 810 |
811 void GDataFileSystem::Copy(const FilePath& src_file_path, | 811 void DriveFileSystem::Copy(const FilePath& src_file_path, |
812 const FilePath& dest_file_path, | 812 const FilePath& dest_file_path, |
813 const FileOperationCallback& callback) { | 813 const FileOperationCallback& callback) { |
814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
815 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 815 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
816 DCHECK(!callback.is_null()); | 816 DCHECK(!callback.is_null()); |
817 | 817 |
818 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread, | 818 RunTaskOnUIThread(base::Bind(&DriveFileSystem::CopyOnUIThread, |
819 ui_weak_ptr_, | 819 ui_weak_ptr_, |
820 src_file_path, | 820 src_file_path, |
821 dest_file_path, | 821 dest_file_path, |
822 CreateRelayCallback(callback))); | 822 CreateRelayCallback(callback))); |
823 } | 823 } |
824 | 824 |
825 void GDataFileSystem::CopyOnUIThread(const FilePath& src_file_path, | 825 void DriveFileSystem::CopyOnUIThread(const FilePath& src_file_path, |
826 const FilePath& dest_file_path, | 826 const FilePath& dest_file_path, |
827 const FileOperationCallback& callback) { | 827 const FileOperationCallback& callback) { |
828 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 828 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
829 DCHECK(!callback.is_null()); | 829 DCHECK(!callback.is_null()); |
830 | 830 |
831 resource_metadata_->GetEntryInfoPairByPaths( | 831 resource_metadata_->GetEntryInfoPairByPaths( |
832 src_file_path, | 832 src_file_path, |
833 dest_file_path.DirName(), | 833 dest_file_path.DirName(), |
834 base::Bind(&GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair, | 834 base::Bind(&DriveFileSystem::CopyOnUIThreadAfterGetEntryInfoPair, |
835 ui_weak_ptr_, | 835 ui_weak_ptr_, |
836 dest_file_path, | 836 dest_file_path, |
837 callback)); | 837 callback)); |
838 } | 838 } |
839 | 839 |
840 void GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair( | 840 void DriveFileSystem::CopyOnUIThreadAfterGetEntryInfoPair( |
841 const FilePath& dest_file_path, | 841 const FilePath& dest_file_path, |
842 const FileOperationCallback& callback, | 842 const FileOperationCallback& callback, |
843 scoped_ptr<EntryInfoPairResult> result) { | 843 scoped_ptr<EntryInfoPairResult> result) { |
844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
845 DCHECK(!callback.is_null()); | 845 DCHECK(!callback.is_null()); |
846 DCHECK(result.get()); | 846 DCHECK(result.get()); |
847 | 847 |
848 if (result->first.error != DRIVE_FILE_OK) { | 848 if (result->first.error != DRIVE_FILE_OK) { |
849 callback.Run(result->first.error); | 849 callback.Run(result->first.error); |
850 return; | 850 return; |
(...skipping 23 matching lines...) Expand all Loading... |
874 // in the document title. | 874 // in the document title. |
875 dest_file_path.BaseName().RemoveExtension().value(), | 875 dest_file_path.BaseName().RemoveExtension().value(), |
876 callback); | 876 callback); |
877 return; | 877 return; |
878 } | 878 } |
879 | 879 |
880 // TODO(kochi): Reimplement this once the server API supports | 880 // TODO(kochi): Reimplement this once the server API supports |
881 // copying of regular files directly on the server side. crbug.com/138273 | 881 // copying of regular files directly on the server side. crbug.com/138273 |
882 const FilePath& src_file_path = result->first.path; | 882 const FilePath& src_file_path = result->first.path; |
883 GetFileByPath(src_file_path, | 883 GetFileByPath(src_file_path, |
884 base::Bind(&GDataFileSystem::OnGetFileCompleteForCopy, | 884 base::Bind(&DriveFileSystem::OnGetFileCompleteForCopy, |
885 ui_weak_ptr_, | 885 ui_weak_ptr_, |
886 dest_file_path, | 886 dest_file_path, |
887 callback), | 887 callback), |
888 GetContentCallback()); | 888 GetContentCallback()); |
889 } | 889 } |
890 | 890 |
891 void GDataFileSystem::OnGetFileCompleteForCopy( | 891 void DriveFileSystem::OnGetFileCompleteForCopy( |
892 const FilePath& remote_dest_file_path, | 892 const FilePath& remote_dest_file_path, |
893 const FileOperationCallback& callback, | 893 const FileOperationCallback& callback, |
894 DriveFileError error, | 894 DriveFileError error, |
895 const FilePath& local_file_path, | 895 const FilePath& local_file_path, |
896 const std::string& unused_mime_type, | 896 const std::string& unused_mime_type, |
897 DriveFileType file_type) { | 897 DriveFileType file_type) { |
898 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 898 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
899 DCHECK(!callback.is_null()); | 899 DCHECK(!callback.is_null()); |
900 | 900 |
901 if (error != DRIVE_FILE_OK) { | 901 if (error != DRIVE_FILE_OK) { |
902 callback.Run(error); | 902 callback.Run(error); |
903 return; | 903 return; |
904 } | 904 } |
905 | 905 |
906 // This callback is only triggered for a regular file via Copy(). | 906 // This callback is only triggered for a regular file via Copy(). |
907 DCHECK_EQ(REGULAR_FILE, file_type); | 907 DCHECK_EQ(REGULAR_FILE, file_type); |
908 TransferRegularFile(local_file_path, remote_dest_file_path, callback); | 908 TransferRegularFile(local_file_path, remote_dest_file_path, callback); |
909 } | 909 } |
910 | 910 |
911 void GDataFileSystem::OnGetFileCompleteForTransferFile( | 911 void DriveFileSystem::OnGetFileCompleteForTransferFile( |
912 const FilePath& local_dest_file_path, | 912 const FilePath& local_dest_file_path, |
913 const FileOperationCallback& callback, | 913 const FileOperationCallback& callback, |
914 DriveFileError error, | 914 DriveFileError error, |
915 const FilePath& local_file_path, | 915 const FilePath& local_file_path, |
916 const std::string& unused_mime_type, | 916 const std::string& unused_mime_type, |
917 DriveFileType file_type) { | 917 DriveFileType file_type) { |
918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
919 DCHECK(!callback.is_null()); | 919 DCHECK(!callback.is_null()); |
920 | 920 |
921 if (error != DRIVE_FILE_OK) { | 921 if (error != DRIVE_FILE_OK) { |
(...skipping 11 matching lines...) Expand all Loading... |
933 blocking_task_runner_, | 933 blocking_task_runner_, |
934 base::Bind(&CopyLocalFileOnBlockingPool, | 934 base::Bind(&CopyLocalFileOnBlockingPool, |
935 local_file_path, | 935 local_file_path, |
936 local_dest_file_path, | 936 local_dest_file_path, |
937 copy_file_error), | 937 copy_file_error), |
938 base::Bind(&RunFileOperationCallbackHelper, | 938 base::Bind(&RunFileOperationCallbackHelper, |
939 callback, | 939 callback, |
940 base::Owned(copy_file_error))); | 940 base::Owned(copy_file_error))); |
941 } | 941 } |
942 | 942 |
943 void GDataFileSystem::CopyDocumentToDirectory( | 943 void DriveFileSystem::CopyDocumentToDirectory( |
944 const FilePath& dir_path, | 944 const FilePath& dir_path, |
945 const std::string& resource_id, | 945 const std::string& resource_id, |
946 const FilePath::StringType& new_name, | 946 const FilePath::StringType& new_name, |
947 const FileOperationCallback& callback) { | 947 const FileOperationCallback& callback) { |
948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
949 DCHECK(!callback.is_null()); | 949 DCHECK(!callback.is_null()); |
950 | 950 |
951 drive_service_->CopyDocument(resource_id, new_name, | 951 drive_service_->CopyDocument(resource_id, new_name, |
952 base::Bind(&GDataFileSystem::OnCopyDocumentCompleted, | 952 base::Bind(&DriveFileSystem::OnCopyDocumentCompleted, |
953 ui_weak_ptr_, | 953 ui_weak_ptr_, |
954 dir_path, | 954 dir_path, |
955 callback)); | 955 callback)); |
956 } | 956 } |
957 | 957 |
958 void GDataFileSystem::Rename(const FilePath& file_path, | 958 void DriveFileSystem::Rename(const FilePath& file_path, |
959 const FilePath::StringType& new_name, | 959 const FilePath::StringType& new_name, |
960 const FileMoveCallback& callback) { | 960 const FileMoveCallback& callback) { |
961 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 961 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
962 DCHECK(!callback.is_null()); | 962 DCHECK(!callback.is_null()); |
963 | 963 |
964 // It is a no-op if the file is renamed to the same name. | 964 // It is a no-op if the file is renamed to the same name. |
965 if (file_path.BaseName().value() == new_name) { | 965 if (file_path.BaseName().value() == new_name) { |
966 callback.Run(DRIVE_FILE_OK, file_path); | 966 callback.Run(DRIVE_FILE_OK, file_path); |
967 return; | 967 return; |
968 } | 968 } |
969 | 969 |
970 // Get the edit URL of an entry at |file_path|. | 970 // Get the edit URL of an entry at |file_path|. |
971 resource_metadata_->GetEntryInfoByPath( | 971 resource_metadata_->GetEntryInfoByPath( |
972 file_path, | 972 file_path, |
973 base::Bind( | 973 base::Bind( |
974 &GDataFileSystem::RenameAfterGetEntryInfo, | 974 &DriveFileSystem::RenameAfterGetEntryInfo, |
975 ui_weak_ptr_, | 975 ui_weak_ptr_, |
976 file_path, | 976 file_path, |
977 new_name, | 977 new_name, |
978 callback)); | 978 callback)); |
979 } | 979 } |
980 | 980 |
981 void GDataFileSystem::RenameAfterGetEntryInfo( | 981 void DriveFileSystem::RenameAfterGetEntryInfo( |
982 const FilePath& file_path, | 982 const FilePath& file_path, |
983 const FilePath::StringType& new_name, | 983 const FilePath::StringType& new_name, |
984 const FileMoveCallback& callback, | 984 const FileMoveCallback& callback, |
985 DriveFileError error, | 985 DriveFileError error, |
986 scoped_ptr<DriveEntryProto> entry_proto) { | 986 scoped_ptr<DriveEntryProto> entry_proto) { |
987 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 987 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
988 | 988 |
989 if (error != DRIVE_FILE_OK) { | 989 if (error != DRIVE_FILE_OK) { |
990 if (!callback.is_null()) | 990 if (!callback.is_null()) |
991 callback.Run(error, file_path); | 991 callback.Run(error, file_path); |
(...skipping 10 matching lines...) Expand all Loading... |
1002 FilePath new_file(file_name); | 1002 FilePath new_file(file_name); |
1003 if (new_file.Extension() == | 1003 if (new_file.Extension() == |
1004 entry_proto->file_specific_info().document_extension()) { | 1004 entry_proto->file_specific_info().document_extension()) { |
1005 file_name = new_file.RemoveExtension().value(); | 1005 file_name = new_file.RemoveExtension().value(); |
1006 } | 1006 } |
1007 } | 1007 } |
1008 | 1008 |
1009 drive_service_->RenameResource( | 1009 drive_service_->RenameResource( |
1010 GURL(entry_proto->edit_url()), | 1010 GURL(entry_proto->edit_url()), |
1011 file_name, | 1011 file_name, |
1012 base::Bind(&GDataFileSystem::RenameEntryLocally, | 1012 base::Bind(&DriveFileSystem::RenameEntryLocally, |
1013 ui_weak_ptr_, | 1013 ui_weak_ptr_, |
1014 file_path, | 1014 file_path, |
1015 file_name, | 1015 file_name, |
1016 callback)); | 1016 callback)); |
1017 } | 1017 } |
1018 | 1018 |
1019 void GDataFileSystem::Move(const FilePath& src_file_path, | 1019 void DriveFileSystem::Move(const FilePath& src_file_path, |
1020 const FilePath& dest_file_path, | 1020 const FilePath& dest_file_path, |
1021 const FileOperationCallback& callback) { | 1021 const FileOperationCallback& callback) { |
1022 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1022 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1023 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1023 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1024 DCHECK(!callback.is_null()); | 1024 DCHECK(!callback.is_null()); |
1025 | 1025 |
1026 RunTaskOnUIThread(base::Bind(&GDataFileSystem::MoveOnUIThread, | 1026 RunTaskOnUIThread(base::Bind(&DriveFileSystem::MoveOnUIThread, |
1027 ui_weak_ptr_, | 1027 ui_weak_ptr_, |
1028 src_file_path, | 1028 src_file_path, |
1029 dest_file_path, | 1029 dest_file_path, |
1030 CreateRelayCallback(callback))); | 1030 CreateRelayCallback(callback))); |
1031 } | 1031 } |
1032 | 1032 |
1033 void GDataFileSystem::MoveOnUIThread(const FilePath& src_file_path, | 1033 void DriveFileSystem::MoveOnUIThread(const FilePath& src_file_path, |
1034 const FilePath& dest_file_path, | 1034 const FilePath& dest_file_path, |
1035 const FileOperationCallback& callback) { | 1035 const FileOperationCallback& callback) { |
1036 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1036 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1037 DCHECK(!callback.is_null()); | 1037 DCHECK(!callback.is_null()); |
1038 | 1038 |
1039 resource_metadata_->GetEntryInfoPairByPaths( | 1039 resource_metadata_->GetEntryInfoPairByPaths( |
1040 src_file_path, | 1040 src_file_path, |
1041 dest_file_path.DirName(), | 1041 dest_file_path.DirName(), |
1042 base::Bind(&GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair, | 1042 base::Bind(&DriveFileSystem::MoveOnUIThreadAfterGetEntryInfoPair, |
1043 ui_weak_ptr_, | 1043 ui_weak_ptr_, |
1044 dest_file_path, | 1044 dest_file_path, |
1045 callback)); | 1045 callback)); |
1046 } | 1046 } |
1047 | 1047 |
1048 void GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair( | 1048 void DriveFileSystem::MoveOnUIThreadAfterGetEntryInfoPair( |
1049 const FilePath& dest_file_path, | 1049 const FilePath& dest_file_path, |
1050 const FileOperationCallback& callback, | 1050 const FileOperationCallback& callback, |
1051 scoped_ptr<EntryInfoPairResult> result) { | 1051 scoped_ptr<EntryInfoPairResult> result) { |
1052 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1052 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1053 DCHECK(!callback.is_null()); | 1053 DCHECK(!callback.is_null()); |
1054 DCHECK(result.get()); | 1054 DCHECK(result.get()); |
1055 | 1055 |
1056 if (result->first.error != DRIVE_FILE_OK) { | 1056 if (result->first.error != DRIVE_FILE_OK) { |
1057 callback.Run(result->first.error); | 1057 callback.Run(result->first.error); |
1058 return; | 1058 return; |
1059 } else if (result->second.error != DRIVE_FILE_OK) { | 1059 } else if (result->second.error != DRIVE_FILE_OK) { |
1060 callback.Run(result->second.error); | 1060 callback.Run(result->second.error); |
1061 return; | 1061 return; |
1062 } | 1062 } |
1063 | 1063 |
1064 scoped_ptr<DriveEntryProto> dest_parent_proto = result->second.proto.Pass(); | 1064 scoped_ptr<DriveEntryProto> dest_parent_proto = result->second.proto.Pass(); |
1065 if (!dest_parent_proto->file_info().is_directory()) { | 1065 if (!dest_parent_proto->file_info().is_directory()) { |
1066 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); | 1066 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); |
1067 return; | 1067 return; |
1068 } | 1068 } |
1069 | 1069 |
1070 // If the file/directory is moved to the same directory, just rename it. | 1070 // If the file/directory is moved to the same directory, just rename it. |
1071 const FilePath& src_file_path = result->first.path; | 1071 const FilePath& src_file_path = result->first.path; |
1072 const FilePath& dest_parent_path = result->second.path; | 1072 const FilePath& dest_parent_path = result->second.path; |
1073 if (src_file_path.DirName() == dest_parent_path) { | 1073 if (src_file_path.DirName() == dest_parent_path) { |
1074 FileMoveCallback final_file_path_update_callback = | 1074 FileMoveCallback final_file_path_update_callback = |
1075 base::Bind(&GDataFileSystem::OnFilePathUpdated, | 1075 base::Bind(&DriveFileSystem::OnFilePathUpdated, |
1076 ui_weak_ptr_, | 1076 ui_weak_ptr_, |
1077 callback); | 1077 callback); |
1078 | 1078 |
1079 Rename(src_file_path, dest_file_path.BaseName().value(), | 1079 Rename(src_file_path, dest_file_path.BaseName().value(), |
1080 final_file_path_update_callback); | 1080 final_file_path_update_callback); |
1081 return; | 1081 return; |
1082 } | 1082 } |
1083 | 1083 |
1084 // Otherwise, the move operation involves three steps: | 1084 // Otherwise, the move operation involves three steps: |
1085 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|) | 1085 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|) |
1086 // within the same directory. The rename operation is a no-op if | 1086 // within the same directory. The rename operation is a no-op if |
1087 // basename(|src_file_path|) equals to basename(|dest_file_path|). | 1087 // basename(|src_file_path|) equals to basename(|dest_file_path|). |
1088 // 2. Removes the file from its parent directory (the file is not deleted), | 1088 // 2. Removes the file from its parent directory (the file is not deleted), |
1089 // which effectively moves the file to the root directory. | 1089 // which effectively moves the file to the root directory. |
1090 // 3. Adds the file to the parent directory of |dest_file_path|, which | 1090 // 3. Adds the file to the parent directory of |dest_file_path|, which |
1091 // effectively moves the file from the root directory to the parent | 1091 // effectively moves the file from the root directory to the parent |
1092 // directory of |dest_file_path|. | 1092 // directory of |dest_file_path|. |
1093 const FileMoveCallback add_file_to_directory_callback = | 1093 const FileMoveCallback add_file_to_directory_callback = |
1094 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, | 1094 base::Bind(&DriveFileSystem::MoveEntryFromRootDirectory, |
1095 ui_weak_ptr_, | 1095 ui_weak_ptr_, |
1096 dest_file_path.DirName(), | 1096 dest_file_path.DirName(), |
1097 callback); | 1097 callback); |
1098 | 1098 |
1099 const FileMoveCallback remove_file_from_directory_callback = | 1099 const FileMoveCallback remove_file_from_directory_callback = |
1100 base::Bind(&GDataFileSystem::RemoveEntryFromNonRootDirectory, | 1100 base::Bind(&DriveFileSystem::RemoveEntryFromNonRootDirectory, |
1101 ui_weak_ptr_, | 1101 ui_weak_ptr_, |
1102 add_file_to_directory_callback); | 1102 add_file_to_directory_callback); |
1103 | 1103 |
1104 Rename(src_file_path, dest_file_path.BaseName().value(), | 1104 Rename(src_file_path, dest_file_path.BaseName().value(), |
1105 remove_file_from_directory_callback); | 1105 remove_file_from_directory_callback); |
1106 } | 1106 } |
1107 | 1107 |
1108 void GDataFileSystem::MoveEntryFromRootDirectory( | 1108 void DriveFileSystem::MoveEntryFromRootDirectory( |
1109 const FilePath& dir_path, | 1109 const FilePath& dir_path, |
1110 const FileOperationCallback& callback, | 1110 const FileOperationCallback& callback, |
1111 DriveFileError error, | 1111 DriveFileError error, |
1112 const FilePath& file_path) { | 1112 const FilePath& file_path) { |
1113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1114 DCHECK(!callback.is_null()); | 1114 DCHECK(!callback.is_null()); |
1115 DCHECK_EQ(kDriveRootDirectory, file_path.DirName().value()); | 1115 DCHECK_EQ(kDriveRootDirectory, file_path.DirName().value()); |
1116 | 1116 |
1117 // Return if there is an error or |dir_path| is the root directory. | 1117 // Return if there is an error or |dir_path| is the root directory. |
1118 if (error != DRIVE_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) { | 1118 if (error != DRIVE_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) { |
1119 callback.Run(error); | 1119 callback.Run(error); |
1120 return; | 1120 return; |
1121 } | 1121 } |
1122 | 1122 |
1123 resource_metadata_->GetEntryInfoPairByPaths( | 1123 resource_metadata_->GetEntryInfoPairByPaths( |
1124 file_path, | 1124 file_path, |
1125 dir_path, | 1125 dir_path, |
1126 base::Bind( | 1126 base::Bind( |
1127 &GDataFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair, | 1127 &DriveFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair, |
1128 ui_weak_ptr_, | 1128 ui_weak_ptr_, |
1129 callback)); | 1129 callback)); |
1130 } | 1130 } |
1131 | 1131 |
1132 void GDataFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair( | 1132 void DriveFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair( |
1133 const FileOperationCallback& callback, | 1133 const FileOperationCallback& callback, |
1134 scoped_ptr<EntryInfoPairResult> result) { | 1134 scoped_ptr<EntryInfoPairResult> result) { |
1135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1136 DCHECK(!callback.is_null()); | 1136 DCHECK(!callback.is_null()); |
1137 DCHECK(result.get()); | 1137 DCHECK(result.get()); |
1138 | 1138 |
1139 if (result->first.error != DRIVE_FILE_OK) { | 1139 if (result->first.error != DRIVE_FILE_OK) { |
1140 callback.Run(result->first.error); | 1140 callback.Run(result->first.error); |
1141 return; | 1141 return; |
1142 } else if (result->second.error != DRIVE_FILE_OK) { | 1142 } else if (result->second.error != DRIVE_FILE_OK) { |
1143 callback.Run(result->second.error); | 1143 callback.Run(result->second.error); |
1144 return; | 1144 return; |
1145 } | 1145 } |
1146 | 1146 |
1147 scoped_ptr<DriveEntryProto> src_proto = result->first.proto.Pass(); | 1147 scoped_ptr<DriveEntryProto> src_proto = result->first.proto.Pass(); |
1148 scoped_ptr<DriveEntryProto> dir_proto = result->second.proto.Pass(); | 1148 scoped_ptr<DriveEntryProto> dir_proto = result->second.proto.Pass(); |
1149 | 1149 |
1150 if (!dir_proto->file_info().is_directory()) { | 1150 if (!dir_proto->file_info().is_directory()) { |
1151 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); | 1151 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); |
1152 return; | 1152 return; |
1153 } | 1153 } |
1154 | 1154 |
1155 const FilePath& file_path = result->first.path; | 1155 const FilePath& file_path = result->first.path; |
1156 const FilePath& dir_path = result->second.path; | 1156 const FilePath& dir_path = result->second.path; |
1157 drive_service_->AddResourceToDirectory( | 1157 drive_service_->AddResourceToDirectory( |
1158 GURL(dir_proto->content_url()), | 1158 GURL(dir_proto->content_url()), |
1159 GURL(src_proto->edit_url()), | 1159 GURL(src_proto->edit_url()), |
1160 base::Bind(&GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted, | 1160 base::Bind(&DriveFileSystem::OnMoveEntryFromRootDirectoryCompleted, |
1161 ui_weak_ptr_, | 1161 ui_weak_ptr_, |
1162 callback, | 1162 callback, |
1163 file_path, | 1163 file_path, |
1164 dir_path)); | 1164 dir_path)); |
1165 } | 1165 } |
1166 | 1166 |
1167 void GDataFileSystem::RemoveEntryFromNonRootDirectory( | 1167 void DriveFileSystem::RemoveEntryFromNonRootDirectory( |
1168 const FileMoveCallback& callback, | 1168 const FileMoveCallback& callback, |
1169 DriveFileError error, | 1169 DriveFileError error, |
1170 const FilePath& file_path) { | 1170 const FilePath& file_path) { |
1171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1172 DCHECK(!callback.is_null()); | 1172 DCHECK(!callback.is_null()); |
1173 | 1173 |
1174 const FilePath dir_path = file_path.DirName(); | 1174 const FilePath dir_path = file_path.DirName(); |
1175 // Return if there is an error or |dir_path| is the root directory. | 1175 // Return if there is an error or |dir_path| is the root directory. |
1176 if (error != DRIVE_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) { | 1176 if (error != DRIVE_FILE_OK || dir_path == FilePath(kDriveRootDirectory)) { |
1177 callback.Run(error, file_path); | 1177 callback.Run(error, file_path); |
1178 return; | 1178 return; |
1179 } | 1179 } |
1180 | 1180 |
1181 resource_metadata_->GetEntryInfoPairByPaths( | 1181 resource_metadata_->GetEntryInfoPairByPaths( |
1182 file_path, | 1182 file_path, |
1183 dir_path, | 1183 dir_path, |
1184 base::Bind( | 1184 base::Bind( |
1185 &GDataFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair, | 1185 &DriveFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair, |
1186 ui_weak_ptr_, | 1186 ui_weak_ptr_, |
1187 callback)); | 1187 callback)); |
1188 } | 1188 } |
1189 | 1189 |
1190 void GDataFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair( | 1190 void DriveFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair( |
1191 const FileMoveCallback& callback, | 1191 const FileMoveCallback& callback, |
1192 scoped_ptr<EntryInfoPairResult> result) { | 1192 scoped_ptr<EntryInfoPairResult> result) { |
1193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1194 DCHECK(!callback.is_null()); | 1194 DCHECK(!callback.is_null()); |
1195 DCHECK(result.get()); | 1195 DCHECK(result.get()); |
1196 | 1196 |
1197 const FilePath& file_path = result->first.path; | 1197 const FilePath& file_path = result->first.path; |
1198 const FilePath& dir_path = result->second.path; | 1198 const FilePath& dir_path = result->second.path; |
1199 if (result->first.error != DRIVE_FILE_OK) { | 1199 if (result->first.error != DRIVE_FILE_OK) { |
1200 callback.Run(result->first.error, file_path); | 1200 callback.Run(result->first.error, file_path); |
1201 return; | 1201 return; |
1202 } else if (result->second.error != DRIVE_FILE_OK) { | 1202 } else if (result->second.error != DRIVE_FILE_OK) { |
1203 callback.Run(result->second.error, file_path); | 1203 callback.Run(result->second.error, file_path); |
1204 return; | 1204 return; |
1205 } | 1205 } |
1206 | 1206 |
1207 scoped_ptr<DriveEntryProto> entry_proto = result->first.proto.Pass(); | 1207 scoped_ptr<DriveEntryProto> entry_proto = result->first.proto.Pass(); |
1208 scoped_ptr<DriveEntryProto> dir_proto = result->second.proto.Pass(); | 1208 scoped_ptr<DriveEntryProto> dir_proto = result->second.proto.Pass(); |
1209 | 1209 |
1210 if (!dir_proto->file_info().is_directory()) { | 1210 if (!dir_proto->file_info().is_directory()) { |
1211 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, file_path); | 1211 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, file_path); |
1212 return; | 1212 return; |
1213 } | 1213 } |
1214 | 1214 |
1215 drive_service_->RemoveResourceFromDirectory( | 1215 drive_service_->RemoveResourceFromDirectory( |
1216 GURL(dir_proto->content_url()), | 1216 GURL(dir_proto->content_url()), |
1217 GURL(entry_proto->edit_url()), | 1217 GURL(entry_proto->edit_url()), |
1218 entry_proto->resource_id(), | 1218 entry_proto->resource_id(), |
1219 base::Bind(&GDataFileSystem::MoveEntryToRootDirectoryLocally, | 1219 base::Bind(&DriveFileSystem::MoveEntryToRootDirectoryLocally, |
1220 ui_weak_ptr_, | 1220 ui_weak_ptr_, |
1221 callback, | 1221 callback, |
1222 file_path, | 1222 file_path, |
1223 dir_path)); | 1223 dir_path)); |
1224 } | 1224 } |
1225 | 1225 |
1226 void GDataFileSystem::Remove(const FilePath& file_path, | 1226 void DriveFileSystem::Remove(const FilePath& file_path, |
1227 bool is_recursive, | 1227 bool is_recursive, |
1228 const FileOperationCallback& callback) { | 1228 const FileOperationCallback& callback) { |
1229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1230 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1230 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1231 RunTaskOnUIThread(base::Bind(&GDataFileSystem::RemoveOnUIThread, | 1231 RunTaskOnUIThread(base::Bind(&DriveFileSystem::RemoveOnUIThread, |
1232 ui_weak_ptr_, | 1232 ui_weak_ptr_, |
1233 file_path, | 1233 file_path, |
1234 is_recursive, | 1234 is_recursive, |
1235 CreateRelayCallback(callback))); | 1235 CreateRelayCallback(callback))); |
1236 } | 1236 } |
1237 | 1237 |
1238 void GDataFileSystem::RemoveOnUIThread( | 1238 void DriveFileSystem::RemoveOnUIThread( |
1239 const FilePath& file_path, | 1239 const FilePath& file_path, |
1240 bool is_recursive, | 1240 bool is_recursive, |
1241 const FileOperationCallback& callback) { | 1241 const FileOperationCallback& callback) { |
1242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1243 | 1243 |
1244 // Get the edit URL of an entry at |file_path|. | 1244 // Get the edit URL of an entry at |file_path|. |
1245 resource_metadata_->GetEntryInfoByPath( | 1245 resource_metadata_->GetEntryInfoByPath( |
1246 file_path, | 1246 file_path, |
1247 base::Bind( | 1247 base::Bind( |
1248 &GDataFileSystem::RemoveOnUIThreadAfterGetEntryInfo, | 1248 &DriveFileSystem::RemoveOnUIThreadAfterGetEntryInfo, |
1249 ui_weak_ptr_, | 1249 ui_weak_ptr_, |
1250 file_path, | 1250 file_path, |
1251 is_recursive, | 1251 is_recursive, |
1252 callback)); | 1252 callback)); |
1253 } | 1253 } |
1254 | 1254 |
1255 void GDataFileSystem::RemoveOnUIThreadAfterGetEntryInfo( | 1255 void DriveFileSystem::RemoveOnUIThreadAfterGetEntryInfo( |
1256 const FilePath& file_path, | 1256 const FilePath& file_path, |
1257 bool /* is_recursive */, | 1257 bool /* is_recursive */, |
1258 const FileOperationCallback& callback, | 1258 const FileOperationCallback& callback, |
1259 DriveFileError error, | 1259 DriveFileError error, |
1260 scoped_ptr<DriveEntryProto> entry_proto) { | 1260 scoped_ptr<DriveEntryProto> entry_proto) { |
1261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1262 | 1262 |
1263 if (error != DRIVE_FILE_OK) { | 1263 if (error != DRIVE_FILE_OK) { |
1264 if (!callback.is_null()) { | 1264 if (!callback.is_null()) { |
1265 base::MessageLoopProxy::current()->PostTask( | 1265 base::MessageLoopProxy::current()->PostTask( |
1266 FROM_HERE, base::Bind(callback, error)); | 1266 FROM_HERE, base::Bind(callback, error)); |
1267 } | 1267 } |
1268 return; | 1268 return; |
1269 } | 1269 } |
1270 | 1270 |
1271 DCHECK(entry_proto.get()); | 1271 DCHECK(entry_proto.get()); |
1272 drive_service_->DeleteDocument( | 1272 drive_service_->DeleteDocument( |
1273 GURL(entry_proto->edit_url()), | 1273 GURL(entry_proto->edit_url()), |
1274 base::Bind(&GDataFileSystem::OnRemovedDocument, | 1274 base::Bind(&DriveFileSystem::OnRemovedDocument, |
1275 ui_weak_ptr_, | 1275 ui_weak_ptr_, |
1276 callback, | 1276 callback, |
1277 file_path)); | 1277 file_path)); |
1278 } | 1278 } |
1279 | 1279 |
1280 void GDataFileSystem::CreateDirectory( | 1280 void DriveFileSystem::CreateDirectory( |
1281 const FilePath& directory_path, | 1281 const FilePath& directory_path, |
1282 bool is_exclusive, | 1282 bool is_exclusive, |
1283 bool is_recursive, | 1283 bool is_recursive, |
1284 const FileOperationCallback& callback) { | 1284 const FileOperationCallback& callback) { |
1285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1286 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1286 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1287 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CreateDirectoryOnUIThread, | 1287 RunTaskOnUIThread(base::Bind(&DriveFileSystem::CreateDirectoryOnUIThread, |
1288 ui_weak_ptr_, | 1288 ui_weak_ptr_, |
1289 directory_path, | 1289 directory_path, |
1290 is_exclusive, | 1290 is_exclusive, |
1291 is_recursive, | 1291 is_recursive, |
1292 CreateRelayCallback(callback))); | 1292 CreateRelayCallback(callback))); |
1293 } | 1293 } |
1294 | 1294 |
1295 void GDataFileSystem::CreateDirectoryOnUIThread( | 1295 void DriveFileSystem::CreateDirectoryOnUIThread( |
1296 const FilePath& directory_path, | 1296 const FilePath& directory_path, |
1297 bool is_exclusive, | 1297 bool is_exclusive, |
1298 bool is_recursive, | 1298 bool is_recursive, |
1299 const FileOperationCallback& callback) { | 1299 const FileOperationCallback& callback) { |
1300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1301 | 1301 |
1302 FilePath last_parent_dir_path; | 1302 FilePath last_parent_dir_path; |
1303 FilePath first_missing_path; | 1303 FilePath first_missing_path; |
1304 GURL last_parent_dir_url; | 1304 GURL last_parent_dir_url; |
1305 FindMissingDirectoryResult result = | 1305 FindMissingDirectoryResult result = |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1342 if (!callback.is_null()) { | 1342 if (!callback.is_null()) { |
1343 MessageLoop::current()->PostTask(FROM_HERE, | 1343 MessageLoop::current()->PostTask(FROM_HERE, |
1344 base::Bind(callback, DRIVE_FILE_ERROR_NOT_FOUND)); | 1344 base::Bind(callback, DRIVE_FILE_ERROR_NOT_FOUND)); |
1345 } | 1345 } |
1346 return; | 1346 return; |
1347 } | 1347 } |
1348 | 1348 |
1349 drive_service_->CreateDirectory( | 1349 drive_service_->CreateDirectory( |
1350 last_parent_dir_url, | 1350 last_parent_dir_url, |
1351 first_missing_path.BaseName().value(), | 1351 first_missing_path.BaseName().value(), |
1352 base::Bind(&GDataFileSystem::OnCreateDirectoryCompleted, | 1352 base::Bind(&DriveFileSystem::OnCreateDirectoryCompleted, |
1353 ui_weak_ptr_, | 1353 ui_weak_ptr_, |
1354 CreateDirectoryParams( | 1354 CreateDirectoryParams( |
1355 first_missing_path, | 1355 first_missing_path, |
1356 directory_path, | 1356 directory_path, |
1357 is_exclusive, | 1357 is_exclusive, |
1358 is_recursive, | 1358 is_recursive, |
1359 callback))); | 1359 callback))); |
1360 } | 1360 } |
1361 | 1361 |
1362 void GDataFileSystem::CreateFile(const FilePath& file_path, | 1362 void DriveFileSystem::CreateFile(const FilePath& file_path, |
1363 bool is_exclusive, | 1363 bool is_exclusive, |
1364 const FileOperationCallback& callback) { | 1364 const FileOperationCallback& callback) { |
1365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1366 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1366 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1367 DCHECK(!callback.is_null()); | 1367 DCHECK(!callback.is_null()); |
1368 | 1368 |
1369 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CreateFileOnUIThread, | 1369 RunTaskOnUIThread(base::Bind(&DriveFileSystem::CreateFileOnUIThread, |
1370 ui_weak_ptr_, | 1370 ui_weak_ptr_, |
1371 file_path, | 1371 file_path, |
1372 is_exclusive, | 1372 is_exclusive, |
1373 CreateRelayCallback(callback))); | 1373 CreateRelayCallback(callback))); |
1374 } | 1374 } |
1375 | 1375 |
1376 void GDataFileSystem::CreateFileOnUIThread( | 1376 void DriveFileSystem::CreateFileOnUIThread( |
1377 const FilePath& file_path, | 1377 const FilePath& file_path, |
1378 bool is_exclusive, | 1378 bool is_exclusive, |
1379 const FileOperationCallback& callback) { | 1379 const FileOperationCallback& callback) { |
1380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1381 DCHECK(!callback.is_null()); | 1381 DCHECK(!callback.is_null()); |
1382 | 1382 |
1383 // First, checks the existence of a file at |file_path|. | 1383 // First, checks the existence of a file at |file_path|. |
1384 resource_metadata_->GetEntryInfoByPath( | 1384 resource_metadata_->GetEntryInfoByPath( |
1385 file_path, | 1385 file_path, |
1386 base::Bind(&GDataFileSystem::OnGetEntryInfoForCreateFile, | 1386 base::Bind(&DriveFileSystem::OnGetEntryInfoForCreateFile, |
1387 ui_weak_ptr_, | 1387 ui_weak_ptr_, |
1388 file_path, | 1388 file_path, |
1389 is_exclusive, | 1389 is_exclusive, |
1390 callback)); | 1390 callback)); |
1391 } | 1391 } |
1392 | 1392 |
1393 void GDataFileSystem::OnGetEntryInfoForCreateFile( | 1393 void DriveFileSystem::OnGetEntryInfoForCreateFile( |
1394 const FilePath& file_path, | 1394 const FilePath& file_path, |
1395 bool is_exclusive, | 1395 bool is_exclusive, |
1396 const FileOperationCallback& callback, | 1396 const FileOperationCallback& callback, |
1397 DriveFileError result, | 1397 DriveFileError result, |
1398 scoped_ptr<DriveEntryProto> entry_proto) { | 1398 scoped_ptr<DriveEntryProto> entry_proto) { |
1399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1400 DCHECK(!callback.is_null()); | 1400 DCHECK(!callback.is_null()); |
1401 | 1401 |
1402 // The |file_path| is invalid. It is an error. | 1402 // The |file_path| is invalid. It is an error. |
1403 if (result != DRIVE_FILE_ERROR_NOT_FOUND && | 1403 if (result != DRIVE_FILE_ERROR_NOT_FOUND && |
(...skipping 18 matching lines...) Expand all Loading... |
1422 callback.Run(DRIVE_FILE_OK); | 1422 callback.Run(DRIVE_FILE_OK); |
1423 return; | 1423 return; |
1424 } | 1424 } |
1425 | 1425 |
1426 // No entry found at |file_path|. Let's create a brand new file. | 1426 // No entry found at |file_path|. Let's create a brand new file. |
1427 // For now, it is implemented by uploading an empty file (/dev/null). | 1427 // For now, it is implemented by uploading an empty file (/dev/null). |
1428 // TODO(kinaba): http://crbug.com/135143. Implement in a nicer way. | 1428 // TODO(kinaba): http://crbug.com/135143. Implement in a nicer way. |
1429 TransferRegularFile(FilePath(kEmptyFilePath), file_path, callback); | 1429 TransferRegularFile(FilePath(kEmptyFilePath), file_path, callback); |
1430 } | 1430 } |
1431 | 1431 |
1432 void GDataFileSystem::GetFileByPath( | 1432 void DriveFileSystem::GetFileByPath( |
1433 const FilePath& file_path, | 1433 const FilePath& file_path, |
1434 const GetFileCallback& get_file_callback, | 1434 const GetFileCallback& get_file_callback, |
1435 const GetContentCallback& get_content_callback) { | 1435 const GetContentCallback& get_content_callback) { |
1436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1437 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1437 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1438 RunTaskOnUIThread( | 1438 RunTaskOnUIThread( |
1439 base::Bind(&GDataFileSystem::GetFileByPathOnUIThread, | 1439 base::Bind(&DriveFileSystem::GetFileByPathOnUIThread, |
1440 ui_weak_ptr_, | 1440 ui_weak_ptr_, |
1441 file_path, | 1441 file_path, |
1442 CreateRelayCallback(get_file_callback), | 1442 CreateRelayCallback(get_file_callback), |
1443 CreateRelayCallback(get_content_callback))); | 1443 CreateRelayCallback(get_content_callback))); |
1444 } | 1444 } |
1445 | 1445 |
1446 void GDataFileSystem::GetFileByPathOnUIThread( | 1446 void DriveFileSystem::GetFileByPathOnUIThread( |
1447 const FilePath& file_path, | 1447 const FilePath& file_path, |
1448 const GetFileCallback& get_file_callback, | 1448 const GetFileCallback& get_file_callback, |
1449 const GetContentCallback& get_content_callback) { | 1449 const GetContentCallback& get_content_callback) { |
1450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1451 | 1451 |
1452 resource_metadata_->GetEntryInfoByPath( | 1452 resource_metadata_->GetEntryInfoByPath( |
1453 file_path, | 1453 file_path, |
1454 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForGetFileByPath, | 1454 base::Bind(&DriveFileSystem::OnGetEntryInfoCompleteForGetFileByPath, |
1455 ui_weak_ptr_, | 1455 ui_weak_ptr_, |
1456 file_path, | 1456 file_path, |
1457 CreateRelayCallback(get_file_callback), | 1457 CreateRelayCallback(get_file_callback), |
1458 CreateRelayCallback(get_content_callback))); | 1458 CreateRelayCallback(get_content_callback))); |
1459 } | 1459 } |
1460 | 1460 |
1461 void GDataFileSystem::OnGetEntryInfoCompleteForGetFileByPath( | 1461 void DriveFileSystem::OnGetEntryInfoCompleteForGetFileByPath( |
1462 const FilePath& file_path, | 1462 const FilePath& file_path, |
1463 const GetFileCallback& get_file_callback, | 1463 const GetFileCallback& get_file_callback, |
1464 const GetContentCallback& get_content_callback, | 1464 const GetContentCallback& get_content_callback, |
1465 DriveFileError error, | 1465 DriveFileError error, |
1466 scoped_ptr<DriveEntryProto> entry_proto) { | 1466 scoped_ptr<DriveEntryProto> entry_proto) { |
1467 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1467 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1468 | 1468 |
1469 // If |error| == PLATFORM_FILE_OK then |entry_proto| must be valid. | 1469 // If |error| == PLATFORM_FILE_OK then |entry_proto| must be valid. |
1470 DCHECK(error != DRIVE_FILE_OK || | 1470 DCHECK(error != DRIVE_FILE_OK || |
1471 (entry_proto.get() && !entry_proto->resource_id().empty())); | 1471 (entry_proto.get() && !entry_proto->resource_id().empty())); |
1472 GetResolvedFileByPath(file_path, | 1472 GetResolvedFileByPath(file_path, |
1473 get_file_callback, | 1473 get_file_callback, |
1474 get_content_callback, | 1474 get_content_callback, |
1475 error, | 1475 error, |
1476 entry_proto.get()); | 1476 entry_proto.get()); |
1477 } | 1477 } |
1478 | 1478 |
1479 void GDataFileSystem::GetResolvedFileByPath( | 1479 void DriveFileSystem::GetResolvedFileByPath( |
1480 const FilePath& file_path, | 1480 const FilePath& file_path, |
1481 const GetFileCallback& get_file_callback, | 1481 const GetFileCallback& get_file_callback, |
1482 const GetContentCallback& get_content_callback, | 1482 const GetContentCallback& get_content_callback, |
1483 DriveFileError error, | 1483 DriveFileError error, |
1484 const DriveEntryProto* entry_proto) { | 1484 const DriveEntryProto* entry_proto) { |
1485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1486 | 1486 |
1487 if (entry_proto && !entry_proto->has_file_specific_info()) | 1487 if (entry_proto && !entry_proto->has_file_specific_info()) |
1488 error = DRIVE_FILE_ERROR_NOT_FOUND; | 1488 error = DRIVE_FILE_ERROR_NOT_FOUND; |
1489 | 1489 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 // Returns absolute path of the file if it were cached or to be cached. | 1534 // Returns absolute path of the file if it were cached or to be cached. |
1535 FilePath local_tmp_path = cache_->GetCacheFilePath( | 1535 FilePath local_tmp_path = cache_->GetCacheFilePath( |
1536 entry_proto->resource_id(), | 1536 entry_proto->resource_id(), |
1537 entry_proto->file_specific_info().file_md5(), | 1537 entry_proto->file_specific_info().file_md5(), |
1538 DriveCache::CACHE_TYPE_TMP, | 1538 DriveCache::CACHE_TYPE_TMP, |
1539 DriveCache::CACHED_FILE_FROM_SERVER); | 1539 DriveCache::CACHED_FILE_FROM_SERVER); |
1540 cache_->GetFileOnUIThread( | 1540 cache_->GetFileOnUIThread( |
1541 entry_proto->resource_id(), | 1541 entry_proto->resource_id(), |
1542 entry_proto->file_specific_info().file_md5(), | 1542 entry_proto->file_specific_info().file_md5(), |
1543 base::Bind( | 1543 base::Bind( |
1544 &GDataFileSystem::OnGetFileFromCache, | 1544 &DriveFileSystem::OnGetFileFromCache, |
1545 ui_weak_ptr_, | 1545 ui_weak_ptr_, |
1546 GetFileFromCacheParams( | 1546 GetFileFromCacheParams( |
1547 file_path, | 1547 file_path, |
1548 local_tmp_path, | 1548 local_tmp_path, |
1549 GURL(entry_proto->content_url()), | 1549 GURL(entry_proto->content_url()), |
1550 entry_proto->resource_id(), | 1550 entry_proto->resource_id(), |
1551 entry_proto->file_specific_info().file_md5(), | 1551 entry_proto->file_specific_info().file_md5(), |
1552 entry_proto->file_specific_info().content_mime_type(), | 1552 entry_proto->file_specific_info().content_mime_type(), |
1553 get_file_callback, | 1553 get_file_callback, |
1554 get_content_callback))); | 1554 get_content_callback))); |
1555 } | 1555 } |
1556 | 1556 |
1557 void GDataFileSystem::GetFileByResourceId( | 1557 void DriveFileSystem::GetFileByResourceId( |
1558 const std::string& resource_id, | 1558 const std::string& resource_id, |
1559 const GetFileCallback& get_file_callback, | 1559 const GetFileCallback& get_file_callback, |
1560 const GetContentCallback& get_content_callback) { | 1560 const GetContentCallback& get_content_callback) { |
1561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1562 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1562 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1563 RunTaskOnUIThread( | 1563 RunTaskOnUIThread( |
1564 base::Bind(&GDataFileSystem::GetFileByResourceIdOnUIThread, | 1564 base::Bind(&DriveFileSystem::GetFileByResourceIdOnUIThread, |
1565 ui_weak_ptr_, | 1565 ui_weak_ptr_, |
1566 resource_id, | 1566 resource_id, |
1567 CreateRelayCallback(get_file_callback), | 1567 CreateRelayCallback(get_file_callback), |
1568 CreateRelayCallback(get_content_callback))); | 1568 CreateRelayCallback(get_content_callback))); |
1569 } | 1569 } |
1570 | 1570 |
1571 void GDataFileSystem::GetFileByResourceIdOnUIThread( | 1571 void DriveFileSystem::GetFileByResourceIdOnUIThread( |
1572 const std::string& resource_id, | 1572 const std::string& resource_id, |
1573 const GetFileCallback& get_file_callback, | 1573 const GetFileCallback& get_file_callback, |
1574 const GetContentCallback& get_content_callback) { | 1574 const GetContentCallback& get_content_callback) { |
1575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1576 | 1576 |
1577 resource_metadata_->GetEntryByResourceIdAsync(resource_id, | 1577 resource_metadata_->GetEntryByResourceIdAsync(resource_id, |
1578 base::Bind(&GDataFileSystem::GetFileByEntryOnUIThread, | 1578 base::Bind(&DriveFileSystem::GetFileByEntryOnUIThread, |
1579 ui_weak_ptr_, | 1579 ui_weak_ptr_, |
1580 get_file_callback, | 1580 get_file_callback, |
1581 get_content_callback)); | 1581 get_content_callback)); |
1582 } | 1582 } |
1583 | 1583 |
1584 void GDataFileSystem::GetFileByEntryOnUIThread( | 1584 void DriveFileSystem::GetFileByEntryOnUIThread( |
1585 const GetFileCallback& get_file_callback, | 1585 const GetFileCallback& get_file_callback, |
1586 const GetContentCallback& get_content_callback, | 1586 const GetContentCallback& get_content_callback, |
1587 DriveEntry* entry) { | 1587 DriveEntry* entry) { |
1588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1589 | 1589 |
1590 FilePath file_path; | 1590 FilePath file_path; |
1591 if (entry) { | 1591 if (entry) { |
1592 DriveFile* file = entry->AsDriveFile(); | 1592 DriveFile* file = entry->AsDriveFile(); |
1593 if (file) | 1593 if (file) |
1594 file_path = file->GetFilePath(); | 1594 file_path = file->GetFilePath(); |
(...skipping 10 matching lines...) Expand all Loading... |
1605 FilePath(), | 1605 FilePath(), |
1606 std::string(), | 1606 std::string(), |
1607 REGULAR_FILE)); | 1607 REGULAR_FILE)); |
1608 } | 1608 } |
1609 return; | 1609 return; |
1610 } | 1610 } |
1611 | 1611 |
1612 GetFileByPath(file_path, get_file_callback, get_content_callback); | 1612 GetFileByPath(file_path, get_file_callback, get_content_callback); |
1613 } | 1613 } |
1614 | 1614 |
1615 void GDataFileSystem::OnGetFileFromCache(const GetFileFromCacheParams& params, | 1615 void DriveFileSystem::OnGetFileFromCache(const GetFileFromCacheParams& params, |
1616 DriveFileError error, | 1616 DriveFileError error, |
1617 const std::string& resource_id, | 1617 const std::string& resource_id, |
1618 const std::string& md5, | 1618 const std::string& md5, |
1619 const FilePath& cache_file_path) { | 1619 const FilePath& cache_file_path) { |
1620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1621 | 1621 |
1622 // Have we found the file in cache? If so, return it back to the caller. | 1622 // Have we found the file in cache? If so, return it back to the caller. |
1623 if (error == DRIVE_FILE_OK) { | 1623 if (error == DRIVE_FILE_OK) { |
1624 if (!params.get_file_callback.is_null()) { | 1624 if (!params.get_file_callback.is_null()) { |
1625 params.get_file_callback.Run(error, | 1625 params.get_file_callback.Run(error, |
(...skipping 10 matching lines...) Expand all Loading... |
1636 // Retrieve fresh file metadata from server. We will extract file size and | 1636 // Retrieve fresh file metadata from server. We will extract file size and |
1637 // content url from there (we want to make sure used content url is not | 1637 // content url from there (we want to make sure used content url is not |
1638 // stale). | 1638 // stale). |
1639 // | 1639 // |
1640 // Check if we have enough space, based on the expected file size. | 1640 // Check if we have enough space, based on the expected file size. |
1641 // - if we don't have enough space, try to free up the disk space | 1641 // - if we don't have enough space, try to free up the disk space |
1642 // - if we still don't have enough space, return "no space" error | 1642 // - if we still don't have enough space, return "no space" error |
1643 // - if we have enough space, start downloading the file from the server | 1643 // - if we have enough space, start downloading the file from the server |
1644 drive_service_->GetDocumentEntry( | 1644 drive_service_->GetDocumentEntry( |
1645 resource_id, | 1645 resource_id, |
1646 base::Bind(&GDataFileSystem::OnGetDocumentEntry, | 1646 base::Bind(&DriveFileSystem::OnGetDocumentEntry, |
1647 ui_weak_ptr_, | 1647 ui_weak_ptr_, |
1648 cache_file_path, | 1648 cache_file_path, |
1649 GetFileFromCacheParams(params.virtual_file_path, | 1649 GetFileFromCacheParams(params.virtual_file_path, |
1650 params.local_tmp_path, | 1650 params.local_tmp_path, |
1651 params.content_url, | 1651 params.content_url, |
1652 params.resource_id, | 1652 params.resource_id, |
1653 params.md5, | 1653 params.md5, |
1654 params.mime_type, | 1654 params.mime_type, |
1655 params.get_file_callback, | 1655 params.get_file_callback, |
1656 params.get_content_callback))); | 1656 params.get_content_callback))); |
1657 } | 1657 } |
1658 | 1658 |
1659 void GDataFileSystem::OnGetDocumentEntry(const FilePath& cache_file_path, | 1659 void DriveFileSystem::OnGetDocumentEntry(const FilePath& cache_file_path, |
1660 const GetFileFromCacheParams& params, | 1660 const GetFileFromCacheParams& params, |
1661 GDataErrorCode status, | 1661 GDataErrorCode status, |
1662 scoped_ptr<base::Value> data) { | 1662 scoped_ptr<base::Value> data) { |
1663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1664 | 1664 |
1665 DriveFileError error = util::GDataToDriveFileError(status); | 1665 DriveFileError error = util::GDataToDriveFileError(status); |
1666 | 1666 |
1667 scoped_ptr<DriveEntry> fresh_entry; | 1667 scoped_ptr<DriveEntry> fresh_entry; |
1668 if (error == DRIVE_FILE_OK) { | 1668 if (error == DRIVE_FILE_OK) { |
1669 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); | 1669 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); |
(...skipping 24 matching lines...) Expand all Loading... |
1694 resource_metadata_->RefreshFile(fresh_entry_as_file.Pass()); | 1694 resource_metadata_->RefreshFile(fresh_entry_as_file.Pass()); |
1695 | 1695 |
1696 bool* has_enough_space = new bool(false); | 1696 bool* has_enough_space = new bool(false); |
1697 util::PostBlockingPoolSequencedTaskAndReply( | 1697 util::PostBlockingPoolSequencedTaskAndReply( |
1698 FROM_HERE, | 1698 FROM_HERE, |
1699 blocking_task_runner_, | 1699 blocking_task_runner_, |
1700 base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor, | 1700 base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor, |
1701 base::Unretained(cache_), | 1701 base::Unretained(cache_), |
1702 file_size, | 1702 file_size, |
1703 has_enough_space), | 1703 has_enough_space), |
1704 base::Bind(&GDataFileSystem::StartDownloadFileIfEnoughSpace, | 1704 base::Bind(&DriveFileSystem::StartDownloadFileIfEnoughSpace, |
1705 ui_weak_ptr_, | 1705 ui_weak_ptr_, |
1706 params, | 1706 params, |
1707 content_url, | 1707 content_url, |
1708 cache_file_path, | 1708 cache_file_path, |
1709 base::Owned(has_enough_space))); | 1709 base::Owned(has_enough_space))); |
1710 } | 1710 } |
1711 | 1711 |
1712 void GDataFileSystem::StartDownloadFileIfEnoughSpace( | 1712 void DriveFileSystem::StartDownloadFileIfEnoughSpace( |
1713 const GetFileFromCacheParams& params, | 1713 const GetFileFromCacheParams& params, |
1714 const GURL& content_url, | 1714 const GURL& content_url, |
1715 const FilePath& cache_file_path, | 1715 const FilePath& cache_file_path, |
1716 bool* has_enough_space) { | 1716 bool* has_enough_space) { |
1717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1718 | 1718 |
1719 if (!*has_enough_space) { | 1719 if (!*has_enough_space) { |
1720 // If no enough space, return PLATFORM_FILE_ERROR_NO_SPACE. | 1720 // If no enough space, return PLATFORM_FILE_ERROR_NO_SPACE. |
1721 if (!params.get_file_callback.is_null()) { | 1721 if (!params.get_file_callback.is_null()) { |
1722 params.get_file_callback.Run(DRIVE_FILE_ERROR_NO_SPACE, | 1722 params.get_file_callback.Run(DRIVE_FILE_ERROR_NO_SPACE, |
1723 cache_file_path, | 1723 cache_file_path, |
1724 params.mime_type, | 1724 params.mime_type, |
1725 REGULAR_FILE); | 1725 REGULAR_FILE); |
1726 } | 1726 } |
1727 return; | 1727 return; |
1728 } | 1728 } |
1729 | 1729 |
1730 // We have enough disk space. Start downloading the file. | 1730 // We have enough disk space. Start downloading the file. |
1731 drive_service_->DownloadFile( | 1731 drive_service_->DownloadFile( |
1732 params.virtual_file_path, | 1732 params.virtual_file_path, |
1733 params.local_tmp_path, | 1733 params.local_tmp_path, |
1734 content_url, | 1734 content_url, |
1735 base::Bind(&GDataFileSystem::OnFileDownloaded, | 1735 base::Bind(&DriveFileSystem::OnFileDownloaded, |
1736 ui_weak_ptr_, | 1736 ui_weak_ptr_, |
1737 params), | 1737 params), |
1738 params.get_content_callback); | 1738 params.get_content_callback); |
1739 } | 1739 } |
1740 | 1740 |
1741 void GDataFileSystem::GetEntryInfoByPath(const FilePath& file_path, | 1741 void DriveFileSystem::GetEntryInfoByPath(const FilePath& file_path, |
1742 const GetEntryInfoCallback& callback) { | 1742 const GetEntryInfoCallback& callback) { |
1743 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1743 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1744 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1744 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1745 DCHECK(!callback.is_null()); | 1745 DCHECK(!callback.is_null()); |
1746 | 1746 |
1747 RunTaskOnUIThread( | 1747 RunTaskOnUIThread( |
1748 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThread, | 1748 base::Bind(&DriveFileSystem::GetEntryInfoByPathOnUIThread, |
1749 ui_weak_ptr_, | 1749 ui_weak_ptr_, |
1750 file_path, | 1750 file_path, |
1751 CreateRelayCallback(callback))); | 1751 CreateRelayCallback(callback))); |
1752 } | 1752 } |
1753 | 1753 |
1754 void GDataFileSystem::GetEntryInfoByPathOnUIThread( | 1754 void DriveFileSystem::GetEntryInfoByPathOnUIThread( |
1755 const FilePath& file_path, | 1755 const FilePath& file_path, |
1756 const GetEntryInfoCallback& callback) { | 1756 const GetEntryInfoCallback& callback) { |
1757 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1757 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1758 DCHECK(!callback.is_null()); | 1758 DCHECK(!callback.is_null()); |
1759 | 1759 |
1760 LoadFeedIfNeeded( | 1760 LoadFeedIfNeeded( |
1761 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad, | 1761 base::Bind(&DriveFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad, |
1762 ui_weak_ptr_, | 1762 ui_weak_ptr_, |
1763 file_path, | 1763 file_path, |
1764 callback)); | 1764 callback)); |
1765 } | 1765 } |
1766 | 1766 |
1767 void GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad( | 1767 void DriveFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad( |
1768 const FilePath& file_path, | 1768 const FilePath& file_path, |
1769 const GetEntryInfoCallback& callback, | 1769 const GetEntryInfoCallback& callback, |
1770 DriveFileError error) { | 1770 DriveFileError error) { |
1771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1772 DCHECK(!callback.is_null()); | 1772 DCHECK(!callback.is_null()); |
1773 | 1773 |
1774 if (error != DRIVE_FILE_OK) { | 1774 if (error != DRIVE_FILE_OK) { |
1775 callback.Run(error, scoped_ptr<DriveEntryProto>()); | 1775 callback.Run(error, scoped_ptr<DriveEntryProto>()); |
1776 return; | 1776 return; |
1777 } | 1777 } |
1778 | 1778 |
1779 resource_metadata_->GetEntryInfoByPath( | 1779 resource_metadata_->GetEntryInfoByPath( |
1780 file_path, | 1780 file_path, |
1781 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry, | 1781 base::Bind(&DriveFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry, |
1782 ui_weak_ptr_, | 1782 ui_weak_ptr_, |
1783 callback)); | 1783 callback)); |
1784 } | 1784 } |
1785 | 1785 |
1786 void GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry( | 1786 void DriveFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry( |
1787 const GetEntryInfoCallback& callback, | 1787 const GetEntryInfoCallback& callback, |
1788 DriveFileError error, | 1788 DriveFileError error, |
1789 scoped_ptr<DriveEntryProto> entry_proto) { | 1789 scoped_ptr<DriveEntryProto> entry_proto) { |
1790 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1790 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1791 DCHECK(!callback.is_null()); | 1791 DCHECK(!callback.is_null()); |
1792 | 1792 |
1793 if (error != DRIVE_FILE_OK) { | 1793 if (error != DRIVE_FILE_OK) { |
1794 callback.Run(error, scoped_ptr<DriveEntryProto>()); | 1794 callback.Run(error, scoped_ptr<DriveEntryProto>()); |
1795 return; | 1795 return; |
1796 } | 1796 } |
1797 DCHECK(entry_proto.get()); | 1797 DCHECK(entry_proto.get()); |
1798 | 1798 |
1799 CheckLocalModificationAndRun(entry_proto.Pass(), callback); | 1799 CheckLocalModificationAndRun(entry_proto.Pass(), callback); |
1800 } | 1800 } |
1801 | 1801 |
1802 void GDataFileSystem::ReadDirectoryByPath( | 1802 void DriveFileSystem::ReadDirectoryByPath( |
1803 const FilePath& file_path, | 1803 const FilePath& file_path, |
1804 const ReadDirectoryWithSettingCallback& callback) { | 1804 const ReadDirectoryWithSettingCallback& callback) { |
1805 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1805 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1806 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1806 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1807 DCHECK(!callback.is_null()); | 1807 DCHECK(!callback.is_null()); |
1808 | 1808 |
1809 RunTaskOnUIThread( | 1809 RunTaskOnUIThread( |
1810 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThread, | 1810 base::Bind(&DriveFileSystem::ReadDirectoryByPathOnUIThread, |
1811 ui_weak_ptr_, | 1811 ui_weak_ptr_, |
1812 file_path, | 1812 file_path, |
1813 CreateRelayCallback(callback))); | 1813 CreateRelayCallback(callback))); |
1814 } | 1814 } |
1815 | 1815 |
1816 void GDataFileSystem::ReadDirectoryByPathOnUIThread( | 1816 void DriveFileSystem::ReadDirectoryByPathOnUIThread( |
1817 const FilePath& file_path, | 1817 const FilePath& file_path, |
1818 const ReadDirectoryWithSettingCallback& callback) { | 1818 const ReadDirectoryWithSettingCallback& callback) { |
1819 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1819 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1820 DCHECK(!callback.is_null()); | 1820 DCHECK(!callback.is_null()); |
1821 | 1821 |
1822 LoadFeedIfNeeded( | 1822 LoadFeedIfNeeded( |
1823 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad, | 1823 base::Bind(&DriveFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad, |
1824 ui_weak_ptr_, | 1824 ui_weak_ptr_, |
1825 file_path, | 1825 file_path, |
1826 callback)); | 1826 callback)); |
1827 } | 1827 } |
1828 | 1828 |
1829 void GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad( | 1829 void DriveFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad( |
1830 const FilePath& file_path, | 1830 const FilePath& file_path, |
1831 const ReadDirectoryWithSettingCallback& callback, | 1831 const ReadDirectoryWithSettingCallback& callback, |
1832 DriveFileError error) { | 1832 DriveFileError error) { |
1833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1834 DCHECK(!callback.is_null()); | 1834 DCHECK(!callback.is_null()); |
1835 | 1835 |
1836 if (error != DRIVE_FILE_OK) { | 1836 if (error != DRIVE_FILE_OK) { |
1837 callback.Run(error, | 1837 callback.Run(error, |
1838 hide_hosted_docs_, | 1838 hide_hosted_docs_, |
1839 scoped_ptr<DriveEntryProtoVector>()); | 1839 scoped_ptr<DriveEntryProtoVector>()); |
1840 return; | 1840 return; |
1841 } | 1841 } |
1842 | 1842 |
1843 resource_metadata_->ReadDirectoryByPath( | 1843 resource_metadata_->ReadDirectoryByPath( |
1844 file_path, | 1844 file_path, |
1845 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead, | 1845 base::Bind(&DriveFileSystem::ReadDirectoryByPathOnUIThreadAfterRead, |
1846 ui_weak_ptr_, | 1846 ui_weak_ptr_, |
1847 callback)); | 1847 callback)); |
1848 } | 1848 } |
1849 | 1849 |
1850 void GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead( | 1850 void DriveFileSystem::ReadDirectoryByPathOnUIThreadAfterRead( |
1851 const ReadDirectoryWithSettingCallback& callback, | 1851 const ReadDirectoryWithSettingCallback& callback, |
1852 DriveFileError error, | 1852 DriveFileError error, |
1853 scoped_ptr<DriveEntryProtoVector> entries) { | 1853 scoped_ptr<DriveEntryProtoVector> entries) { |
1854 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1854 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1855 DCHECK(!callback.is_null()); | 1855 DCHECK(!callback.is_null()); |
1856 | 1856 |
1857 if (error != DRIVE_FILE_OK) { | 1857 if (error != DRIVE_FILE_OK) { |
1858 callback.Run(error, | 1858 callback.Run(error, |
1859 hide_hosted_docs_, | 1859 hide_hosted_docs_, |
1860 scoped_ptr<DriveEntryProtoVector>()); | 1860 scoped_ptr<DriveEntryProtoVector>()); |
1861 return; | 1861 return; |
1862 } | 1862 } |
1863 DCHECK(entries.get()); // This is valid for emptry directories too. | 1863 DCHECK(entries.get()); // This is valid for emptry directories too. |
1864 | 1864 |
1865 callback.Run(DRIVE_FILE_OK, hide_hosted_docs_, entries.Pass()); | 1865 callback.Run(DRIVE_FILE_OK, hide_hosted_docs_, entries.Pass()); |
1866 } | 1866 } |
1867 | 1867 |
1868 void GDataFileSystem::RequestDirectoryRefresh(const FilePath& file_path) { | 1868 void DriveFileSystem::RequestDirectoryRefresh(const FilePath& file_path) { |
1869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1870 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1870 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1871 RunTaskOnUIThread( | 1871 RunTaskOnUIThread( |
1872 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread, | 1872 base::Bind(&DriveFileSystem::RequestDirectoryRefreshOnUIThread, |
1873 ui_weak_ptr_, | 1873 ui_weak_ptr_, |
1874 file_path)); | 1874 file_path)); |
1875 } | 1875 } |
1876 | 1876 |
1877 void GDataFileSystem::RequestDirectoryRefreshOnUIThread( | 1877 void DriveFileSystem::RequestDirectoryRefreshOnUIThread( |
1878 const FilePath& file_path) { | 1878 const FilePath& file_path) { |
1879 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1879 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1880 | 1880 |
1881 // Make sure the destination directory exists. | 1881 // Make sure the destination directory exists. |
1882 resource_metadata_->GetEntryInfoByPath( | 1882 resource_metadata_->GetEntryInfoByPath( |
1883 file_path, | 1883 file_path, |
1884 base::Bind( | 1884 base::Bind( |
1885 &GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo, | 1885 &DriveFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo, |
1886 ui_weak_ptr_, | 1886 ui_weak_ptr_, |
1887 file_path)); | 1887 file_path)); |
1888 } | 1888 } |
1889 | 1889 |
1890 void GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo( | 1890 void DriveFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo( |
1891 const FilePath& file_path, | 1891 const FilePath& file_path, |
1892 DriveFileError error, | 1892 DriveFileError error, |
1893 scoped_ptr<DriveEntryProto> entry_proto) { | 1893 scoped_ptr<DriveEntryProto> entry_proto) { |
1894 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1894 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1895 | 1895 |
1896 if (error != DRIVE_FILE_OK || | 1896 if (error != DRIVE_FILE_OK || |
1897 !entry_proto->file_info().is_directory()) { | 1897 !entry_proto->file_info().is_directory()) { |
1898 LOG(ERROR) << "Directory entry not found: " << file_path.value(); | 1898 LOG(ERROR) << "Directory entry not found: " << file_path.value(); |
1899 return; | 1899 return; |
1900 } | 1900 } |
1901 | 1901 |
1902 feed_loader_->LoadDirectoryFromServer( | 1902 feed_loader_->LoadDirectoryFromServer( |
1903 resource_metadata_->origin(), | 1903 resource_metadata_->origin(), |
1904 entry_proto->resource_id(), | 1904 entry_proto->resource_id(), |
1905 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, | 1905 base::Bind(&DriveFileSystem::OnRequestDirectoryRefresh, |
1906 ui_weak_ptr_, | 1906 ui_weak_ptr_, |
1907 file_path)); | 1907 file_path)); |
1908 } | 1908 } |
1909 | 1909 |
1910 void GDataFileSystem::OnRequestDirectoryRefresh( | 1910 void DriveFileSystem::OnRequestDirectoryRefresh( |
1911 const FilePath& directory_path, | 1911 const FilePath& directory_path, |
1912 GetDocumentsParams* params, | 1912 GetDocumentsParams* params, |
1913 DriveFileError error) { | 1913 DriveFileError error) { |
1914 DCHECK(params); | 1914 DCHECK(params); |
1915 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1915 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1916 | 1916 |
1917 if (error != DRIVE_FILE_OK) { | 1917 if (error != DRIVE_FILE_OK) { |
1918 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() | 1918 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() |
1919 << ": " << error; | 1919 << ": " << error; |
1920 return; | 1920 return; |
(...skipping 10 matching lines...) Expand all Loading... |
1931 &unused_uma_stats); | 1931 &unused_uma_stats); |
1932 if (error != DRIVE_FILE_OK) { | 1932 if (error != DRIVE_FILE_OK) { |
1933 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() | 1933 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() |
1934 << ": " << error; | 1934 << ": " << error; |
1935 return; | 1935 return; |
1936 } | 1936 } |
1937 | 1937 |
1938 resource_metadata_->RefreshDirectory( | 1938 resource_metadata_->RefreshDirectory( |
1939 params->directory_resource_id, | 1939 params->directory_resource_id, |
1940 file_map, | 1940 file_map, |
1941 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, | 1941 base::Bind(&DriveFileSystem::OnDirectoryChangeFileMoveCallback, |
1942 ui_weak_ptr_)); | 1942 ui_weak_ptr_)); |
1943 } | 1943 } |
1944 | 1944 |
1945 void GDataFileSystem::UpdateFileByResourceId( | 1945 void DriveFileSystem::UpdateFileByResourceId( |
1946 const std::string& resource_id, | 1946 const std::string& resource_id, |
1947 const FileOperationCallback& callback) { | 1947 const FileOperationCallback& callback) { |
1948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1949 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1949 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1950 DCHECK(!callback.is_null()); | 1950 DCHECK(!callback.is_null()); |
1951 | 1951 |
1952 RunTaskOnUIThread( | 1952 RunTaskOnUIThread( |
1953 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, | 1953 base::Bind(&DriveFileSystem::UpdateFileByResourceIdOnUIThread, |
1954 ui_weak_ptr_, | 1954 ui_weak_ptr_, |
1955 resource_id, | 1955 resource_id, |
1956 CreateRelayCallback(callback))); | 1956 CreateRelayCallback(callback))); |
1957 } | 1957 } |
1958 | 1958 |
1959 void GDataFileSystem::UpdateFileByResourceIdOnUIThread( | 1959 void DriveFileSystem::UpdateFileByResourceIdOnUIThread( |
1960 const std::string& resource_id, | 1960 const std::string& resource_id, |
1961 const FileOperationCallback& callback) { | 1961 const FileOperationCallback& callback) { |
1962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1963 DCHECK(!callback.is_null()); | 1963 DCHECK(!callback.is_null()); |
1964 | 1964 |
1965 // TODO(satorux): GetEntryInfoByResourceId() is called twice for | 1965 // TODO(satorux): GetEntryInfoByResourceId() is called twice for |
1966 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873 | 1966 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873 |
1967 resource_metadata_->GetEntryInfoByResourceId( | 1967 resource_metadata_->GetEntryInfoByResourceId( |
1968 resource_id, | 1968 resource_id, |
1969 base::Bind(&GDataFileSystem::UpdateFileByEntryInfo, | 1969 base::Bind(&DriveFileSystem::UpdateFileByEntryInfo, |
1970 ui_weak_ptr_, | 1970 ui_weak_ptr_, |
1971 callback)); | 1971 callback)); |
1972 } | 1972 } |
1973 | 1973 |
1974 void GDataFileSystem::UpdateFileByEntryInfo( | 1974 void DriveFileSystem::UpdateFileByEntryInfo( |
1975 const FileOperationCallback& callback, | 1975 const FileOperationCallback& callback, |
1976 DriveFileError error, | 1976 DriveFileError error, |
1977 const FilePath& /* dive_file_path */, | 1977 const FilePath& /* dive_file_path */, |
1978 scoped_ptr<DriveEntryProto> entry_proto) { | 1978 scoped_ptr<DriveEntryProto> entry_proto) { |
1979 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1979 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1980 DCHECK(!callback.is_null()); | 1980 DCHECK(!callback.is_null()); |
1981 | 1981 |
1982 if (error != DRIVE_FILE_OK) { | 1982 if (error != DRIVE_FILE_OK) { |
1983 callback.Run(error); | 1983 callback.Run(error); |
1984 return; | 1984 return; |
1985 } | 1985 } |
1986 | 1986 |
1987 DCHECK(entry_proto.get()); | 1987 DCHECK(entry_proto.get()); |
1988 if (entry_proto->file_info().is_directory()) { | 1988 if (entry_proto->file_info().is_directory()) { |
1989 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND); | 1989 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND); |
1990 return; | 1990 return; |
1991 } | 1991 } |
1992 | 1992 |
1993 cache_->GetFileOnUIThread( | 1993 cache_->GetFileOnUIThread( |
1994 entry_proto->resource_id(), | 1994 entry_proto->resource_id(), |
1995 entry_proto->file_specific_info().file_md5(), | 1995 entry_proto->file_specific_info().file_md5(), |
1996 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFile, | 1996 base::Bind(&DriveFileSystem::OnGetFileCompleteForUpdateFile, |
1997 ui_weak_ptr_, | 1997 ui_weak_ptr_, |
1998 callback)); | 1998 callback)); |
1999 } | 1999 } |
2000 | 2000 |
2001 void GDataFileSystem::OnGetFileCompleteForUpdateFile( | 2001 void DriveFileSystem::OnGetFileCompleteForUpdateFile( |
2002 const FileOperationCallback& callback, | 2002 const FileOperationCallback& callback, |
2003 DriveFileError error, | 2003 DriveFileError error, |
2004 const std::string& resource_id, | 2004 const std::string& resource_id, |
2005 const std::string& /* md5 */, | 2005 const std::string& /* md5 */, |
2006 const FilePath& cache_file_path) { | 2006 const FilePath& cache_file_path) { |
2007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2008 DCHECK(!callback.is_null()); | 2008 DCHECK(!callback.is_null()); |
2009 | 2009 |
2010 if (error != DRIVE_FILE_OK) { | 2010 if (error != DRIVE_FILE_OK) { |
2011 callback.Run(error); | 2011 callback.Run(error); |
2012 return; | 2012 return; |
2013 } | 2013 } |
2014 | 2014 |
2015 // Gets the size of the cache file. Since the file is locally modified, the | 2015 // Gets the size of the cache file. Since the file is locally modified, the |
2016 // file size information stored in DriveEntry is not correct. | 2016 // file size information stored in DriveEntry is not correct. |
2017 DriveFileError* get_size_error = new DriveFileError(DRIVE_FILE_ERROR_FAILED); | 2017 DriveFileError* get_size_error = new DriveFileError(DRIVE_FILE_ERROR_FAILED); |
2018 int64* file_size = new int64(-1); | 2018 int64* file_size = new int64(-1); |
2019 util::PostBlockingPoolSequencedTaskAndReply( | 2019 util::PostBlockingPoolSequencedTaskAndReply( |
2020 FROM_HERE, | 2020 FROM_HERE, |
2021 blocking_task_runner_, | 2021 blocking_task_runner_, |
2022 base::Bind(&GetLocalFileSizeOnBlockingPool, | 2022 base::Bind(&GetLocalFileSizeOnBlockingPool, |
2023 cache_file_path, | 2023 cache_file_path, |
2024 get_size_error, | 2024 get_size_error, |
2025 file_size), | 2025 file_size), |
2026 base::Bind(&GDataFileSystem::OnGetFileSizeCompleteForUpdateFile, | 2026 base::Bind(&DriveFileSystem::OnGetFileSizeCompleteForUpdateFile, |
2027 ui_weak_ptr_, | 2027 ui_weak_ptr_, |
2028 callback, | 2028 callback, |
2029 resource_id, | 2029 resource_id, |
2030 cache_file_path, | 2030 cache_file_path, |
2031 base::Owned(get_size_error), | 2031 base::Owned(get_size_error), |
2032 base::Owned(file_size))); | 2032 base::Owned(file_size))); |
2033 } | 2033 } |
2034 | 2034 |
2035 void GDataFileSystem::OnGetFileSizeCompleteForUpdateFile( | 2035 void DriveFileSystem::OnGetFileSizeCompleteForUpdateFile( |
2036 const FileOperationCallback& callback, | 2036 const FileOperationCallback& callback, |
2037 const std::string& resource_id, | 2037 const std::string& resource_id, |
2038 const FilePath& cache_file_path, | 2038 const FilePath& cache_file_path, |
2039 DriveFileError* error, | 2039 DriveFileError* error, |
2040 int64* file_size) { | 2040 int64* file_size) { |
2041 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2041 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2042 DCHECK(!callback.is_null()); | 2042 DCHECK(!callback.is_null()); |
2043 | 2043 |
2044 if (*error != DRIVE_FILE_OK) { | 2044 if (*error != DRIVE_FILE_OK) { |
2045 callback.Run(*error); | 2045 callback.Run(*error); |
2046 return; | 2046 return; |
2047 } | 2047 } |
2048 | 2048 |
2049 // TODO(satorux): GetEntryInfoByResourceId() is called twice for | 2049 // TODO(satorux): GetEntryInfoByResourceId() is called twice for |
2050 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873 | 2050 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873 |
2051 resource_metadata_->GetEntryInfoByResourceId( | 2051 resource_metadata_->GetEntryInfoByResourceId( |
2052 resource_id, | 2052 resource_id, |
2053 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry, | 2053 base::Bind(&DriveFileSystem::OnGetFileCompleteForUpdateFileByEntry, |
2054 ui_weak_ptr_, | 2054 ui_weak_ptr_, |
2055 callback, | 2055 callback, |
2056 *file_size, | 2056 *file_size, |
2057 cache_file_path)); | 2057 cache_file_path)); |
2058 } | 2058 } |
2059 | 2059 |
2060 void GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry( | 2060 void DriveFileSystem::OnGetFileCompleteForUpdateFileByEntry( |
2061 const FileOperationCallback& callback, | 2061 const FileOperationCallback& callback, |
2062 int64 file_size, | 2062 int64 file_size, |
2063 const FilePath& cache_file_path, | 2063 const FilePath& cache_file_path, |
2064 DriveFileError error, | 2064 DriveFileError error, |
2065 const FilePath& drive_file_path, | 2065 const FilePath& drive_file_path, |
2066 scoped_ptr<DriveEntryProto> entry_proto) { | 2066 scoped_ptr<DriveEntryProto> entry_proto) { |
2067 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2067 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2068 DCHECK(!callback.is_null()); | 2068 DCHECK(!callback.is_null()); |
2069 | 2069 |
2070 if (error != DRIVE_FILE_OK) { | 2070 if (error != DRIVE_FILE_OK) { |
2071 callback.Run(error); | 2071 callback.Run(error); |
2072 return; | 2072 return; |
2073 } | 2073 } |
2074 | 2074 |
2075 DCHECK(entry_proto.get()); | 2075 DCHECK(entry_proto.get()); |
2076 if (entry_proto->file_info().is_directory()) { | 2076 if (entry_proto->file_info().is_directory()) { |
2077 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND); | 2077 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND); |
2078 return; | 2078 return; |
2079 } | 2079 } |
2080 | 2080 |
2081 uploader_->UploadExistingFile( | 2081 uploader_->UploadExistingFile( |
2082 GURL(entry_proto->upload_url()), | 2082 GURL(entry_proto->upload_url()), |
2083 drive_file_path, | 2083 drive_file_path, |
2084 cache_file_path, | 2084 cache_file_path, |
2085 file_size, | 2085 file_size, |
2086 entry_proto->file_specific_info().content_mime_type(), | 2086 entry_proto->file_specific_info().content_mime_type(), |
2087 base::Bind(&GDataFileSystem::OnUpdatedFileUploaded, | 2087 base::Bind(&DriveFileSystem::OnUpdatedFileUploaded, |
2088 ui_weak_ptr_, | 2088 ui_weak_ptr_, |
2089 callback)); | 2089 callback)); |
2090 } | 2090 } |
2091 | 2091 |
2092 void GDataFileSystem::OnUpdatedFileUploaded( | 2092 void DriveFileSystem::OnUpdatedFileUploaded( |
2093 const FileOperationCallback& callback, | 2093 const FileOperationCallback& callback, |
2094 DriveFileError error, | 2094 DriveFileError error, |
2095 scoped_ptr<UploadFileInfo> upload_file_info) { | 2095 scoped_ptr<UploadFileInfo> upload_file_info) { |
2096 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2096 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2097 DCHECK(upload_file_info.get()); | 2097 DCHECK(upload_file_info.get()); |
2098 | 2098 |
2099 if (error != DRIVE_FILE_OK) { | 2099 if (error != DRIVE_FILE_OK) { |
2100 if (!callback.is_null()) | 2100 if (!callback.is_null()) |
2101 callback.Run(error); | 2101 callback.Run(error); |
2102 return; | 2102 return; |
2103 } | 2103 } |
2104 | 2104 |
2105 AddUploadedFile(UPLOAD_EXISTING_FILE, | 2105 AddUploadedFile(UPLOAD_EXISTING_FILE, |
2106 upload_file_info->gdata_path.DirName(), | 2106 upload_file_info->gdata_path.DirName(), |
2107 upload_file_info->entry.Pass(), | 2107 upload_file_info->entry.Pass(), |
2108 upload_file_info->file_path, | 2108 upload_file_info->file_path, |
2109 DriveCache::FILE_OPERATION_MOVE, | 2109 DriveCache::FILE_OPERATION_MOVE, |
2110 base::Bind(&OnAddUploadFileCompleted, callback, error)); | 2110 base::Bind(&OnAddUploadFileCompleted, callback, error)); |
2111 } | 2111 } |
2112 | 2112 |
2113 void GDataFileSystem::GetAvailableSpace( | 2113 void DriveFileSystem::GetAvailableSpace( |
2114 const GetAvailableSpaceCallback& callback) { | 2114 const GetAvailableSpaceCallback& callback) { |
2115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2116 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2116 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2117 RunTaskOnUIThread(base::Bind(&GDataFileSystem::GetAvailableSpaceOnUIThread, | 2117 RunTaskOnUIThread(base::Bind(&DriveFileSystem::GetAvailableSpaceOnUIThread, |
2118 ui_weak_ptr_, | 2118 ui_weak_ptr_, |
2119 CreateRelayCallback(callback))); | 2119 CreateRelayCallback(callback))); |
2120 } | 2120 } |
2121 | 2121 |
2122 void GDataFileSystem::GetAvailableSpaceOnUIThread( | 2122 void DriveFileSystem::GetAvailableSpaceOnUIThread( |
2123 const GetAvailableSpaceCallback& callback) { | 2123 const GetAvailableSpaceCallback& callback) { |
2124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2125 DCHECK(!callback.is_null()); | 2125 DCHECK(!callback.is_null()); |
2126 | 2126 |
2127 drive_service_->GetAccountMetadata( | 2127 drive_service_->GetAccountMetadata( |
2128 gdata::util::IsDriveV2ApiEnabled() ? | 2128 gdata::util::IsDriveV2ApiEnabled() ? |
2129 base::Bind(&GDataFileSystem::OnGetAboutResource, | 2129 base::Bind(&DriveFileSystem::OnGetAboutResource, |
2130 ui_weak_ptr_, | 2130 ui_weak_ptr_, |
2131 callback) : | 2131 callback) : |
2132 base::Bind(&GDataFileSystem::OnGetAvailableSpace, | 2132 base::Bind(&DriveFileSystem::OnGetAvailableSpace, |
2133 ui_weak_ptr_, | 2133 ui_weak_ptr_, |
2134 callback)); | 2134 callback)); |
2135 } | 2135 } |
2136 | 2136 |
2137 void GDataFileSystem::OnGetAvailableSpace( | 2137 void DriveFileSystem::OnGetAvailableSpace( |
2138 const GetAvailableSpaceCallback& callback, | 2138 const GetAvailableSpaceCallback& callback, |
2139 GDataErrorCode status, | 2139 GDataErrorCode status, |
2140 scoped_ptr<base::Value> data) { | 2140 scoped_ptr<base::Value> data) { |
2141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2142 DCHECK(!callback.is_null()); | 2142 DCHECK(!callback.is_null()); |
2143 | 2143 |
2144 DriveFileError error = util::GDataToDriveFileError(status); | 2144 DriveFileError error = util::GDataToDriveFileError(status); |
2145 if (error != DRIVE_FILE_OK) { | 2145 if (error != DRIVE_FILE_OK) { |
2146 callback.Run(error, -1, -1); | 2146 callback.Run(error, -1, -1); |
2147 return; | 2147 return; |
2148 } | 2148 } |
2149 | 2149 |
2150 scoped_ptr<AccountMetadataFeed> feed; | 2150 scoped_ptr<AccountMetadataFeed> feed; |
2151 if (data.get()) | 2151 if (data.get()) |
2152 feed = AccountMetadataFeed::CreateFrom(*data); | 2152 feed = AccountMetadataFeed::CreateFrom(*data); |
2153 if (!feed.get()) { | 2153 if (!feed.get()) { |
2154 callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1); | 2154 callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1); |
2155 return; | 2155 return; |
2156 } | 2156 } |
2157 | 2157 |
2158 callback.Run(DRIVE_FILE_OK, | 2158 callback.Run(DRIVE_FILE_OK, |
2159 feed->quota_bytes_total(), | 2159 feed->quota_bytes_total(), |
2160 feed->quota_bytes_used()); | 2160 feed->quota_bytes_used()); |
2161 } | 2161 } |
2162 | 2162 |
2163 void GDataFileSystem::OnGetAboutResource( | 2163 void DriveFileSystem::OnGetAboutResource( |
2164 const GetAvailableSpaceCallback& callback, | 2164 const GetAvailableSpaceCallback& callback, |
2165 GDataErrorCode status, | 2165 GDataErrorCode status, |
2166 scoped_ptr<base::Value> resource_json) { | 2166 scoped_ptr<base::Value> resource_json) { |
2167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2168 DCHECK(!callback.is_null()); | 2168 DCHECK(!callback.is_null()); |
2169 | 2169 |
2170 DriveFileError error = util::GDataToDriveFileError(status); | 2170 DriveFileError error = util::GDataToDriveFileError(status); |
2171 if (error != DRIVE_FILE_OK) { | 2171 if (error != DRIVE_FILE_OK) { |
2172 callback.Run(error, -1, -1); | 2172 callback.Run(error, -1, -1); |
2173 return; | 2173 return; |
2174 } | 2174 } |
2175 | 2175 |
2176 scoped_ptr<AboutResource> about; | 2176 scoped_ptr<AboutResource> about; |
2177 if (resource_json.get()) | 2177 if (resource_json.get()) |
2178 about = AboutResource::CreateFrom(*resource_json); | 2178 about = AboutResource::CreateFrom(*resource_json); |
2179 | 2179 |
2180 if (!about.get()) { | 2180 if (!about.get()) { |
2181 callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1); | 2181 callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1); |
2182 return; | 2182 return; |
2183 } | 2183 } |
2184 | 2184 |
2185 callback.Run(DRIVE_FILE_OK, | 2185 callback.Run(DRIVE_FILE_OK, |
2186 about->quota_bytes_total(), | 2186 about->quota_bytes_total(), |
2187 about->quota_bytes_used()); | 2187 about->quota_bytes_used()); |
2188 } | 2188 } |
2189 | 2189 |
2190 void GDataFileSystem::OnCreateDirectoryCompleted( | 2190 void DriveFileSystem::OnCreateDirectoryCompleted( |
2191 const CreateDirectoryParams& params, | 2191 const CreateDirectoryParams& params, |
2192 GDataErrorCode status, | 2192 GDataErrorCode status, |
2193 scoped_ptr<base::Value> data) { | 2193 scoped_ptr<base::Value> data) { |
2194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2195 | 2195 |
2196 DriveFileError error = util::GDataToDriveFileError(status); | 2196 DriveFileError error = util::GDataToDriveFileError(status); |
2197 if (error != DRIVE_FILE_OK) { | 2197 if (error != DRIVE_FILE_OK) { |
2198 if (!params.callback.is_null()) | 2198 if (!params.callback.is_null()) |
2199 params.callback.Run(error); | 2199 params.callback.Run(error); |
2200 | 2200 |
(...skipping 23 matching lines...) Expand all Loading... |
2224 params.callback); | 2224 params.callback); |
2225 return; | 2225 return; |
2226 } | 2226 } |
2227 | 2227 |
2228 if (!params.callback.is_null()) { | 2228 if (!params.callback.is_null()) { |
2229 // Finally done with the create request. | 2229 // Finally done with the create request. |
2230 params.callback.Run(DRIVE_FILE_OK); | 2230 params.callback.Run(DRIVE_FILE_OK); |
2231 } | 2231 } |
2232 } | 2232 } |
2233 | 2233 |
2234 void GDataFileSystem::OnSearch(const SearchCallback& callback, | 2234 void DriveFileSystem::OnSearch(const SearchCallback& callback, |
2235 GetDocumentsParams* params, | 2235 GetDocumentsParams* params, |
2236 DriveFileError error) { | 2236 DriveFileError error) { |
2237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2238 | 2238 |
2239 if (error != DRIVE_FILE_OK) { | 2239 if (error != DRIVE_FILE_OK) { |
2240 if (!callback.is_null()) | 2240 if (!callback.is_null()) |
2241 callback.Run(error, GURL(), scoped_ptr<std::vector<SearchResultInfo> >()); | 2241 callback.Run(error, GURL(), scoped_ptr<std::vector<SearchResultInfo> >()); |
2242 return; | 2242 return; |
2243 } | 2243 } |
2244 | 2244 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2284 } | 2284 } |
2285 | 2285 |
2286 // We will need information about result entry to create info for callback. | 2286 // We will need information about result entry to create info for callback. |
2287 // We can't use |entry| anymore, so we have to refetch entry from file | 2287 // We can't use |entry| anymore, so we have to refetch entry from file |
2288 // system. Also, |entry| doesn't have file path set before |RefreshFile| | 2288 // system. Also, |entry| doesn't have file path set before |RefreshFile| |
2289 // call, so we can't get file path from there. | 2289 // call, so we can't get file path from there. |
2290 resource_metadata_->GetEntryByResourceIdAsync(entry_resource_id, | 2290 resource_metadata_->GetEntryByResourceIdAsync(entry_resource_id, |
2291 base::Bind(&AddEntryToSearchResults, | 2291 base::Bind(&AddEntryToSearchResults, |
2292 results, | 2292 results, |
2293 callback, | 2293 callback, |
2294 base::Bind(&GDataFileSystem::CheckForUpdates, ui_weak_ptr_), | 2294 base::Bind(&DriveFileSystem::CheckForUpdates, ui_weak_ptr_), |
2295 error, | 2295 error, |
2296 i+1 == feed->entries().size(), | 2296 i+1 == feed->entries().size(), |
2297 next_feed)); | 2297 next_feed)); |
2298 } | 2298 } |
2299 } | 2299 } |
2300 | 2300 |
2301 void GDataFileSystem::Search(const std::string& search_query, | 2301 void DriveFileSystem::Search(const std::string& search_query, |
2302 const GURL& next_feed, | 2302 const GURL& next_feed, |
2303 const SearchCallback& callback) { | 2303 const SearchCallback& callback) { |
2304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2305 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2305 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2306 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread, | 2306 RunTaskOnUIThread(base::Bind(&DriveFileSystem::SearchAsyncOnUIThread, |
2307 ui_weak_ptr_, | 2307 ui_weak_ptr_, |
2308 search_query, | 2308 search_query, |
2309 next_feed, | 2309 next_feed, |
2310 CreateRelayCallback(callback))); | 2310 CreateRelayCallback(callback))); |
2311 } | 2311 } |
2312 | 2312 |
2313 void GDataFileSystem::SearchAsyncOnUIThread( | 2313 void DriveFileSystem::SearchAsyncOnUIThread( |
2314 const std::string& search_query, | 2314 const std::string& search_query, |
2315 const GURL& next_feed, | 2315 const GURL& next_feed, |
2316 const SearchCallback& callback) { | 2316 const SearchCallback& callback) { |
2317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2318 | 2318 |
2319 feed_loader_->SearchFromServer( | 2319 feed_loader_->SearchFromServer( |
2320 resource_metadata_->origin(), | 2320 resource_metadata_->origin(), |
2321 search_query, | 2321 search_query, |
2322 next_feed, | 2322 next_feed, |
2323 base::Bind(&GDataFileSystem::OnSearch, ui_weak_ptr_, callback)); | 2323 base::Bind(&DriveFileSystem::OnSearch, ui_weak_ptr_, callback)); |
2324 } | 2324 } |
2325 | 2325 |
2326 void GDataFileSystem::OnDirectoryChanged(const FilePath& directory_path) { | 2326 void DriveFileSystem::OnDirectoryChanged(const FilePath& directory_path) { |
2327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2328 | 2328 |
2329 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2329 FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, |
2330 OnDirectoryChanged(directory_path)); | 2330 OnDirectoryChanged(directory_path)); |
2331 } | 2331 } |
2332 | 2332 |
2333 void GDataFileSystem::OnDocumentFeedFetched(int num_accumulated_entries) { | 2333 void DriveFileSystem::OnDocumentFeedFetched(int num_accumulated_entries) { |
2334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2335 | 2335 |
2336 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2336 FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, |
2337 OnDocumentFeedFetched(num_accumulated_entries)); | 2337 OnDocumentFeedFetched(num_accumulated_entries)); |
2338 } | 2338 } |
2339 | 2339 |
2340 void GDataFileSystem::OnFeedFromServerLoaded() { | 2340 void DriveFileSystem::OnFeedFromServerLoaded() { |
2341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2342 | 2342 |
2343 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2343 FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, |
2344 OnFeedFromServerLoaded()); | 2344 OnFeedFromServerLoaded()); |
2345 } | 2345 } |
2346 | 2346 |
2347 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { | 2347 void DriveFileSystem::LoadRootFeedFromCacheForTesting() { |
2348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2349 | 2349 |
2350 feed_loader_->LoadFromCache( | 2350 feed_loader_->LoadFromCache( |
2351 false, // should_load_from_server. | 2351 false, // should_load_from_server. |
2352 FileOperationCallback()); | 2352 FileOperationCallback()); |
2353 } | 2353 } |
2354 | 2354 |
2355 DriveFileError GDataFileSystem::UpdateFromFeedForTesting( | 2355 DriveFileError DriveFileSystem::UpdateFromFeedForTesting( |
2356 const std::vector<DocumentFeed*>& feed_list, | 2356 const std::vector<DocumentFeed*>& feed_list, |
2357 int64 start_changestamp, | 2357 int64 start_changestamp, |
2358 int64 root_feed_changestamp) { | 2358 int64 root_feed_changestamp) { |
2359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2360 | 2360 |
2361 return feed_loader_->UpdateFromFeed(feed_list, | 2361 return feed_loader_->UpdateFromFeed(feed_list, |
2362 start_changestamp, | 2362 start_changestamp, |
2363 root_feed_changestamp); | 2363 root_feed_changestamp); |
2364 } | 2364 } |
2365 | 2365 |
2366 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, | 2366 void DriveFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, |
2367 DriveFileError error, | 2367 DriveFileError error, |
2368 const FilePath& /* file_path */) { | 2368 const FilePath& /* file_path */) { |
2369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2370 if (!callback.is_null()) | 2370 if (!callback.is_null()) |
2371 callback.Run(error); | 2371 callback.Run(error); |
2372 } | 2372 } |
2373 | 2373 |
2374 void GDataFileSystem::OnCopyDocumentCompleted( | 2374 void DriveFileSystem::OnCopyDocumentCompleted( |
2375 const FilePath& dir_path, | 2375 const FilePath& dir_path, |
2376 const FileOperationCallback& callback, | 2376 const FileOperationCallback& callback, |
2377 GDataErrorCode status, | 2377 GDataErrorCode status, |
2378 scoped_ptr<base::Value> data) { | 2378 scoped_ptr<base::Value> data) { |
2379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2380 DCHECK(!callback.is_null()); | 2380 DCHECK(!callback.is_null()); |
2381 | 2381 |
2382 DriveFileError error = util::GDataToDriveFileError(status); | 2382 DriveFileError error = util::GDataToDriveFileError(status); |
2383 if (error != DRIVE_FILE_OK) { | 2383 if (error != DRIVE_FILE_OK) { |
2384 callback.Run(error); | 2384 callback.Run(error); |
(...skipping 11 matching lines...) Expand all Loading... |
2396 callback.Run(DRIVE_FILE_ERROR_FAILED); | 2396 callback.Run(DRIVE_FILE_ERROR_FAILED); |
2397 return; | 2397 return; |
2398 } | 2398 } |
2399 | 2399 |
2400 // |entry| was added in the root directory on the server, so we should | 2400 // |entry| was added in the root directory on the server, so we should |
2401 // first add it to |root_| to mirror the state and then move it to the | 2401 // first add it to |root_| to mirror the state and then move it to the |
2402 // destination directory by MoveEntryFromRootDirectory(). | 2402 // destination directory by MoveEntryFromRootDirectory(). |
2403 resource_metadata_->AddEntryToDirectory( | 2403 resource_metadata_->AddEntryToDirectory( |
2404 resource_metadata_->root(), | 2404 resource_metadata_->root(), |
2405 entry, | 2405 entry, |
2406 base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, | 2406 base::Bind(&DriveFileSystem::MoveEntryFromRootDirectory, |
2407 ui_weak_ptr_, | 2407 ui_weak_ptr_, |
2408 dir_path, | 2408 dir_path, |
2409 callback)); | 2409 callback)); |
2410 } | 2410 } |
2411 | 2411 |
2412 void GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted( | 2412 void DriveFileSystem::OnMoveEntryFromRootDirectoryCompleted( |
2413 const FileOperationCallback& callback, | 2413 const FileOperationCallback& callback, |
2414 const FilePath& file_path, | 2414 const FilePath& file_path, |
2415 const FilePath& dir_path, | 2415 const FilePath& dir_path, |
2416 GDataErrorCode status, | 2416 GDataErrorCode status, |
2417 const GURL& document_url) { | 2417 const GURL& document_url) { |
2418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2419 DCHECK(!callback.is_null()); | 2419 DCHECK(!callback.is_null()); |
2420 | 2420 |
2421 DriveFileError error = util::GDataToDriveFileError(status); | 2421 DriveFileError error = util::GDataToDriveFileError(status); |
2422 if (error == DRIVE_FILE_OK) { | 2422 if (error == DRIVE_FILE_OK) { |
2423 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); | 2423 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); |
2424 if (entry) { | 2424 if (entry) { |
2425 DCHECK_EQ(resource_metadata_->root(), entry->parent()); | 2425 DCHECK_EQ(resource_metadata_->root(), entry->parent()); |
2426 resource_metadata_->MoveEntryToDirectory( | 2426 resource_metadata_->MoveEntryToDirectory( |
2427 dir_path, | 2427 dir_path, |
2428 entry, | 2428 entry, |
2429 base::Bind( | 2429 base::Bind( |
2430 &GDataFileSystem::NotifyAndRunFileOperationCallback, | 2430 &DriveFileSystem::NotifyAndRunFileOperationCallback, |
2431 ui_weak_ptr_, | 2431 ui_weak_ptr_, |
2432 callback)); | 2432 callback)); |
2433 return; | 2433 return; |
2434 } else { | 2434 } else { |
2435 error = DRIVE_FILE_ERROR_NOT_FOUND; | 2435 error = DRIVE_FILE_ERROR_NOT_FOUND; |
2436 } | 2436 } |
2437 } | 2437 } |
2438 | 2438 |
2439 callback.Run(error); | 2439 callback.Run(error); |
2440 } | 2440 } |
2441 | 2441 |
2442 void GDataFileSystem::OnRemovedDocument( | 2442 void DriveFileSystem::OnRemovedDocument( |
2443 const FileOperationCallback& callback, | 2443 const FileOperationCallback& callback, |
2444 const FilePath& file_path, | 2444 const FilePath& file_path, |
2445 GDataErrorCode status, | 2445 GDataErrorCode status, |
2446 const GURL& document_url) { | 2446 const GURL& document_url) { |
2447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2448 | 2448 |
2449 DriveFileError error = util::GDataToDriveFileError(status); | 2449 DriveFileError error = util::GDataToDriveFileError(status); |
2450 | 2450 |
2451 if (error == DRIVE_FILE_OK) | 2451 if (error == DRIVE_FILE_OK) |
2452 error = RemoveEntryAndCacheLocally(file_path); | 2452 error = RemoveEntryAndCacheLocally(file_path); |
2453 | 2453 |
2454 if (!callback.is_null()) { | 2454 if (!callback.is_null()) { |
2455 callback.Run(error); | 2455 callback.Run(error); |
2456 } | 2456 } |
2457 } | 2457 } |
2458 | 2458 |
2459 void GDataFileSystem::OnFileDownloaded( | 2459 void DriveFileSystem::OnFileDownloaded( |
2460 const GetFileFromCacheParams& params, | 2460 const GetFileFromCacheParams& params, |
2461 GDataErrorCode status, | 2461 GDataErrorCode status, |
2462 const GURL& content_url, | 2462 const GURL& content_url, |
2463 const FilePath& downloaded_file_path) { | 2463 const FilePath& downloaded_file_path) { |
2464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2465 | 2465 |
2466 // If user cancels download of a pinned-but-not-fetched file, mark file as | 2466 // If user cancels download of a pinned-but-not-fetched file, mark file as |
2467 // unpinned so that we do not sync the file again. | 2467 // unpinned so that we do not sync the file again. |
2468 if (status == GDATA_CANCELLED) { | 2468 if (status == GDATA_CANCELLED) { |
2469 cache_->GetCacheEntryOnUIThread( | 2469 cache_->GetCacheEntryOnUIThread( |
2470 params.resource_id, | 2470 params.resource_id, |
2471 params.md5, | 2471 params.md5, |
2472 base::Bind(&GDataFileSystem::UnpinIfPinned, | 2472 base::Bind(&DriveFileSystem::UnpinIfPinned, |
2473 ui_weak_ptr_, | 2473 ui_weak_ptr_, |
2474 params.resource_id, | 2474 params.resource_id, |
2475 params.md5)); | 2475 params.md5)); |
2476 } | 2476 } |
2477 | 2477 |
2478 // At this point, the disk can be full or nearly full for several reasons: | 2478 // At this point, the disk can be full or nearly full for several reasons: |
2479 // - The expected file size was incorrect and the file was larger | 2479 // - The expected file size was incorrect and the file was larger |
2480 // - There was an in-flight download operation and it used up space | 2480 // - There was an in-flight download operation and it used up space |
2481 // - The disk became full for some user actions we cannot control | 2481 // - The disk became full for some user actions we cannot control |
2482 // (ex. the user might have downloaded a large file from a regular web site) | 2482 // (ex. the user might have downloaded a large file from a regular web site) |
2483 // | 2483 // |
2484 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE, | 2484 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE, |
2485 // and try to free up space, even if the file was downloaded successfully. | 2485 // and try to free up space, even if the file was downloaded successfully. |
2486 bool* has_enough_space = new bool(false); | 2486 bool* has_enough_space = new bool(false); |
2487 util::PostBlockingPoolSequencedTaskAndReply( | 2487 util::PostBlockingPoolSequencedTaskAndReply( |
2488 FROM_HERE, | 2488 FROM_HERE, |
2489 blocking_task_runner_, | 2489 blocking_task_runner_, |
2490 base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor, | 2490 base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor, |
2491 base::Unretained(cache_), | 2491 base::Unretained(cache_), |
2492 0, | 2492 0, |
2493 has_enough_space), | 2493 has_enough_space), |
2494 base::Bind(&GDataFileSystem::OnFileDownloadedAndSpaceChecked, | 2494 base::Bind(&DriveFileSystem::OnFileDownloadedAndSpaceChecked, |
2495 ui_weak_ptr_, | 2495 ui_weak_ptr_, |
2496 params, | 2496 params, |
2497 status, | 2497 status, |
2498 content_url, | 2498 content_url, |
2499 downloaded_file_path, | 2499 downloaded_file_path, |
2500 base::Owned(has_enough_space))); | 2500 base::Owned(has_enough_space))); |
2501 } | 2501 } |
2502 | 2502 |
2503 void GDataFileSystem::UnpinIfPinned( | 2503 void DriveFileSystem::UnpinIfPinned( |
2504 const std::string& resource_id, | 2504 const std::string& resource_id, |
2505 const std::string& md5, | 2505 const std::string& md5, |
2506 bool success, | 2506 bool success, |
2507 const DriveCacheEntry& cache_entry) { | 2507 const DriveCacheEntry& cache_entry) { |
2508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2509 // TODO(hshi): http://crbug.com/127138 notify when file properties change. | 2509 // TODO(hshi): http://crbug.com/127138 notify when file properties change. |
2510 // This allows file manager to clear the "Available offline" checkbox. | 2510 // This allows file manager to clear the "Available offline" checkbox. |
2511 if (success && cache_entry.is_pinned()) | 2511 if (success && cache_entry.is_pinned()) |
2512 cache_->UnpinOnUIThread(resource_id, md5, CacheOperationCallback()); | 2512 cache_->UnpinOnUIThread(resource_id, md5, CacheOperationCallback()); |
2513 } | 2513 } |
2514 | 2514 |
2515 void GDataFileSystem::OnFileDownloadedAndSpaceChecked( | 2515 void DriveFileSystem::OnFileDownloadedAndSpaceChecked( |
2516 const GetFileFromCacheParams& params, | 2516 const GetFileFromCacheParams& params, |
2517 GDataErrorCode status, | 2517 GDataErrorCode status, |
2518 const GURL& content_url, | 2518 const GURL& content_url, |
2519 const FilePath& downloaded_file_path, | 2519 const FilePath& downloaded_file_path, |
2520 bool* has_enough_space) { | 2520 bool* has_enough_space) { |
2521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2522 | 2522 |
2523 DriveFileError error = util::GDataToDriveFileError(status); | 2523 DriveFileError error = util::GDataToDriveFileError(status); |
2524 | 2524 |
2525 // Make sure that downloaded file is properly stored in cache. We don't have | 2525 // Make sure that downloaded file is properly stored in cache. We don't have |
2526 // to wait for this operation to finish since the user can already use the | 2526 // to wait for this operation to finish since the user can already use the |
2527 // downloaded file. | 2527 // downloaded file. |
2528 if (error == DRIVE_FILE_OK) { | 2528 if (error == DRIVE_FILE_OK) { |
2529 if (*has_enough_space) { | 2529 if (*has_enough_space) { |
2530 cache_->StoreOnUIThread( | 2530 cache_->StoreOnUIThread( |
2531 params.resource_id, | 2531 params.resource_id, |
2532 params.md5, | 2532 params.md5, |
2533 downloaded_file_path, | 2533 downloaded_file_path, |
2534 DriveCache::FILE_OPERATION_MOVE, | 2534 DriveCache::FILE_OPERATION_MOVE, |
2535 base::Bind(&GDataFileSystem::OnDownloadStoredToCache, | 2535 base::Bind(&DriveFileSystem::OnDownloadStoredToCache, |
2536 ui_weak_ptr_)); | 2536 ui_weak_ptr_)); |
2537 } else { | 2537 } else { |
2538 // If we don't have enough space, remove the downloaded file, and | 2538 // If we don't have enough space, remove the downloaded file, and |
2539 // report "no space" error. | 2539 // report "no space" error. |
2540 util::PostBlockingPoolSequencedTask( | 2540 util::PostBlockingPoolSequencedTask( |
2541 FROM_HERE, | 2541 FROM_HERE, |
2542 blocking_task_runner_, | 2542 blocking_task_runner_, |
2543 base::Bind(base::IgnoreResult(&file_util::Delete), | 2543 base::Bind(base::IgnoreResult(&file_util::Delete), |
2544 downloaded_file_path, | 2544 downloaded_file_path, |
2545 false /* recursive*/)); | 2545 false /* recursive*/)); |
2546 error = DRIVE_FILE_ERROR_NO_SPACE; | 2546 error = DRIVE_FILE_ERROR_NO_SPACE; |
2547 } | 2547 } |
2548 } | 2548 } |
2549 | 2549 |
2550 if (!params.get_file_callback.is_null()) { | 2550 if (!params.get_file_callback.is_null()) { |
2551 params.get_file_callback.Run(error, | 2551 params.get_file_callback.Run(error, |
2552 downloaded_file_path, | 2552 downloaded_file_path, |
2553 params.mime_type, | 2553 params.mime_type, |
2554 REGULAR_FILE); | 2554 REGULAR_FILE); |
2555 } | 2555 } |
2556 } | 2556 } |
2557 | 2557 |
2558 void GDataFileSystem::OnDownloadStoredToCache(DriveFileError error, | 2558 void DriveFileSystem::OnDownloadStoredToCache(DriveFileError error, |
2559 const std::string& resource_id, | 2559 const std::string& resource_id, |
2560 const std::string& md5) { | 2560 const std::string& md5) { |
2561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2562 // Nothing much to do here for now. | 2562 // Nothing much to do here for now. |
2563 } | 2563 } |
2564 | 2564 |
2565 void GDataFileSystem::RenameEntryLocally( | 2565 void DriveFileSystem::RenameEntryLocally( |
2566 const FilePath& file_path, | 2566 const FilePath& file_path, |
2567 const FilePath::StringType& new_name, | 2567 const FilePath::StringType& new_name, |
2568 const FileMoveCallback& callback, | 2568 const FileMoveCallback& callback, |
2569 GDataErrorCode status, | 2569 GDataErrorCode status, |
2570 const GURL& document_url) { | 2570 const GURL& document_url) { |
2571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2572 | 2572 |
2573 const DriveFileError error = util::GDataToDriveFileError(status); | 2573 const DriveFileError error = util::GDataToDriveFileError(status); |
2574 if (error != DRIVE_FILE_OK) { | 2574 if (error != DRIVE_FILE_OK) { |
2575 if (!callback.is_null()) | 2575 if (!callback.is_null()) |
(...skipping 13 matching lines...) Expand all Loading... |
2589 // After changing the title of the entry, call MoveEntryToDirectory() to | 2589 // After changing the title of the entry, call MoveEntryToDirectory() to |
2590 // remove the entry from its parent directory and then add it back in order to | 2590 // remove the entry from its parent directory and then add it back in order to |
2591 // go through the file name de-duplication. | 2591 // go through the file name de-duplication. |
2592 // TODO(achuith/satorux/zel): This code is fragile. The title has been | 2592 // TODO(achuith/satorux/zel): This code is fragile. The title has been |
2593 // changed, but not the file_name. MoveEntryToDirectory calls RemoveChild to | 2593 // changed, but not the file_name. MoveEntryToDirectory calls RemoveChild to |
2594 // remove the child based on the old file_name, and then re-adds the child by | 2594 // remove the child based on the old file_name, and then re-adds the child by |
2595 // first assigning the new title to file_name. http://crbug.com/30157 | 2595 // first assigning the new title to file_name. http://crbug.com/30157 |
2596 resource_metadata_->MoveEntryToDirectory( | 2596 resource_metadata_->MoveEntryToDirectory( |
2597 entry->parent()->GetFilePath(), | 2597 entry->parent()->GetFilePath(), |
2598 entry, | 2598 entry, |
2599 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, | 2599 base::Bind(&DriveFileSystem::NotifyAndRunFileMoveCallback, |
2600 ui_weak_ptr_, | 2600 ui_weak_ptr_, |
2601 callback)); | 2601 callback)); |
2602 } | 2602 } |
2603 | 2603 |
2604 void GDataFileSystem::MoveEntryToRootDirectoryLocally( | 2604 void DriveFileSystem::MoveEntryToRootDirectoryLocally( |
2605 const FileMoveCallback& callback, | 2605 const FileMoveCallback& callback, |
2606 const FilePath& file_path, | 2606 const FilePath& file_path, |
2607 const FilePath& dir_path, | 2607 const FilePath& dir_path, |
2608 GDataErrorCode status, | 2608 GDataErrorCode status, |
2609 const GURL& document_url) { | 2609 const GURL& document_url) { |
2610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2611 DCHECK(!callback.is_null()); | 2611 DCHECK(!callback.is_null()); |
2612 | 2612 |
2613 const DriveFileError error = util::GDataToDriveFileError(status); | 2613 const DriveFileError error = util::GDataToDriveFileError(status); |
2614 if (error != DRIVE_FILE_OK) { | 2614 if (error != DRIVE_FILE_OK) { |
2615 callback.Run(error, FilePath()); | 2615 callback.Run(error, FilePath()); |
2616 return; | 2616 return; |
2617 } | 2617 } |
2618 | 2618 |
2619 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); | 2619 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); |
2620 if (!entry) { | 2620 if (!entry) { |
2621 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, FilePath()); | 2621 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, FilePath()); |
2622 return; | 2622 return; |
2623 } | 2623 } |
2624 | 2624 |
2625 resource_metadata_->MoveEntryToDirectory( | 2625 resource_metadata_->MoveEntryToDirectory( |
2626 resource_metadata_->root()->GetFilePath(), | 2626 resource_metadata_->root()->GetFilePath(), |
2627 entry, | 2627 entry, |
2628 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, | 2628 base::Bind(&DriveFileSystem::NotifyAndRunFileMoveCallback, |
2629 ui_weak_ptr_, | 2629 ui_weak_ptr_, |
2630 callback)); | 2630 callback)); |
2631 } | 2631 } |
2632 | 2632 |
2633 void GDataFileSystem::NotifyAndRunFileMoveCallback( | 2633 void DriveFileSystem::NotifyAndRunFileMoveCallback( |
2634 const FileMoveCallback& callback, | 2634 const FileMoveCallback& callback, |
2635 DriveFileError error, | 2635 DriveFileError error, |
2636 const FilePath& moved_file_path) { | 2636 const FilePath& moved_file_path) { |
2637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2638 | 2638 |
2639 if (error == DRIVE_FILE_OK) | 2639 if (error == DRIVE_FILE_OK) |
2640 OnDirectoryChanged(moved_file_path.DirName()); | 2640 OnDirectoryChanged(moved_file_path.DirName()); |
2641 | 2641 |
2642 if (!callback.is_null()) | 2642 if (!callback.is_null()) |
2643 callback.Run(error, moved_file_path); | 2643 callback.Run(error, moved_file_path); |
2644 } | 2644 } |
2645 | 2645 |
2646 void GDataFileSystem::NotifyAndRunFileOperationCallback( | 2646 void DriveFileSystem::NotifyAndRunFileOperationCallback( |
2647 const FileOperationCallback& callback, | 2647 const FileOperationCallback& callback, |
2648 DriveFileError error, | 2648 DriveFileError error, |
2649 const FilePath& moved_file_path) { | 2649 const FilePath& moved_file_path) { |
2650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2651 DCHECK(!callback.is_null()); | 2651 DCHECK(!callback.is_null()); |
2652 | 2652 |
2653 if (error == DRIVE_FILE_OK) | 2653 if (error == DRIVE_FILE_OK) |
2654 OnDirectoryChanged(moved_file_path.DirName()); | 2654 OnDirectoryChanged(moved_file_path.DirName()); |
2655 | 2655 |
2656 callback.Run(error); | 2656 callback.Run(error); |
2657 } | 2657 } |
2658 | 2658 |
2659 void GDataFileSystem::OnDirectoryChangeFileMoveCallback( | 2659 void DriveFileSystem::OnDirectoryChangeFileMoveCallback( |
2660 DriveFileError error, | 2660 DriveFileError error, |
2661 const FilePath& directory_path) { | 2661 const FilePath& directory_path) { |
2662 if (error == DRIVE_FILE_OK) | 2662 if (error == DRIVE_FILE_OK) |
2663 OnDirectoryChanged(directory_path); | 2663 OnDirectoryChanged(directory_path); |
2664 } | 2664 } |
2665 | 2665 |
2666 DriveFileError GDataFileSystem::RemoveEntryAndCacheLocally( | 2666 DriveFileError DriveFileSystem::RemoveEntryAndCacheLocally( |
2667 const FilePath& file_path) { | 2667 const FilePath& file_path) { |
2668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2669 | 2669 |
2670 std::string resource_id; | 2670 std::string resource_id; |
2671 DriveFileError error = RemoveEntryLocally(file_path, &resource_id); | 2671 DriveFileError error = RemoveEntryLocally(file_path, &resource_id); |
2672 if (error != DRIVE_FILE_OK) | 2672 if (error != DRIVE_FILE_OK) |
2673 return error; | 2673 return error; |
2674 | 2674 |
2675 // If resource_id is not empty, remove its corresponding file from cache. | 2675 // If resource_id is not empty, remove its corresponding file from cache. |
2676 if (!resource_id.empty()) | 2676 if (!resource_id.empty()) |
2677 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); | 2677 cache_->RemoveOnUIThread(resource_id, CacheOperationCallback()); |
2678 | 2678 |
2679 return DRIVE_FILE_OK; | 2679 return DRIVE_FILE_OK; |
2680 } | 2680 } |
2681 | 2681 |
2682 void GDataFileSystem::RemoveStaleEntryOnUpload( | 2682 void DriveFileSystem::RemoveStaleEntryOnUpload( |
2683 const std::string& resource_id, | 2683 const std::string& resource_id, |
2684 DriveDirectory* parent_dir, | 2684 DriveDirectory* parent_dir, |
2685 const FileMoveCallback& callback, | 2685 const FileMoveCallback& callback, |
2686 DriveEntry* existing_entry) { | 2686 DriveEntry* existing_entry) { |
2687 if (existing_entry && | 2687 if (existing_entry && |
2688 // This should always match, but just in case. | 2688 // This should always match, but just in case. |
2689 existing_entry->parent() == parent_dir) { | 2689 existing_entry->parent() == parent_dir) { |
2690 resource_metadata_->RemoveEntryFromParent(existing_entry, callback); | 2690 resource_metadata_->RemoveEntryFromParent(existing_entry, callback); |
2691 } else { | 2691 } else { |
2692 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, FilePath()); | 2692 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, FilePath()); |
2693 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; | 2693 LOG(ERROR) << "Entry for the existing file not found: " << resource_id; |
2694 } | 2694 } |
2695 } | 2695 } |
2696 | 2696 |
2697 void GDataFileSystem::NotifyFileSystemMounted() { | 2697 void DriveFileSystem::NotifyFileSystemMounted() { |
2698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2699 | 2699 |
2700 DVLOG(1) << "File System is mounted"; | 2700 DVLOG(1) << "File System is mounted"; |
2701 // Notify the observers that the file system is mounted. | 2701 // Notify the observers that the file system is mounted. |
2702 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2702 FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, |
2703 OnFileSystemMounted()); | 2703 OnFileSystemMounted()); |
2704 } | 2704 } |
2705 | 2705 |
2706 void GDataFileSystem::NotifyFileSystemToBeUnmounted() { | 2706 void DriveFileSystem::NotifyFileSystemToBeUnmounted() { |
2707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2708 | 2708 |
2709 DVLOG(1) << "File System is to be unmounted"; | 2709 DVLOG(1) << "File System is to be unmounted"; |
2710 // Notify the observers that the file system is being unmounted. | 2710 // Notify the observers that the file system is being unmounted. |
2711 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2711 FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, |
2712 OnFileSystemBeingUnmounted()); | 2712 OnFileSystemBeingUnmounted()); |
2713 } | 2713 } |
2714 | 2714 |
2715 void GDataFileSystem::NotifyInitialLoadFinishedAndRun( | 2715 void DriveFileSystem::NotifyInitialLoadFinishedAndRun( |
2716 const FileOperationCallback& callback, | 2716 const FileOperationCallback& callback, |
2717 DriveFileError error) { | 2717 DriveFileError error) { |
2718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2719 DCHECK(!callback.is_null()); | 2719 DCHECK(!callback.is_null()); |
2720 | 2720 |
2721 // Notify the observers that root directory has been initialized. | 2721 // Notify the observers that root directory has been initialized. |
2722 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2722 FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, |
2723 OnInitialLoadFinished()); | 2723 OnInitialLoadFinished()); |
2724 | 2724 |
2725 callback.Run(error); | 2725 callback.Run(error); |
2726 } | 2726 } |
2727 | 2727 |
2728 DriveFileError GDataFileSystem::AddNewDirectory( | 2728 DriveFileError DriveFileSystem::AddNewDirectory( |
2729 const FilePath& directory_path, base::Value* entry_value) { | 2729 const FilePath& directory_path, base::Value* entry_value) { |
2730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2731 | 2731 |
2732 if (!entry_value) | 2732 if (!entry_value) |
2733 return DRIVE_FILE_ERROR_FAILED; | 2733 return DRIVE_FILE_ERROR_FAILED; |
2734 | 2734 |
2735 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); | 2735 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); |
2736 | 2736 |
2737 if (!doc_entry.get()) | 2737 if (!doc_entry.get()) |
2738 return DRIVE_FILE_ERROR_FAILED; | 2738 return DRIVE_FILE_ERROR_FAILED; |
(...skipping 11 matching lines...) Expand all Loading... |
2750 return DRIVE_FILE_ERROR_FAILED; | 2750 return DRIVE_FILE_ERROR_FAILED; |
2751 | 2751 |
2752 DriveEntry* new_entry = | 2752 DriveEntry* new_entry = |
2753 resource_metadata_->FromDocumentEntry(*doc_entry); | 2753 resource_metadata_->FromDocumentEntry(*doc_entry); |
2754 if (!new_entry) | 2754 if (!new_entry) |
2755 return DRIVE_FILE_ERROR_FAILED; | 2755 return DRIVE_FILE_ERROR_FAILED; |
2756 | 2756 |
2757 resource_metadata_->AddEntryToDirectory( | 2757 resource_metadata_->AddEntryToDirectory( |
2758 parent_dir, | 2758 parent_dir, |
2759 new_entry, | 2759 new_entry, |
2760 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, | 2760 base::Bind(&DriveFileSystem::NotifyAndRunFileMoveCallback, |
2761 ui_weak_ptr_, | 2761 ui_weak_ptr_, |
2762 FileMoveCallback())); | 2762 FileMoveCallback())); |
2763 return DRIVE_FILE_OK; | 2763 return DRIVE_FILE_OK; |
2764 } | 2764 } |
2765 | 2765 |
2766 GDataFileSystem::FindMissingDirectoryResult | 2766 DriveFileSystem::FindMissingDirectoryResult |
2767 GDataFileSystem::FindFirstMissingParentDirectory( | 2767 DriveFileSystem::FindFirstMissingParentDirectory( |
2768 const FilePath& directory_path, | 2768 const FilePath& directory_path, |
2769 GURL* last_dir_content_url, | 2769 GURL* last_dir_content_url, |
2770 FilePath* first_missing_parent_path) { | 2770 FilePath* first_missing_parent_path) { |
2771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2772 | 2772 |
2773 // Let's find which how deep is the existing directory structure and | 2773 // Let's find which how deep is the existing directory structure and |
2774 // get the first element that's missing. | 2774 // get the first element that's missing. |
2775 std::vector<FilePath::StringType> path_parts; | 2775 std::vector<FilePath::StringType> path_parts; |
2776 directory_path.GetComponents(&path_parts); | 2776 directory_path.GetComponents(&path_parts); |
2777 FilePath current_path; | 2777 FilePath current_path; |
(...skipping 11 matching lines...) Expand all Loading... |
2789 return FOUND_INVALID; | 2789 return FOUND_INVALID; |
2790 } | 2790 } |
2791 } else { | 2791 } else { |
2792 *first_missing_parent_path = current_path; | 2792 *first_missing_parent_path = current_path; |
2793 return FOUND_MISSING; | 2793 return FOUND_MISSING; |
2794 } | 2794 } |
2795 } | 2795 } |
2796 return DIRECTORY_ALREADY_PRESENT; | 2796 return DIRECTORY_ALREADY_PRESENT; |
2797 } | 2797 } |
2798 | 2798 |
2799 DriveFileError GDataFileSystem::RemoveEntryLocally( | 2799 DriveFileError DriveFileSystem::RemoveEntryLocally( |
2800 const FilePath& file_path, std::string* resource_id) { | 2800 const FilePath& file_path, std::string* resource_id) { |
2801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2802 | 2802 |
2803 resource_id->clear(); | 2803 resource_id->clear(); |
2804 | 2804 |
2805 // Find directory element within the cached file system snapshot. | 2805 // Find directory element within the cached file system snapshot. |
2806 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); | 2806 DriveEntry* entry = resource_metadata_->FindEntryByPathSync(file_path); |
2807 | 2807 |
2808 if (!entry) | 2808 if (!entry) |
2809 return DRIVE_FILE_ERROR_NOT_FOUND; | 2809 return DRIVE_FILE_ERROR_NOT_FOUND; |
2810 | 2810 |
2811 // You can't remove root element. | 2811 // You can't remove root element. |
2812 if (!entry->parent()) | 2812 if (!entry->parent()) |
2813 return DRIVE_FILE_ERROR_ACCESS_DENIED; | 2813 return DRIVE_FILE_ERROR_ACCESS_DENIED; |
2814 | 2814 |
2815 // If it's a file (only files have resource id), get its resource id so that | 2815 // If it's a file (only files have resource id), get its resource id so that |
2816 // we can remove it after releasing the auto lock. | 2816 // we can remove it after releasing the auto lock. |
2817 if (entry->AsDriveFile()) | 2817 if (entry->AsDriveFile()) |
2818 *resource_id = entry->AsDriveFile()->resource_id(); | 2818 *resource_id = entry->AsDriveFile()->resource_id(); |
2819 | 2819 |
2820 resource_metadata_->RemoveEntryFromParent( | 2820 resource_metadata_->RemoveEntryFromParent( |
2821 entry, | 2821 entry, |
2822 base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, | 2822 base::Bind(&DriveFileSystem::OnDirectoryChangeFileMoveCallback, |
2823 ui_weak_ptr_)); | 2823 ui_weak_ptr_)); |
2824 return DRIVE_FILE_OK; | 2824 return DRIVE_FILE_OK; |
2825 } | 2825 } |
2826 | 2826 |
2827 void GDataFileSystem::AddUploadedFile( | 2827 void DriveFileSystem::AddUploadedFile( |
2828 UploadMode upload_mode, | 2828 UploadMode upload_mode, |
2829 const FilePath& virtual_dir_path, | 2829 const FilePath& virtual_dir_path, |
2830 scoped_ptr<DocumentEntry> entry, | 2830 scoped_ptr<DocumentEntry> entry, |
2831 const FilePath& file_content_path, | 2831 const FilePath& file_content_path, |
2832 DriveCache::FileOperationType cache_operation, | 2832 DriveCache::FileOperationType cache_operation, |
2833 const base::Closure& callback) { | 2833 const base::Closure& callback) { |
2834 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2834 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2835 | 2835 |
2836 // Post a task to the same thread, rather than calling it here, as | 2836 // Post a task to the same thread, rather than calling it here, as |
2837 // AddUploadedFile() is asynchronous. | 2837 // AddUploadedFile() is asynchronous. |
2838 base::MessageLoopProxy::current()->PostTask( | 2838 base::MessageLoopProxy::current()->PostTask( |
2839 FROM_HERE, | 2839 FROM_HERE, |
2840 base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread, | 2840 base::Bind(&DriveFileSystem::AddUploadedFileOnUIThread, |
2841 ui_weak_ptr_, | 2841 ui_weak_ptr_, |
2842 upload_mode, | 2842 upload_mode, |
2843 virtual_dir_path, | 2843 virtual_dir_path, |
2844 base::Passed(&entry), | 2844 base::Passed(&entry), |
2845 file_content_path, | 2845 file_content_path, |
2846 cache_operation, | 2846 cache_operation, |
2847 callback)); | 2847 callback)); |
2848 } | 2848 } |
2849 | 2849 |
2850 void GDataFileSystem::AddUploadedFileOnUIThread( | 2850 void DriveFileSystem::AddUploadedFileOnUIThread( |
2851 UploadMode upload_mode, | 2851 UploadMode upload_mode, |
2852 const FilePath& virtual_dir_path, | 2852 const FilePath& virtual_dir_path, |
2853 scoped_ptr<DocumentEntry> entry, | 2853 scoped_ptr<DocumentEntry> entry, |
2854 const FilePath& file_content_path, | 2854 const FilePath& file_content_path, |
2855 DriveCache::FileOperationType cache_operation, | 2855 DriveCache::FileOperationType cache_operation, |
2856 const base::Closure& callback) { | 2856 const base::Closure& callback) { |
2857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2858 | 2858 |
2859 // ScopedClosureRunner ensures that the specified callback is always invoked | 2859 // ScopedClosureRunner ensures that the specified callback is always invoked |
2860 // upon return or passed on. | 2860 // upon return or passed on. |
(...skipping 21 matching lines...) Expand all Loading... |
2882 const std::string& resource_id = new_entry->resource_id(); | 2882 const std::string& resource_id = new_entry->resource_id(); |
2883 AddUploadedFileParams* params = | 2883 AddUploadedFileParams* params = |
2884 new AddUploadedFileParams(upload_mode, | 2884 new AddUploadedFileParams(upload_mode, |
2885 parent_dir, | 2885 parent_dir, |
2886 new_entry.Pass(), | 2886 new_entry.Pass(), |
2887 file_content_path, | 2887 file_content_path, |
2888 cache_operation, | 2888 cache_operation, |
2889 callback_runner.Release()); | 2889 callback_runner.Release()); |
2890 | 2890 |
2891 const FileMoveCallback file_move_callback = | 2891 const FileMoveCallback file_move_callback = |
2892 base::Bind(&GDataFileSystem::ContinueAddUploadedFile, | 2892 base::Bind(&DriveFileSystem::ContinueAddUploadedFile, |
2893 ui_weak_ptr_, params); | 2893 ui_weak_ptr_, params); |
2894 | 2894 |
2895 if (upload_mode == UPLOAD_EXISTING_FILE) { | 2895 if (upload_mode == UPLOAD_EXISTING_FILE) { |
2896 // Remove an existing entry, which should be present. | 2896 // Remove an existing entry, which should be present. |
2897 resource_metadata_->GetEntryByResourceIdAsync( | 2897 resource_metadata_->GetEntryByResourceIdAsync( |
2898 resource_id, | 2898 resource_id, |
2899 base::Bind(&GDataFileSystem::RemoveStaleEntryOnUpload, | 2899 base::Bind(&DriveFileSystem::RemoveStaleEntryOnUpload, |
2900 ui_weak_ptr_, | 2900 ui_weak_ptr_, |
2901 resource_id, | 2901 resource_id, |
2902 parent_dir, | 2902 parent_dir, |
2903 file_move_callback)); | 2903 file_move_callback)); |
2904 } else { | 2904 } else { |
2905 file_move_callback.Run(DRIVE_FILE_OK, FilePath()); | 2905 file_move_callback.Run(DRIVE_FILE_OK, FilePath()); |
2906 } | 2906 } |
2907 } | 2907 } |
2908 | 2908 |
2909 void GDataFileSystem::ContinueAddUploadedFile( | 2909 void DriveFileSystem::ContinueAddUploadedFile( |
2910 AddUploadedFileParams* params, | 2910 AddUploadedFileParams* params, |
2911 DriveFileError error, | 2911 DriveFileError error, |
2912 const FilePath& file_path) { | 2912 const FilePath& file_path) { |
2913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2914 DCHECK_EQ(DRIVE_FILE_OK, error); | 2914 DCHECK_EQ(DRIVE_FILE_OK, error); |
2915 DCHECK(params->new_entry.get()); | 2915 DCHECK(params->new_entry.get()); |
2916 DriveFile* file = params->new_entry->AsDriveFile(); | 2916 DriveFile* file = params->new_entry->AsDriveFile(); |
2917 DCHECK(file); | 2917 DCHECK(file); |
2918 | 2918 |
2919 params->resource_id = file->resource_id(); | 2919 params->resource_id = file->resource_id(); |
2920 params->md5 = file->file_md5(); | 2920 params->md5 = file->file_md5(); |
2921 resource_metadata_->AddEntryToDirectory( | 2921 resource_metadata_->AddEntryToDirectory( |
2922 params->parent_dir, | 2922 params->parent_dir, |
2923 params->new_entry.release(), | 2923 params->new_entry.release(), |
2924 base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback, | 2924 base::Bind(&DriveFileSystem::NotifyAndRunFileMoveCallback, |
2925 ui_weak_ptr_, | 2925 ui_weak_ptr_, |
2926 base::Bind(&GDataFileSystem::AddUploadedFileToCache, | 2926 base::Bind(&DriveFileSystem::AddUploadedFileToCache, |
2927 ui_weak_ptr_, | 2927 ui_weak_ptr_, |
2928 base::Owned(params)))); | 2928 base::Owned(params)))); |
2929 } | 2929 } |
2930 | 2930 |
2931 void GDataFileSystem::AddUploadedFileToCache( | 2931 void DriveFileSystem::AddUploadedFileToCache( |
2932 AddUploadedFileParams* params, | 2932 AddUploadedFileParams* params, |
2933 DriveFileError error, | 2933 DriveFileError error, |
2934 const FilePath& file_path) { | 2934 const FilePath& file_path) { |
2935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2936 | 2936 |
2937 if (params->upload_mode == UPLOAD_NEW_FILE) { | 2937 if (params->upload_mode == UPLOAD_NEW_FILE) { |
2938 // Add the file to the cache if we have uploaded a new file. | 2938 // Add the file to the cache if we have uploaded a new file. |
2939 cache_->StoreOnUIThread(params->resource_id, | 2939 cache_->StoreOnUIThread(params->resource_id, |
2940 params->md5, | 2940 params->md5, |
2941 params->file_content_path, | 2941 params->file_content_path, |
2942 params->cache_operation, | 2942 params->cache_operation, |
2943 base::Bind(&OnCacheUpdatedForAddUploadedFile, | 2943 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
2944 params->callback)); | 2944 params->callback)); |
2945 } else if (params->upload_mode == UPLOAD_EXISTING_FILE) { | 2945 } else if (params->upload_mode == UPLOAD_EXISTING_FILE) { |
2946 // Clear the dirty bit if we have updated an existing file. | 2946 // Clear the dirty bit if we have updated an existing file. |
2947 cache_->ClearDirtyOnUIThread(params->resource_id, | 2947 cache_->ClearDirtyOnUIThread(params->resource_id, |
2948 params->md5, | 2948 params->md5, |
2949 base::Bind(&OnCacheUpdatedForAddUploadedFile, | 2949 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
2950 params->callback)); | 2950 params->callback)); |
2951 } else { | 2951 } else { |
2952 NOTREACHED() << "Unexpected upload mode: " << params->upload_mode; | 2952 NOTREACHED() << "Unexpected upload mode: " << params->upload_mode; |
2953 // Shouldn't reach here, so the line below should not make much sense, but | 2953 // Shouldn't reach here, so the line below should not make much sense, but |
2954 // since calling |callback| exactly once is our obligation, we'd better call | 2954 // since calling |callback| exactly once is our obligation, we'd better call |
2955 // it for not to clutter further more. | 2955 // it for not to clutter further more. |
2956 params->callback.Run(); | 2956 params->callback.Run(); |
2957 } | 2957 } |
2958 } | 2958 } |
2959 | 2959 |
2960 void GDataFileSystem::UpdateEntryData(const std::string& resource_id, | 2960 void DriveFileSystem::UpdateEntryData(const std::string& resource_id, |
2961 const std::string& md5, | 2961 const std::string& md5, |
2962 scoped_ptr<DocumentEntry> entry, | 2962 scoped_ptr<DocumentEntry> entry, |
2963 const FilePath& file_content_path, | 2963 const FilePath& file_content_path, |
2964 const base::Closure& callback) { | 2964 const base::Closure& callback) { |
2965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2966 | 2966 |
2967 // Post a task to the same thread, rather than calling it here, as | 2967 // Post a task to the same thread, rather than calling it here, as |
2968 // UpdateEntryData() is asynchronous. | 2968 // UpdateEntryData() is asynchronous. |
2969 base::MessageLoopProxy::current()->PostTask( | 2969 base::MessageLoopProxy::current()->PostTask( |
2970 FROM_HERE, | 2970 FROM_HERE, |
2971 base::Bind(&GDataFileSystem::UpdateEntryDataOnUIThread, | 2971 base::Bind(&DriveFileSystem::UpdateEntryDataOnUIThread, |
2972 ui_weak_ptr_, | 2972 ui_weak_ptr_, |
2973 resource_id, | 2973 resource_id, |
2974 md5, | 2974 md5, |
2975 base::Passed(&entry), | 2975 base::Passed(&entry), |
2976 file_content_path, | 2976 file_content_path, |
2977 callback)); | 2977 callback)); |
2978 } | 2978 } |
2979 | 2979 |
2980 void GDataFileSystem::UpdateEntryDataOnUIThread( | 2980 void DriveFileSystem::UpdateEntryDataOnUIThread( |
2981 const std::string& resource_id, | 2981 const std::string& resource_id, |
2982 const std::string& md5, | 2982 const std::string& md5, |
2983 scoped_ptr<DocumentEntry> entry, | 2983 scoped_ptr<DocumentEntry> entry, |
2984 const FilePath& file_content_path, | 2984 const FilePath& file_content_path, |
2985 const base::Closure& callback) { | 2985 const base::Closure& callback) { |
2986 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2986 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2987 | 2987 |
2988 scoped_ptr<DriveFile> new_entry( | 2988 scoped_ptr<DriveFile> new_entry( |
2989 resource_metadata_->FromDocumentEntry(*entry)->AsDriveFile()); | 2989 resource_metadata_->FromDocumentEntry(*entry)->AsDriveFile()); |
2990 if (!new_entry.get()) { | 2990 if (!new_entry.get()) { |
2991 return; | 2991 return; |
2992 } | 2992 } |
2993 | 2993 |
2994 resource_metadata_->RefreshFile(new_entry.Pass()); | 2994 resource_metadata_->RefreshFile(new_entry.Pass()); |
2995 | 2995 |
2996 // Add the file to the cache if we have uploaded a new file. | 2996 // Add the file to the cache if we have uploaded a new file. |
2997 cache_->StoreOnUIThread(resource_id, | 2997 cache_->StoreOnUIThread(resource_id, |
2998 md5, | 2998 md5, |
2999 file_content_path, | 2999 file_content_path, |
3000 DriveCache::FILE_OPERATION_MOVE, | 3000 DriveCache::FILE_OPERATION_MOVE, |
3001 base::Bind(&OnCacheUpdatedForAddUploadedFile, | 3001 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
3002 callback)); | 3002 callback)); |
3003 } | 3003 } |
3004 | 3004 |
3005 | 3005 |
3006 void GDataFileSystem::Observe(int type, | 3006 void DriveFileSystem::Observe(int type, |
3007 const content::NotificationSource& source, | 3007 const content::NotificationSource& source, |
3008 const content::NotificationDetails& details) { | 3008 const content::NotificationDetails& details) { |
3009 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3009 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3010 | 3010 |
3011 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 3011 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
3012 PrefService* pref_service = profile_->GetPrefs(); | 3012 PrefService* pref_service = profile_->GetPrefs(); |
3013 std::string* pref_name = content::Details<std::string>(details).ptr(); | 3013 std::string* pref_name = content::Details<std::string>(details).ptr(); |
3014 if (*pref_name == prefs::kDisableGDataHostedFiles) { | 3014 if (*pref_name == prefs::kDisableGDataHostedFiles) { |
3015 SetHideHostedDocuments( | 3015 SetHideHostedDocuments( |
3016 pref_service->GetBoolean(prefs::kDisableGDataHostedFiles)); | 3016 pref_service->GetBoolean(prefs::kDisableGDataHostedFiles)); |
3017 } | 3017 } |
3018 } else { | 3018 } else { |
3019 NOTREACHED(); | 3019 NOTREACHED(); |
3020 } | 3020 } |
3021 } | 3021 } |
3022 | 3022 |
3023 void GDataFileSystem::SetHideHostedDocuments(bool hide) { | 3023 void DriveFileSystem::SetHideHostedDocuments(bool hide) { |
3024 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3024 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3025 | 3025 |
3026 if (hide == hide_hosted_docs_) | 3026 if (hide == hide_hosted_docs_) |
3027 return; | 3027 return; |
3028 | 3028 |
3029 hide_hosted_docs_ = hide; | 3029 hide_hosted_docs_ = hide; |
3030 const FilePath root_path = resource_metadata_->root()->GetFilePath(); | 3030 const FilePath root_path = resource_metadata_->root()->GetFilePath(); |
3031 | 3031 |
3032 // Kick off directory refresh when this setting changes. | 3032 // Kick off directory refresh when this setting changes. |
3033 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 3033 FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, |
3034 OnDirectoryChanged(root_path)); | 3034 OnDirectoryChanged(root_path)); |
3035 } | 3035 } |
3036 | 3036 |
3037 //============= GDataFileSystem: internal helper functions ===================== | 3037 //============= DriveFileSystem: internal helper functions ===================== |
3038 | 3038 |
3039 void GDataFileSystem::InitializePreferenceObserver() { | 3039 void DriveFileSystem::InitializePreferenceObserver() { |
3040 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3040 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3041 | 3041 |
3042 pref_registrar_.reset(new PrefChangeRegistrar()); | 3042 pref_registrar_.reset(new PrefChangeRegistrar()); |
3043 pref_registrar_->Init(profile_->GetPrefs()); | 3043 pref_registrar_->Init(profile_->GetPrefs()); |
3044 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 3044 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
3045 } | 3045 } |
3046 | 3046 |
3047 void GDataFileSystem::OpenFile(const FilePath& file_path, | 3047 void DriveFileSystem::OpenFile(const FilePath& file_path, |
3048 const OpenFileCallback& callback) { | 3048 const OpenFileCallback& callback) { |
3049 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 3049 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
3050 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 3050 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
3051 RunTaskOnUIThread(base::Bind(&GDataFileSystem::OpenFileOnUIThread, | 3051 RunTaskOnUIThread(base::Bind(&DriveFileSystem::OpenFileOnUIThread, |
3052 ui_weak_ptr_, | 3052 ui_weak_ptr_, |
3053 file_path, | 3053 file_path, |
3054 CreateRelayCallback(callback))); | 3054 CreateRelayCallback(callback))); |
3055 } | 3055 } |
3056 | 3056 |
3057 void GDataFileSystem::OpenFileOnUIThread(const FilePath& file_path, | 3057 void DriveFileSystem::OpenFileOnUIThread(const FilePath& file_path, |
3058 const OpenFileCallback& callback) { | 3058 const OpenFileCallback& callback) { |
3059 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3059 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3060 | 3060 |
3061 // If the file is already opened, it cannot be opened again before closed. | 3061 // If the file is already opened, it cannot be opened again before closed. |
3062 // This is for avoiding simultaneous modification to the file, and moreover | 3062 // This is for avoiding simultaneous modification to the file, and moreover |
3063 // to avoid an inconsistent cache state (suppose an operation sequence like | 3063 // to avoid an inconsistent cache state (suppose an operation sequence like |
3064 // Open->Open->modify->Close->modify->Close; the second modify may not be | 3064 // Open->Open->modify->Close->modify->Close; the second modify may not be |
3065 // synchronized to the server since it is already Closed on the cache). | 3065 // synchronized to the server since it is already Closed on the cache). |
3066 if (open_files_.find(file_path) != open_files_.end()) { | 3066 if (open_files_.find(file_path) != open_files_.end()) { |
3067 MessageLoop::current()->PostTask( | 3067 MessageLoop::current()->PostTask( |
3068 FROM_HERE, | 3068 FROM_HERE, |
3069 base::Bind(callback, DRIVE_FILE_ERROR_IN_USE, FilePath())); | 3069 base::Bind(callback, DRIVE_FILE_ERROR_IN_USE, FilePath())); |
3070 return; | 3070 return; |
3071 } | 3071 } |
3072 open_files_.insert(file_path); | 3072 open_files_.insert(file_path); |
3073 | 3073 |
3074 resource_metadata_->GetEntryInfoByPath( | 3074 resource_metadata_->GetEntryInfoByPath( |
3075 file_path, | 3075 file_path, |
3076 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForOpenFile, | 3076 base::Bind(&DriveFileSystem::OnGetEntryInfoCompleteForOpenFile, |
3077 ui_weak_ptr_, | 3077 ui_weak_ptr_, |
3078 file_path, | 3078 file_path, |
3079 base::Bind(&GDataFileSystem::OnOpenFileFinished, | 3079 base::Bind(&DriveFileSystem::OnOpenFileFinished, |
3080 ui_weak_ptr_, | 3080 ui_weak_ptr_, |
3081 file_path, | 3081 file_path, |
3082 callback))); | 3082 callback))); |
3083 } | 3083 } |
3084 | 3084 |
3085 void GDataFileSystem::OnGetEntryInfoCompleteForOpenFile( | 3085 void DriveFileSystem::OnGetEntryInfoCompleteForOpenFile( |
3086 const FilePath& file_path, | 3086 const FilePath& file_path, |
3087 const OpenFileCallback& callback, | 3087 const OpenFileCallback& callback, |
3088 DriveFileError error, | 3088 DriveFileError error, |
3089 scoped_ptr<DriveEntryProto> entry_proto) { | 3089 scoped_ptr<DriveEntryProto> entry_proto) { |
3090 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3090 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3091 | 3091 |
3092 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 3092 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
3093 error = DRIVE_FILE_ERROR_NOT_FOUND; | 3093 error = DRIVE_FILE_ERROR_NOT_FOUND; |
3094 | 3094 |
3095 if (error == DRIVE_FILE_OK) { | 3095 if (error == DRIVE_FILE_OK) { |
3096 if (entry_proto->file_specific_info().file_md5().empty() || | 3096 if (entry_proto->file_specific_info().file_md5().empty() || |
3097 entry_proto->file_specific_info().is_hosted_document()) { | 3097 entry_proto->file_specific_info().is_hosted_document()) { |
3098 // No support for opening a directory or hosted document. | 3098 // No support for opening a directory or hosted document. |
3099 error = DRIVE_FILE_ERROR_INVALID_OPERATION; | 3099 error = DRIVE_FILE_ERROR_INVALID_OPERATION; |
3100 } | 3100 } |
3101 } | 3101 } |
3102 | 3102 |
3103 if (error != DRIVE_FILE_OK) { | 3103 if (error != DRIVE_FILE_OK) { |
3104 if (!callback.is_null()) | 3104 if (!callback.is_null()) |
3105 callback.Run(error, FilePath()); | 3105 callback.Run(error, FilePath()); |
3106 return; | 3106 return; |
3107 } | 3107 } |
3108 | 3108 |
3109 DCHECK(!entry_proto->resource_id().empty()); | 3109 DCHECK(!entry_proto->resource_id().empty()); |
3110 GetResolvedFileByPath( | 3110 GetResolvedFileByPath( |
3111 file_path, | 3111 file_path, |
3112 base::Bind(&GDataFileSystem::OnGetFileCompleteForOpenFile, | 3112 base::Bind(&DriveFileSystem::OnGetFileCompleteForOpenFile, |
3113 ui_weak_ptr_, | 3113 ui_weak_ptr_, |
3114 callback, | 3114 callback, |
3115 GetFileCompleteForOpenParams( | 3115 GetFileCompleteForOpenParams( |
3116 entry_proto->resource_id(), | 3116 entry_proto->resource_id(), |
3117 entry_proto->file_specific_info().file_md5())), | 3117 entry_proto->file_specific_info().file_md5())), |
3118 GetContentCallback(), | 3118 GetContentCallback(), |
3119 error, | 3119 error, |
3120 entry_proto.get()); | 3120 entry_proto.get()); |
3121 } | 3121 } |
3122 | 3122 |
3123 void GDataFileSystem::OnGetFileCompleteForOpenFile( | 3123 void DriveFileSystem::OnGetFileCompleteForOpenFile( |
3124 const OpenFileCallback& callback, | 3124 const OpenFileCallback& callback, |
3125 const GetFileCompleteForOpenParams& entry_proto, | 3125 const GetFileCompleteForOpenParams& entry_proto, |
3126 DriveFileError error, | 3126 DriveFileError error, |
3127 const FilePath& file_path, | 3127 const FilePath& file_path, |
3128 const std::string& mime_type, | 3128 const std::string& mime_type, |
3129 DriveFileType file_type) { | 3129 DriveFileType file_type) { |
3130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3131 | 3131 |
3132 if (error != DRIVE_FILE_OK) { | 3132 if (error != DRIVE_FILE_OK) { |
3133 if (!callback.is_null()) | 3133 if (!callback.is_null()) |
3134 callback.Run(error, FilePath()); | 3134 callback.Run(error, FilePath()); |
3135 return; | 3135 return; |
3136 } | 3136 } |
3137 | 3137 |
3138 // OpenFileOnUIThread ensures that the file is a regular file. | 3138 // OpenFileOnUIThread ensures that the file is a regular file. |
3139 DCHECK_EQ(REGULAR_FILE, file_type); | 3139 DCHECK_EQ(REGULAR_FILE, file_type); |
3140 | 3140 |
3141 cache_->MarkDirtyOnUIThread( | 3141 cache_->MarkDirtyOnUIThread( |
3142 entry_proto.resource_id, | 3142 entry_proto.resource_id, |
3143 entry_proto.md5, | 3143 entry_proto.md5, |
3144 base::Bind(&GDataFileSystem::OnMarkDirtyInCacheCompleteForOpenFile, | 3144 base::Bind(&DriveFileSystem::OnMarkDirtyInCacheCompleteForOpenFile, |
3145 ui_weak_ptr_, | 3145 ui_weak_ptr_, |
3146 callback)); | 3146 callback)); |
3147 } | 3147 } |
3148 | 3148 |
3149 void GDataFileSystem::OnMarkDirtyInCacheCompleteForOpenFile( | 3149 void DriveFileSystem::OnMarkDirtyInCacheCompleteForOpenFile( |
3150 const OpenFileCallback& callback, | 3150 const OpenFileCallback& callback, |
3151 DriveFileError error, | 3151 DriveFileError error, |
3152 const std::string& resource_id, | 3152 const std::string& resource_id, |
3153 const std::string& md5, | 3153 const std::string& md5, |
3154 const FilePath& cache_file_path) { | 3154 const FilePath& cache_file_path) { |
3155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3156 | 3156 |
3157 if (!callback.is_null()) | 3157 if (!callback.is_null()) |
3158 callback.Run(error, cache_file_path); | 3158 callback.Run(error, cache_file_path); |
3159 } | 3159 } |
3160 | 3160 |
3161 void GDataFileSystem::OnOpenFileFinished(const FilePath& file_path, | 3161 void DriveFileSystem::OnOpenFileFinished(const FilePath& file_path, |
3162 const OpenFileCallback& callback, | 3162 const OpenFileCallback& callback, |
3163 DriveFileError result, | 3163 DriveFileError result, |
3164 const FilePath& cache_file_path) { | 3164 const FilePath& cache_file_path) { |
3165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3166 | 3166 |
3167 // All the invocation of |callback| from operations initiated from OpenFile | 3167 // All the invocation of |callback| from operations initiated from OpenFile |
3168 // must go through here. Removes the |file_path| from the remembered set when | 3168 // must go through here. Removes the |file_path| from the remembered set when |
3169 // the file was not successfully opened. | 3169 // the file was not successfully opened. |
3170 if (result != DRIVE_FILE_OK) | 3170 if (result != DRIVE_FILE_OK) |
3171 open_files_.erase(file_path); | 3171 open_files_.erase(file_path); |
3172 | 3172 |
3173 if (!callback.is_null()) | 3173 if (!callback.is_null()) |
3174 callback.Run(result, cache_file_path); | 3174 callback.Run(result, cache_file_path); |
3175 } | 3175 } |
3176 | 3176 |
3177 void GDataFileSystem::CloseFile(const FilePath& file_path, | 3177 void DriveFileSystem::CloseFile(const FilePath& file_path, |
3178 const FileOperationCallback& callback) { | 3178 const FileOperationCallback& callback) { |
3179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 3179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
3180 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 3180 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
3181 DCHECK(!callback.is_null()); | 3181 DCHECK(!callback.is_null()); |
3182 | 3182 |
3183 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CloseFileOnUIThread, | 3183 RunTaskOnUIThread(base::Bind(&DriveFileSystem::CloseFileOnUIThread, |
3184 ui_weak_ptr_, | 3184 ui_weak_ptr_, |
3185 file_path, | 3185 file_path, |
3186 CreateRelayCallback(callback))); | 3186 CreateRelayCallback(callback))); |
3187 } | 3187 } |
3188 | 3188 |
3189 void GDataFileSystem::CloseFileOnUIThread( | 3189 void DriveFileSystem::CloseFileOnUIThread( |
3190 const FilePath& file_path, | 3190 const FilePath& file_path, |
3191 const FileOperationCallback& callback) { | 3191 const FileOperationCallback& callback) { |
3192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3193 DCHECK(!callback.is_null()); | 3193 DCHECK(!callback.is_null()); |
3194 | 3194 |
3195 if (open_files_.find(file_path) == open_files_.end()) { | 3195 if (open_files_.find(file_path) == open_files_.end()) { |
3196 // The file is not being opened. | 3196 // The file is not being opened. |
3197 MessageLoop::current()->PostTask( | 3197 MessageLoop::current()->PostTask( |
3198 FROM_HERE, | 3198 FROM_HERE, |
3199 base::Bind(callback, DRIVE_FILE_ERROR_NOT_FOUND)); | 3199 base::Bind(callback, DRIVE_FILE_ERROR_NOT_FOUND)); |
3200 return; | 3200 return; |
3201 } | 3201 } |
3202 | 3202 |
3203 // Step 1 of CloseFile: Get resource_id and md5 for |file_path|. | 3203 // Step 1 of CloseFile: Get resource_id and md5 for |file_path|. |
3204 resource_metadata_->GetEntryInfoByPath( | 3204 resource_metadata_->GetEntryInfoByPath( |
3205 file_path, | 3205 file_path, |
3206 base::Bind(&GDataFileSystem::CloseFileOnUIThreadAfterGetEntryInfo, | 3206 base::Bind(&DriveFileSystem::CloseFileOnUIThreadAfterGetEntryInfo, |
3207 ui_weak_ptr_, | 3207 ui_weak_ptr_, |
3208 file_path, | 3208 file_path, |
3209 base::Bind(&GDataFileSystem::CloseFileOnUIThreadFinalize, | 3209 base::Bind(&DriveFileSystem::CloseFileOnUIThreadFinalize, |
3210 ui_weak_ptr_, | 3210 ui_weak_ptr_, |
3211 file_path, | 3211 file_path, |
3212 callback))); | 3212 callback))); |
3213 } | 3213 } |
3214 | 3214 |
3215 void GDataFileSystem::CloseFileOnUIThreadAfterGetEntryInfo( | 3215 void DriveFileSystem::CloseFileOnUIThreadAfterGetEntryInfo( |
3216 const FilePath& file_path, | 3216 const FilePath& file_path, |
3217 const FileOperationCallback& callback, | 3217 const FileOperationCallback& callback, |
3218 DriveFileError error, | 3218 DriveFileError error, |
3219 scoped_ptr<DriveEntryProto> entry_proto) { | 3219 scoped_ptr<DriveEntryProto> entry_proto) { |
3220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3221 DCHECK(!callback.is_null()); | 3221 DCHECK(!callback.is_null()); |
3222 | 3222 |
3223 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 3223 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
3224 error = DRIVE_FILE_ERROR_NOT_FOUND; | 3224 error = DRIVE_FILE_ERROR_NOT_FOUND; |
3225 | 3225 |
3226 if (error != DRIVE_FILE_OK) { | 3226 if (error != DRIVE_FILE_OK) { |
3227 callback.Run(error); | 3227 callback.Run(error); |
3228 return; | 3228 return; |
3229 } | 3229 } |
3230 | 3230 |
3231 // Step 2 of CloseFile: Commit the modification in cache. This will trigger | 3231 // Step 2 of CloseFile: Commit the modification in cache. This will trigger |
3232 // background upload. | 3232 // background upload. |
3233 // TODO(benchan,kinaba): Call ClearDirtyInCache instead of CommitDirtyInCache | 3233 // TODO(benchan,kinaba): Call ClearDirtyInCache instead of CommitDirtyInCache |
3234 // if the file has not been modified. Come up with a way to detect the | 3234 // if the file has not been modified. Come up with a way to detect the |
3235 // intactness effectively, or provide a method for user to declare it when | 3235 // intactness effectively, or provide a method for user to declare it when |
3236 // calling CloseFile(). | 3236 // calling CloseFile(). |
3237 cache_->CommitDirtyOnUIThread( | 3237 cache_->CommitDirtyOnUIThread( |
3238 entry_proto->resource_id(), | 3238 entry_proto->resource_id(), |
3239 entry_proto->file_specific_info().file_md5(), | 3239 entry_proto->file_specific_info().file_md5(), |
3240 base::Bind(&GDataFileSystem::CloseFileOnUIThreadAfterCommitDirtyInCache, | 3240 base::Bind(&DriveFileSystem::CloseFileOnUIThreadAfterCommitDirtyInCache, |
3241 ui_weak_ptr_, | 3241 ui_weak_ptr_, |
3242 callback)); | 3242 callback)); |
3243 } | 3243 } |
3244 | 3244 |
3245 void GDataFileSystem::CloseFileOnUIThreadAfterCommitDirtyInCache( | 3245 void DriveFileSystem::CloseFileOnUIThreadAfterCommitDirtyInCache( |
3246 const FileOperationCallback& callback, | 3246 const FileOperationCallback& callback, |
3247 DriveFileError error, | 3247 DriveFileError error, |
3248 const std::string& /* resource_id */, | 3248 const std::string& /* resource_id */, |
3249 const std::string& /* md5 */) { | 3249 const std::string& /* md5 */) { |
3250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3251 DCHECK(!callback.is_null()); | 3251 DCHECK(!callback.is_null()); |
3252 | 3252 |
3253 callback.Run(error); | 3253 callback.Run(error); |
3254 } | 3254 } |
3255 | 3255 |
3256 void GDataFileSystem::CloseFileOnUIThreadFinalize( | 3256 void DriveFileSystem::CloseFileOnUIThreadFinalize( |
3257 const FilePath& file_path, | 3257 const FilePath& file_path, |
3258 const FileOperationCallback& callback, | 3258 const FileOperationCallback& callback, |
3259 DriveFileError result) { | 3259 DriveFileError result) { |
3260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3261 DCHECK(!callback.is_null()); | 3261 DCHECK(!callback.is_null()); |
3262 | 3262 |
3263 // Step 3 of CloseFile. | 3263 // Step 3 of CloseFile. |
3264 // All the invocation of |callback| from operations initiated from CloseFile | 3264 // All the invocation of |callback| from operations initiated from CloseFile |
3265 // must go through here. Removes the |file_path| from the remembered set so | 3265 // must go through here. Removes the |file_path| from the remembered set so |
3266 // that subsequent operations can open the file again. | 3266 // that subsequent operations can open the file again. |
3267 open_files_.erase(file_path); | 3267 open_files_.erase(file_path); |
3268 | 3268 |
3269 // Then invokes the user-supplied callback function. | 3269 // Then invokes the user-supplied callback function. |
3270 callback.Run(result); | 3270 callback.Run(result); |
3271 } | 3271 } |
3272 | 3272 |
3273 void GDataFileSystem::CheckLocalModificationAndRun( | 3273 void DriveFileSystem::CheckLocalModificationAndRun( |
3274 scoped_ptr<DriveEntryProto> entry_proto, | 3274 scoped_ptr<DriveEntryProto> entry_proto, |
3275 const GetEntryInfoCallback& callback) { | 3275 const GetEntryInfoCallback& callback) { |
3276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3277 DCHECK(entry_proto.get()); | 3277 DCHECK(entry_proto.get()); |
3278 DCHECK(!callback.is_null()); | 3278 DCHECK(!callback.is_null()); |
3279 | 3279 |
3280 // For entries that will never be cached, use the original entry info as is. | 3280 // For entries that will never be cached, use the original entry info as is. |
3281 if (!entry_proto->has_file_specific_info() || | 3281 if (!entry_proto->has_file_specific_info() || |
3282 entry_proto->file_specific_info().is_hosted_document()) { | 3282 entry_proto->file_specific_info().is_hosted_document()) { |
3283 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 3283 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
3284 return; | 3284 return; |
3285 } | 3285 } |
3286 | 3286 |
3287 // Checks if the file is cached and modified locally. | 3287 // Checks if the file is cached and modified locally. |
3288 const std::string resource_id = entry_proto->resource_id(); | 3288 const std::string resource_id = entry_proto->resource_id(); |
3289 const std::string md5 = entry_proto->file_specific_info().file_md5(); | 3289 const std::string md5 = entry_proto->file_specific_info().file_md5(); |
3290 cache_->GetCacheEntryOnUIThread( | 3290 cache_->GetCacheEntryOnUIThread( |
3291 resource_id, | 3291 resource_id, |
3292 md5, | 3292 md5, |
3293 base::Bind( | 3293 base::Bind( |
3294 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry, | 3294 &DriveFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry, |
3295 ui_weak_ptr_, base::Passed(&entry_proto), callback)); | 3295 ui_weak_ptr_, base::Passed(&entry_proto), callback)); |
3296 } | 3296 } |
3297 | 3297 |
3298 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry( | 3298 void DriveFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry( |
3299 scoped_ptr<DriveEntryProto> entry_proto, | 3299 scoped_ptr<DriveEntryProto> entry_proto, |
3300 const GetEntryInfoCallback& callback, | 3300 const GetEntryInfoCallback& callback, |
3301 bool success, | 3301 bool success, |
3302 const DriveCacheEntry& cache_entry) { | 3302 const DriveCacheEntry& cache_entry) { |
3303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3304 DCHECK(!callback.is_null()); | 3304 DCHECK(!callback.is_null()); |
3305 | 3305 |
3306 // When no dirty cache is found, use the original entry info as is. | 3306 // When no dirty cache is found, use the original entry info as is. |
3307 if (!success || !cache_entry.is_dirty()) { | 3307 if (!success || !cache_entry.is_dirty()) { |
3308 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 3308 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
3309 return; | 3309 return; |
3310 } | 3310 } |
3311 | 3311 |
3312 // Gets the cache file path. | 3312 // Gets the cache file path. |
3313 const std::string& resource_id = entry_proto->resource_id(); | 3313 const std::string& resource_id = entry_proto->resource_id(); |
3314 const std::string& md5 = entry_proto->file_specific_info().file_md5(); | 3314 const std::string& md5 = entry_proto->file_specific_info().file_md5(); |
3315 cache_->GetFileOnUIThread( | 3315 cache_->GetFileOnUIThread( |
3316 resource_id, | 3316 resource_id, |
3317 md5, | 3317 md5, |
3318 base::Bind( | 3318 base::Bind( |
3319 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile, | 3319 &DriveFileSystem::CheckLocalModificationAndRunAfterGetCacheFile, |
3320 ui_weak_ptr_, base::Passed(&entry_proto), callback)); | 3320 ui_weak_ptr_, base::Passed(&entry_proto), callback)); |
3321 } | 3321 } |
3322 | 3322 |
3323 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile( | 3323 void DriveFileSystem::CheckLocalModificationAndRunAfterGetCacheFile( |
3324 scoped_ptr<DriveEntryProto> entry_proto, | 3324 scoped_ptr<DriveEntryProto> entry_proto, |
3325 const GetEntryInfoCallback& callback, | 3325 const GetEntryInfoCallback& callback, |
3326 DriveFileError error, | 3326 DriveFileError error, |
3327 const std::string& resource_id, | 3327 const std::string& resource_id, |
3328 const std::string& md5, | 3328 const std::string& md5, |
3329 const FilePath& local_cache_path) { | 3329 const FilePath& local_cache_path) { |
3330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3331 DCHECK(!callback.is_null()); | 3331 DCHECK(!callback.is_null()); |
3332 | 3332 |
3333 // When no dirty cache is found, use the original entry info as is. | 3333 // When no dirty cache is found, use the original entry info as is. |
3334 if (error != DRIVE_FILE_OK) { | 3334 if (error != DRIVE_FILE_OK) { |
3335 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 3335 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
3336 return; | 3336 return; |
3337 } | 3337 } |
3338 | 3338 |
3339 // If the cache is dirty, obtain the file info from the cache file itself. | 3339 // If the cache is dirty, obtain the file info from the cache file itself. |
3340 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; | 3340 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; |
3341 bool* get_file_info_result = new bool(false); | 3341 bool* get_file_info_result = new bool(false); |
3342 util::PostBlockingPoolSequencedTaskAndReply( | 3342 util::PostBlockingPoolSequencedTaskAndReply( |
3343 FROM_HERE, | 3343 FROM_HERE, |
3344 blocking_task_runner_, | 3344 blocking_task_runner_, |
3345 base::Bind(&GetFileInfoOnBlockingPool, | 3345 base::Bind(&GetFileInfoOnBlockingPool, |
3346 local_cache_path, | 3346 local_cache_path, |
3347 base::Unretained(file_info), | 3347 base::Unretained(file_info), |
3348 base::Unretained(get_file_info_result)), | 3348 base::Unretained(get_file_info_result)), |
3349 base::Bind(&GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo, | 3349 base::Bind(&DriveFileSystem::CheckLocalModificationAndRunAfterGetFileInfo, |
3350 ui_weak_ptr_, | 3350 ui_weak_ptr_, |
3351 base::Passed(&entry_proto), | 3351 base::Passed(&entry_proto), |
3352 callback, | 3352 callback, |
3353 base::Owned(file_info), | 3353 base::Owned(file_info), |
3354 base::Owned(get_file_info_result))); | 3354 base::Owned(get_file_info_result))); |
3355 } | 3355 } |
3356 | 3356 |
3357 void GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo( | 3357 void DriveFileSystem::CheckLocalModificationAndRunAfterGetFileInfo( |
3358 scoped_ptr<DriveEntryProto> entry_proto, | 3358 scoped_ptr<DriveEntryProto> entry_proto, |
3359 const GetEntryInfoCallback& callback, | 3359 const GetEntryInfoCallback& callback, |
3360 base::PlatformFileInfo* file_info, | 3360 base::PlatformFileInfo* file_info, |
3361 bool* get_file_info_result) { | 3361 bool* get_file_info_result) { |
3362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3363 DCHECK(!callback.is_null()); | 3363 DCHECK(!callback.is_null()); |
3364 | 3364 |
3365 if (!*get_file_info_result) { | 3365 if (!*get_file_info_result) { |
3366 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, scoped_ptr<DriveEntryProto>()); | 3366 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, scoped_ptr<DriveEntryProto>()); |
3367 return; | 3367 return; |
3368 } | 3368 } |
3369 | 3369 |
3370 PlatformFileInfoProto entry_file_info; | 3370 PlatformFileInfoProto entry_file_info; |
3371 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3371 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3372 *entry_proto->mutable_file_info() = entry_file_info; | 3372 *entry_proto->mutable_file_info() = entry_file_info; |
3373 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 3373 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
3374 } | 3374 } |
3375 | 3375 |
3376 } // namespace gdata | 3376 } // namespace gdata |
OLD | NEW |