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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10827211: Replace GDataDirectory::TakeEntry with GDataDirectoryService::AddEntryToDirectory. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: expect/assert after RunBlockingTask Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_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"
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 FilePath new_file(file_name); 1109 FilePath new_file(file_name);
1110 if (new_file.Extension() == 1110 if (new_file.Extension() ==
1111 entry_proto->file_specific_info().document_extension()) { 1111 entry_proto->file_specific_info().document_extension()) {
1112 file_name = new_file.RemoveExtension().value(); 1112 file_name = new_file.RemoveExtension().value();
1113 } 1113 }
1114 } 1114 }
1115 1115
1116 documents_service_->RenameResource( 1116 documents_service_->RenameResource(
1117 GURL(entry_proto->edit_url()), 1117 GURL(entry_proto->edit_url()),
1118 file_name, 1118 file_name,
1119 base::Bind(&GDataFileSystem::OnRenameResourceCompleted, 1119 base::Bind(&GDataFileSystem::RenameFileOnFileSystem,
1120 ui_weak_ptr_, 1120 ui_weak_ptr_,
1121 file_path, 1121 file_path,
1122 file_name, 1122 file_name,
1123 callback)); 1123 callback));
1124 } 1124 }
1125 1125
1126 void GDataFileSystem::Move(const FilePath& src_file_path, 1126 void GDataFileSystem::Move(const FilePath& src_file_path,
1127 const FilePath& dest_file_path, 1127 const FilePath& dest_file_path,
1128 const FileOperationCallback& callback) { 1128 const FileOperationCallback& callback) {
1129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 FilePathUpdateCallback add_file_to_directory_callback = 1185 FilePathUpdateCallback add_file_to_directory_callback =
1186 base::Bind(&GDataFileSystem::AddEntryToDirectory, 1186 base::Bind(&GDataFileSystem::AddEntryToDirectory,
1187 ui_weak_ptr_, 1187 ui_weak_ptr_,
1188 dest_file_path.DirName(), 1188 dest_file_path.DirName(),
1189 callback); 1189 callback);
1190 1190
1191 FilePathUpdateCallback remove_file_from_directory_callback = 1191 FilePathUpdateCallback remove_file_from_directory_callback =
1192 base::Bind(&GDataFileSystem::RemoveEntryFromDirectory, 1192 base::Bind(&GDataFileSystem::RemoveEntryFromDirectory,
1193 ui_weak_ptr_, 1193 ui_weak_ptr_,
1194 src_file_path.DirName(), 1194 src_file_path.DirName(),
1195 add_file_to_directory_callback); 1195 add_file_to_directory_callback);
satorux1 2012/08/08 23:25:01 wow, move operation is super complicated...
1196 1196
1197 Rename(src_file_path, dest_file_path.BaseName().value(), 1197 Rename(src_file_path, dest_file_path.BaseName().value(),
1198 remove_file_from_directory_callback); 1198 remove_file_from_directory_callback);
1199 } 1199 }
1200 1200
1201 void GDataFileSystem::AddEntryToDirectory( 1201 void GDataFileSystem::AddEntryToDirectory(
1202 const FilePath& dir_path, 1202 const FilePath& dir_path,
1203 const FileOperationCallback& callback, 1203 const FileOperationCallback& callback,
1204 GDataFileError error, 1204 GDataFileError error,
1205 const FilePath& file_path) { 1205 const FilePath& file_path) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 MessageLoop::current()->PostTask(FROM_HERE, 1260 MessageLoop::current()->PostTask(FROM_HERE,
1261 base::Bind(callback, error, file_path)); 1261 base::Bind(callback, error, file_path));
1262 } 1262 }
1263 return; 1263 return;
1264 } 1264 }
1265 1265
1266 documents_service_->RemoveResourceFromDirectory( 1266 documents_service_->RemoveResourceFromDirectory(
1267 dir->content_url(), 1267 dir->content_url(),
1268 entry->edit_url(), 1268 entry->edit_url(),
1269 entry->resource_id(), 1269 entry->resource_id(),
1270 base::Bind(&GDataFileSystem::OnRemoveEntryFromDirectoryCompleted, 1270 base::Bind(&GDataFileSystem::RemoveEntryFromDirectoryOnFileSystem,
1271 ui_weak_ptr_, 1271 ui_weak_ptr_,
1272 callback, 1272 callback,
1273 file_path, 1273 file_path,
1274 dir_path)); 1274 dir_path));
1275 } 1275 }
1276 1276
1277 void GDataFileSystem::Remove(const FilePath& file_path, 1277 void GDataFileSystem::Remove(const FilePath& file_path,
1278 bool is_recursive, 1278 bool is_recursive,
1279 const FileOperationCallback& callback) { 1279 const FileOperationCallback& callback) {
1280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
2001 scoped_ptr<GDataEntry> entry(it->second); 2001 scoped_ptr<GDataEntry> entry(it->second);
2002 // Skip if it's not a file (i.e. directory). 2002 // Skip if it's not a file (i.e. directory).
2003 if (!entry->AsGDataFile()) 2003 if (!entry->AsGDataFile())
2004 continue; 2004 continue;
2005 directory->AddEntry(entry.release()); 2005 directory->AddEntry(entry.release());
2006 } 2006 }
2007 2007
2008 // Note that there may be no change in the directory, but it's expensive to 2008 // Note that there may be no change in the directory, but it's expensive to
2009 // check if the new metadata matches the existing one, so we just always 2009 // check if the new metadata matches the existing one, so we just always
2010 // notify that the directory is changed. 2010 // notify that the directory is changed.
2011 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, 2011 OnDirectoryChanged(directory_path);
2012 observers_, OnDirectoryChanged(directory_path));
2013 DVLOG(1) << "Directory refreshed: " << directory_path.value(); 2012 DVLOG(1) << "Directory refreshed: " << directory_path.value();
2014 } 2013 }
2015 2014
2016 void GDataFileSystem::UpdateFileByResourceId( 2015 void GDataFileSystem::UpdateFileByResourceId(
2017 const std::string& resource_id, 2016 const std::string& resource_id,
2018 const FileOperationCallback& callback) { 2017 const FileOperationCallback& callback) {
2019 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2018 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2020 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2019 BrowserThread::CurrentlyOn(BrowserThread::IO));
2021 RunTaskOnUIThread( 2020 RunTaskOnUIThread(
2022 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, 2021 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread,
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
2393 int root_feed_changestamp) { 2392 int root_feed_changestamp) {
2394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2395 2394
2396 return feed_loader_->UpdateFromFeed(feed_list, 2395 return feed_loader_->UpdateFromFeed(feed_list,
2397 start_changestamp, 2396 start_changestamp,
2398 root_feed_changestamp); 2397 root_feed_changestamp);
2399 } 2398 }
2400 2399
2401 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, 2400 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback,
2402 GDataFileError error, 2401 GDataFileError error,
2403 const FilePath& file_path) { 2402 const FilePath& file_path) {
satorux1 2012/08/08 23:25:01 this is weird. file_path is not used... can you co
achuithb 2012/08/09 00:12:51 Done. We have this in a lot of places because we
satorux1 2012/08/09 00:26:24 don't have to spend time finding them but if we se
2404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2405 if (!callback.is_null()) 2404 if (!callback.is_null())
2406 callback.Run(error); 2405 callback.Run(error);
2407 } 2406 }
2408 2407
2409 void GDataFileSystem::OnRenameResourceCompleted(
2410 const FilePath& file_path,
2411 const FilePath::StringType& new_name,
2412 const FilePathUpdateCallback& callback,
2413 GDataErrorCode status,
2414 const GURL& document_url) {
2415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2416
2417 FilePath updated_file_path;
2418 GDataFileError error = util::GDataToGDataFileError(status);
2419 if (error == GDATA_FILE_OK)
2420 error = RenameFileOnFilesystem(file_path, new_name, &updated_file_path);
2421
2422 if (!callback.is_null())
2423 callback.Run(error, updated_file_path);
2424 }
2425
2426 void GDataFileSystem::OnCopyDocumentCompleted( 2408 void GDataFileSystem::OnCopyDocumentCompleted(
2427 const FilePath& dir_path, 2409 const FilePath& dir_path,
2428 const FileOperationCallback& callback, 2410 const FileOperationCallback& callback,
2429 GDataErrorCode status, 2411 GDataErrorCode status,
2430 scoped_ptr<base::Value> data) { 2412 scoped_ptr<base::Value> data) {
2431 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2432 2414
2433 GDataFileError error = util::GDataToGDataFileError(status); 2415 GDataFileError error = util::GDataToGDataFileError(status);
2434 if (error != GDATA_FILE_OK) { 2416 if (error != GDATA_FILE_OK) {
2435 if (!callback.is_null()) 2417 if (!callback.is_null())
2436 callback.Run(error); 2418 callback.Run(error);
2437 2419
2438 return; 2420 return;
2439 } 2421 }
2440 2422
2441 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); 2423 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data));
2442 if (!doc_entry.get()) { 2424 if (!doc_entry.get()) {
2443 if (!callback.is_null()) 2425 if (!callback.is_null())
2444 callback.Run(GDATA_FILE_ERROR_FAILED); 2426 callback.Run(GDATA_FILE_ERROR_FAILED);
2445 2427
2446 return; 2428 return;
2447 } 2429 }
2448 2430
2449 GDataEntry* entry = GDataEntry::FromDocumentEntry( 2431 GDataEntry* entry = GDataEntry::FromDocumentEntry(
2450 directory_service_->root(), doc_entry.get(), directory_service_.get()); 2432 NULL, doc_entry.get(), directory_service_.get());
2451 if (!entry) { 2433 if (!entry) {
2452 if (!callback.is_null()) 2434 if (!callback.is_null())
2453 callback.Run(GDATA_FILE_ERROR_FAILED); 2435 callback.Run(GDATA_FILE_ERROR_FAILED);
2454 2436
2455 return; 2437 return;
2456 } 2438 }
2457 2439
2458 // |entry| was added in the root directory on the server, so we should 2440 // |entry| was added in the root directory on the server, so we should
2459 // first add it to |root_| to mirror the state and then move it to the 2441 // first add it to |root_| to mirror the state and then move it to the
2460 // destination directory by AddEntryToDirectory(). 2442 // destination directory by AddEntryToDirectory().
2461 directory_service_->root()->AddEntry(entry); 2443 directory_service_->root()->AddEntry(entry);
2462 AddEntryToDirectory(dir_path, callback, GDATA_FILE_OK, entry->GetFilePath()); 2444 AddEntryToDirectory(dir_path, callback, GDATA_FILE_OK, entry->GetFilePath());
2463 } 2445 }
2464 2446
2465 void GDataFileSystem::OnAddEntryToDirectoryCompleted( 2447 void GDataFileSystem::OnAddEntryToDirectoryCompleted(
2466 const FileOperationCallback& callback, 2448 const FileOperationCallback& callback,
2467 const FilePath& file_path, 2449 const FilePath& file_path,
2468 const FilePath& dir_path, 2450 const FilePath& dir_path,
2469 GDataErrorCode status, 2451 GDataErrorCode status,
2470 const GURL& document_url) { 2452 const GURL& document_url) {
2471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2472 2454
2473 GDataFileError error = util::GDataToGDataFileError(status); 2455 GDataFileError error = util::GDataToGDataFileError(status);
2474 if (error == GDATA_FILE_OK) { 2456 if (error == GDATA_FILE_OK) {
2475 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); 2457 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
2476 if (entry) { 2458 if (entry) {
2477 DCHECK_EQ(directory_service_->root(), entry->parent()); 2459 DCHECK_EQ(directory_service_->root(), entry->parent());
2478 error = AddEntryToDirectoryOnFilesystem(entry, dir_path); 2460 directory_service_->AddEntryToDirectory(dir_path, entry,
2461 base::Bind(
2462 &GDataFileSystem::OnAddEntryToDirectoryWithFileOperationCallback,
2463 ui_weak_ptr_,
2464 callback));
2465 return;
2479 } else { 2466 } else {
2480 error = GDATA_FILE_ERROR_NOT_FOUND; 2467 error = GDATA_FILE_ERROR_NOT_FOUND;
2481 } 2468 }
2482 } 2469 }
2483 2470
2484 if (!callback.is_null()) 2471 if (!callback.is_null())
2485 callback.Run(error); 2472 callback.Run(error);
2486 } 2473 }
2487 2474
2488 void GDataFileSystem::OnRemoveEntryFromDirectoryCompleted(
2489 const FilePathUpdateCallback& callback,
2490 const FilePath& file_path,
2491 const FilePath& dir_path,
2492 GDataErrorCode status,
2493 const GURL& document_url) {
2494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2495
2496 FilePath updated_file_path = file_path;
2497 GDataFileError error = util::GDataToGDataFileError(status);
2498 if (error == GDATA_FILE_OK)
2499 error = RemoveEntryFromDirectoryOnFilesystem(file_path, dir_path,
2500 &updated_file_path);
2501
2502 if (!callback.is_null())
2503 callback.Run(error, updated_file_path);
2504 }
2505
2506 void GDataFileSystem::OnRemovedDocument( 2475 void GDataFileSystem::OnRemovedDocument(
2507 const FileOperationCallback& callback, 2476 const FileOperationCallback& callback,
2508 const FilePath& file_path, 2477 const FilePath& file_path,
2509 GDataErrorCode status, 2478 GDataErrorCode status,
2510 const GURL& document_url) { 2479 const GURL& document_url) {
2511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2512 2481
2513 GDataFileError error = util::GDataToGDataFileError(status); 2482 GDataFileError error = util::GDataToGDataFileError(status);
2514 2483
2515 if (error == GDATA_FILE_OK) 2484 if (error == GDATA_FILE_OK)
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2619 } 2588 }
2620 } 2589 }
2621 2590
2622 void GDataFileSystem::OnDownloadStoredToCache(GDataFileError error, 2591 void GDataFileSystem::OnDownloadStoredToCache(GDataFileError error,
2623 const std::string& resource_id, 2592 const std::string& resource_id,
2624 const std::string& md5) { 2593 const std::string& md5) {
2625 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2594 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2626 // Nothing much to do here for now. 2595 // Nothing much to do here for now.
2627 } 2596 }
2628 2597
2629 GDataFileError GDataFileSystem::RenameFileOnFilesystem( 2598 void GDataFileSystem::RenameFileOnFileSystem(
2630 const FilePath& file_path, 2599 const FilePath& file_path,
2631 const FilePath::StringType& new_name, 2600 const FilePath::StringType& new_name,
2632 FilePath* updated_file_path) { 2601 const FilePathUpdateCallback& callback,
2602 GDataErrorCode status,
2603 const GURL& document_url) {
2633 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2634 DCHECK(updated_file_path); 2605
2606 const GDataFileError error = util::GDataToGDataFileError(status);
2607 if (error != GDATA_FILE_OK) {
2608 if (!callback.is_null())
2609 callback.Run(error, FilePath());
2610 return;
2611 }
2635 2612
2636 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); 2613 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
2637 if (!entry) 2614 if (!entry) {
2638 return GDATA_FILE_ERROR_NOT_FOUND; 2615 if (!callback.is_null())
2616 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath());
2617 return;
2618 }
2639 2619
2640 DCHECK(entry->parent()); 2620 DCHECK(entry->parent());
2641 entry->set_title(new_name); 2621 entry->set_title(new_name);
2642 // After changing the title of the entry, call TakeFile() to remove the 2622 // After changing the title of the entry, call AddEntryToDirectory() to remove
2643 // entry from its parent directory and then add it back in order to go 2623 // the entry from its parent directory and then add it back in order to go
2644 // through the file name de-duplication. 2624 // through the file name de-duplication.
2645 // TODO(achuith/satorux/zel): This code is fragile. The title has been 2625 // TODO(achuith/satorux/zel): This code is fragile. The title has been
2646 // changed, but not the file_name. TakeEntry removes the child based on the 2626 // changed, but not the file_name. AddEntryToDirectory calls RemoveChild to
2647 // old file_name, and then re-adds the child by first assigning the new title 2627 // remove the child based on the old file_name, and then re-adds the child by
2648 // to file_name. http://crbug.com/30157 2628 // first assigning the new title to file_name. http://crbug.com/30157
2649 if (!entry->parent()->TakeEntry(entry)) 2629 directory_service_->AddEntryToDirectory(entry->parent()->GetFilePath(), entry,
satorux1 2012/08/08 23:25:01 nit: when it cannot fit one line, let's align para
achuithb 2012/08/09 00:12:51 Done.
2650 return GDATA_FILE_ERROR_FAILED; 2630 base::Bind(&GDataFileSystem::OnAddEntryToDirectoryWithFileUpdateCallback,
2651 2631 ui_weak_ptr_,
2652 *updated_file_path = entry->GetFilePath(); 2632 callback));
2653
2654 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
2655 OnDirectoryChanged(updated_file_path->DirName()));
2656 return GDATA_FILE_OK;
2657 } 2633 }
2658 2634
2659 GDataFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem( 2635 void GDataFileSystem::RemoveEntryFromDirectoryOnFileSystem(
2660 GDataEntry* entry, const FilePath& dir_path) { 2636 const FilePathUpdateCallback& callback,
2637 const FilePath& file_path,
2638 const FilePath& dir_path,
2639 GDataErrorCode status,
2640 const GURL& document_url) {
2661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2662 DCHECK(entry);
2663 2642
2664 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path); 2643 const GDataFileError error = util::GDataToGDataFileError(status);
2665 if (!dir_entry) 2644 if (error != GDATA_FILE_OK) {
2666 return GDATA_FILE_ERROR_NOT_FOUND; 2645 if (!callback.is_null())
2646 callback.Run(error, FilePath());
2647 return;
2648 }
2667 2649
2668 GDataDirectory* dir = dir_entry->AsGDataDirectory(); 2650 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
2669 if (!dir) 2651 if (!entry) {
2670 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; 2652 if (!callback.is_null())
2653 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath());
2654 return;
2655 }
2671 2656
2672 if (!dir->TakeEntry(entry)) 2657 directory_service_->AddEntryToDirectory(
2673 return GDATA_FILE_ERROR_FAILED; 2658 directory_service_->root()->GetFilePath(), entry,
satorux1 2012/08/08 23:25:01 nit: move entry to the next line
achuithb 2012/08/09 00:12:51 Done.
2674 2659 base::Bind(&GDataFileSystem::OnAddEntryToDirectoryWithFileUpdateCallback,
2675 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, 2660 ui_weak_ptr_,
2676 OnDirectoryChanged(dir_path)); 2661 callback));
2677 return GDATA_FILE_OK;
2678 } 2662 }
2679 2663
2680 GDataFileError GDataFileSystem::RemoveEntryFromDirectoryOnFilesystem( 2664 void GDataFileSystem::OnAddEntryToDirectoryWithFileUpdateCallback(
2681 const FilePath& file_path, const FilePath& dir_path, 2665 const FilePathUpdateCallback& callback,
2682 FilePath* updated_file_path) { 2666 GDataFileError error,
2683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2667 const FilePath& updated_file_path) {
2684 DCHECK(updated_file_path); 2668 if (error == GDATA_FILE_OK)
2669 OnDirectoryChanged(updated_file_path.DirName());
2685 2670
2686 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); 2671 if (!callback.is_null())
2687 if (!entry) 2672 callback.Run(error, updated_file_path);
2688 return GDATA_FILE_ERROR_NOT_FOUND; 2673 }
2689 2674
2690 GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path); 2675 void GDataFileSystem::OnAddEntryToDirectoryWithFileOperationCallback(
2691 if (!dir) 2676 const FileOperationCallback& callback,
2692 return GDATA_FILE_ERROR_NOT_FOUND; 2677 GDataFileError error,
2678 const FilePath& updated_file_path) {
2679 if (error == GDATA_FILE_OK)
2680 OnDirectoryChanged(updated_file_path.DirName());
2693 2681
2694 if (!dir->AsGDataDirectory()) 2682 if (!callback.is_null())
2695 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; 2683 callback.Run(error);
2696
2697 DCHECK_EQ(dir->AsGDataDirectory(), entry->parent());
2698
2699 if (!directory_service_->root()->TakeEntry(entry))
2700 return GDATA_FILE_ERROR_FAILED;
2701
2702 *updated_file_path = entry->GetFilePath();
2703
2704 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
2705 OnDirectoryChanged(updated_file_path->DirName()));
2706 return GDATA_FILE_OK;
2707 } 2684 }
2708 2685
2709 GDataFileError GDataFileSystem::RemoveEntryFromFileSystem( 2686 GDataFileError GDataFileSystem::RemoveEntryFromFileSystem(
2710 const FilePath& file_path) { 2687 const FilePath& file_path) {
2711 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2688 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2712 2689
2713 std::string resource_id; 2690 std::string resource_id;
2714 GDataFileError error = RemoveEntryFromGData(file_path, &resource_id); 2691 GDataFileError error = RemoveEntryFromGData(file_path, &resource_id);
2715 if (error != GDATA_FILE_OK) 2692 if (error != GDATA_FILE_OK)
2716 return error; 2693 return error;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2787 return GDATA_FILE_ERROR_FAILED; 2764 return GDATA_FILE_ERROR_FAILED;
2788 2765
2789 // Check if parent is a directory since in theory since this is a callback 2766 // Check if parent is a directory since in theory since this is a callback
2790 // something could in the meantime have nuked the parent dir and created a 2767 // something could in the meantime have nuked the parent dir and created a
2791 // file with the exact same name. 2768 // file with the exact same name.
2792 GDataDirectory* parent_dir = entry->AsGDataDirectory(); 2769 GDataDirectory* parent_dir = entry->AsGDataDirectory();
2793 if (!parent_dir) 2770 if (!parent_dir)
2794 return GDATA_FILE_ERROR_FAILED; 2771 return GDATA_FILE_ERROR_FAILED;
2795 2772
2796 GDataEntry* new_entry = GDataEntry::FromDocumentEntry( 2773 GDataEntry* new_entry = GDataEntry::FromDocumentEntry(
2797 parent_dir, doc_entry.get(), directory_service_.get()); 2774 NULL, doc_entry.get(), directory_service_.get());
2798 if (!new_entry) 2775 if (!new_entry)
2799 return GDATA_FILE_ERROR_FAILED; 2776 return GDATA_FILE_ERROR_FAILED;
2800 2777
2801 parent_dir->AddEntry(new_entry); 2778 parent_dir->AddEntry(new_entry);
2802 2779
2803 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, 2780 OnDirectoryChanged(directory_path);
2804 OnDirectoryChanged(directory_path));
2805 return GDATA_FILE_OK; 2781 return GDATA_FILE_OK;
2806 } 2782 }
2807 2783
2808 GDataFileSystem::FindMissingDirectoryResult 2784 GDataFileSystem::FindMissingDirectoryResult
2809 GDataFileSystem::FindFirstMissingParentDirectory( 2785 GDataFileSystem::FindFirstMissingParentDirectory(
2810 const FilePath& directory_path, 2786 const FilePath& directory_path,
2811 GURL* last_dir_content_url, 2787 GURL* last_dir_content_url,
2812 FilePath* first_missing_parent_path) { 2788 FilePath* first_missing_parent_path) {
2813 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2814 2790
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2855 return GDATA_FILE_ERROR_ACCESS_DENIED; 2831 return GDATA_FILE_ERROR_ACCESS_DENIED;
2856 2832
2857 // If it's a file (only files have resource id), get its resource id so that 2833 // If it's a file (only files have resource id), get its resource id so that
2858 // we can remove it after releasing the auto lock. 2834 // we can remove it after releasing the auto lock.
2859 if (entry->AsGDataFile()) 2835 if (entry->AsGDataFile())
2860 *resource_id = entry->AsGDataFile()->resource_id(); 2836 *resource_id = entry->AsGDataFile()->resource_id();
2861 2837
2862 GDataDirectory* parent_dir = entry->parent(); 2838 GDataDirectory* parent_dir = entry->parent();
2863 parent_dir->RemoveEntry(entry); 2839 parent_dir->RemoveEntry(entry);
2864 2840
2865 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, 2841 OnDirectoryChanged(parent_dir->GetFilePath());
2866 OnDirectoryChanged(parent_dir->GetFilePath()));
2867 return GDATA_FILE_OK; 2842 return GDATA_FILE_OK;
2868 } 2843 }
2869 2844
2870 void GDataFileSystem::AddUploadedFile( 2845 void GDataFileSystem::AddUploadedFile(
2871 UploadMode upload_mode, 2846 UploadMode upload_mode,
2872 const FilePath& virtual_dir_path, 2847 const FilePath& virtual_dir_path,
2873 scoped_ptr<DocumentEntry> entry, 2848 scoped_ptr<DocumentEntry> entry,
2874 const FilePath& file_content_path, 2849 const FilePath& file_content_path,
2875 GDataCache::FileOperationType cache_operation, 2850 GDataCache::FileOperationType cache_operation,
2876 const base::Closure& callback) { 2851 const base::Closure& callback) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2912 virtual_dir_path); 2887 virtual_dir_path);
2913 if (!dir_entry) 2888 if (!dir_entry)
2914 return; 2889 return;
2915 2890
2916 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); 2891 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory();
2917 if (!parent_dir) 2892 if (!parent_dir)
2918 return; 2893 return;
2919 2894
2920 scoped_ptr<GDataEntry> new_entry( 2895 scoped_ptr<GDataEntry> new_entry(
2921 GDataEntry::FromDocumentEntry( 2896 GDataEntry::FromDocumentEntry(
2922 parent_dir, entry.get(), directory_service_.get())); 2897 NULL, entry.get(), directory_service_.get()));
2923 if (!new_entry.get()) 2898 if (!new_entry.get())
2924 return; 2899 return;
2925 2900
2926 if (upload_mode == UPLOAD_EXISTING_FILE) { 2901 if (upload_mode == UPLOAD_EXISTING_FILE) {
2927 // Remove an existing entry, which should be present. 2902 // Remove an existing entry, which should be present.
2928 const std::string& resource_id = new_entry->resource_id(); 2903 const std::string& resource_id = new_entry->resource_id();
2929 directory_service_->GetEntryByResourceIdAsync(resource_id, 2904 directory_service_->GetEntryByResourceIdAsync(resource_id,
2930 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); 2905 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir));
2931 } 2906 }
2932 2907
2933 GDataFile* file = new_entry->AsGDataFile(); 2908 GDataFile* file = new_entry->AsGDataFile();
2934 DCHECK(file); 2909 DCHECK(file);
2935 const std::string& resource_id = file->resource_id(); 2910 const std::string& resource_id = file->resource_id();
2936 const std::string& md5 = file->file_md5(); 2911 const std::string& md5 = file->file_md5();
2937 parent_dir->AddEntry(new_entry.release()); 2912 parent_dir->AddEntry(new_entry.release());
2938 2913
2939 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, 2914 OnDirectoryChanged(virtual_dir_path);
2940 OnDirectoryChanged(virtual_dir_path));
2941 2915
2942 if (upload_mode == UPLOAD_NEW_FILE) { 2916 if (upload_mode == UPLOAD_NEW_FILE) {
2943 // Add the file to the cache if we have uploaded a new file. 2917 // Add the file to the cache if we have uploaded a new file.
2944 cache_->StoreOnUIThread(resource_id, 2918 cache_->StoreOnUIThread(resource_id,
2945 md5, 2919 md5,
2946 file_content_path, 2920 file_content_path,
2947 cache_operation, 2921 cache_operation,
2948 base::Bind(&OnCacheUpdatedForAddUploadedFile, 2922 base::Bind(&OnCacheUpdatedForAddUploadedFile,
2949 callback_runner.Release())); 2923 callback_runner.Release()));
2950 } else if (upload_mode == UPLOAD_EXISTING_FILE) { 2924 } else if (upload_mode == UPLOAD_EXISTING_FILE) {
(...skipping 10 matching lines...) Expand all
2961 void GDataFileSystem::Observe(int type, 2935 void GDataFileSystem::Observe(int type,
2962 const content::NotificationSource& source, 2936 const content::NotificationSource& source,
2963 const content::NotificationDetails& details) { 2937 const content::NotificationDetails& details) {
2964 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2965 2939
2966 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 2940 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
2967 std::string* pref_name = content::Details<std::string>(details).ptr(); 2941 std::string* pref_name = content::Details<std::string>(details).ptr();
2968 if (*pref_name == prefs::kDisableGDataHostedFiles) { 2942 if (*pref_name == prefs::kDisableGDataHostedFiles) {
2969 const FilePath root_path = directory_service_->root()->GetFilePath(); 2943 const FilePath root_path = directory_service_->root()->GetFilePath();
2970 // Kick off directory refresh when this setting changes. 2944 // Kick off directory refresh when this setting changes.
2971 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, 2945 OnDirectoryChanged(root_path);
2972 OnDirectoryChanged(root_path));
2973 } 2946 }
2974 } else { 2947 } else {
2975 NOTREACHED(); 2948 NOTREACHED();
2976 } 2949 }
2977 } 2950 }
2978 2951
2979 //============= GDataFileSystem: internal helper functions ===================== 2952 //============= GDataFileSystem: internal helper functions =====================
2980 2953
2981 void GDataFileSystem::InitializePreferenceObserver() { 2954 void GDataFileSystem::InitializePreferenceObserver() {
2982 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2955 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
3405 } 3378 }
3406 3379
3407 PlatformFileInfoProto entry_file_info; 3380 PlatformFileInfoProto entry_file_info;
3408 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 3381 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
3409 *entry_proto->mutable_file_info() = entry_file_info; 3382 *entry_proto->mutable_file_info() = entry_file_info;
3410 if (!callback.is_null()) 3383 if (!callback.is_null())
3411 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 3384 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3412 } 3385 }
3413 3386
3414 } // namespace gdata 3387 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698