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

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

Issue 10800092: Database support for GDataDirectoryService. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 const FilePath local_file_path; 765 const FilePath local_file_path;
766 const FilePath remote_file_path; 766 const FilePath remote_file_path;
767 const FileOperationCallback callback; 767 const FileOperationCallback callback;
768 }; 768 };
769 769
770 // GDataFileSystem class implementation. 770 // GDataFileSystem class implementation.
771 771
772 GDataFileSystem::GDataFileSystem( 772 GDataFileSystem::GDataFileSystem(
773 Profile* profile, 773 Profile* profile,
774 GDataCache* cache, 774 GDataCache* cache,
775 GDataDirectoryService* directory_service,
775 DocumentsServiceInterface* documents_service, 776 DocumentsServiceInterface* documents_service,
776 GDataUploaderInterface* uploader, 777 GDataUploaderInterface* uploader,
777 DriveWebAppsRegistryInterface* webapps_registry, 778 DriveWebAppsRegistryInterface* webapps_registry,
778 base::SequencedTaskRunner* blocking_task_runner) 779 base::SequencedTaskRunner* blocking_task_runner)
779 : profile_(profile), 780 : profile_(profile),
780 cache_(cache), 781 cache_(cache),
782 directory_service_(directory_service),
781 uploader_(uploader), 783 uploader_(uploader),
782 documents_service_(documents_service), 784 documents_service_(documents_service),
783 webapps_registry_(webapps_registry), 785 webapps_registry_(webapps_registry),
784 update_timer_(true /* retain_user_task */, true /* is_repeating */), 786 update_timer_(true /* retain_user_task */, true /* is_repeating */),
785 hide_hosted_docs_(false), 787 hide_hosted_docs_(false),
786 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 788 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
787 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()), 789 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()),
788 blocking_task_runner_(blocking_task_runner) { 790 blocking_task_runner_(blocking_task_runner) {
789 // Should be created from the file browser extension API on UI thread. 791 // Should be created from the file browser extension API on UI thread.
790 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 792 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
791 } 793 }
792 794
793 void GDataFileSystem::Initialize() { 795 void GDataFileSystem::Initialize() {
794 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
795 797
796 documents_service_->Initialize(profile_); 798 documents_service_->Initialize(profile_);
797 799
798 directory_service_.reset(new GDataDirectoryService);
799
800 PrefService* pref_service = profile_->GetPrefs(); 800 PrefService* pref_service = profile_->GetPrefs();
801 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); 801 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles);
802 802
803 InitializePreferenceObserver(); 803 InitializePreferenceObserver();
804 } 804 }
805 805
806 void GDataFileSystem::CheckForUpdates() { 806 void GDataFileSystem::CheckForUpdates() {
807 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 807 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
808 ContentOrigin initial_origin = directory_service_->origin(); 808 ContentOrigin initial_origin = directory_service_->origin();
809 if (initial_origin == FROM_SERVER) { 809 if (initial_origin == FROM_SERVER) {
(...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after
2132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2133 2133
2134 GDataFileError error = GDataToGDataFileError(status); 2134 GDataFileError error = GDataToGDataFileError(status);
2135 2135
2136 scoped_ptr<GDataEntry> fresh_entry; 2136 scoped_ptr<GDataEntry> fresh_entry;
2137 if (error == GDATA_FILE_OK) { 2137 if (error == GDATA_FILE_OK) {
2138 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); 2138 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data));
2139 if (doc_entry.get()) { 2139 if (doc_entry.get()) {
2140 fresh_entry.reset( 2140 fresh_entry.reset(
2141 GDataEntry::FromDocumentEntry(NULL, doc_entry.get(), 2141 GDataEntry::FromDocumentEntry(NULL, doc_entry.get(),
2142 directory_service_.get())); 2142 directory_service_));
2143 } 2143 }
2144 if (!fresh_entry.get() || !fresh_entry->AsGDataFile()) { 2144 if (!fresh_entry.get() || !fresh_entry->AsGDataFile()) {
2145 LOG(ERROR) << "Got invalid entry from server for " << params.resource_id; 2145 LOG(ERROR) << "Got invalid entry from server for " << params.resource_id;
2146 error = GDATA_FILE_ERROR_FAILED; 2146 error = GDATA_FILE_ERROR_FAILED;
2147 } 2147 }
2148 } 2148 }
2149 2149
2150 if (error != GDATA_FILE_OK) { 2150 if (error != GDATA_FILE_OK) {
2151 if (!params.get_file_callback.is_null()) { 2151 if (!params.get_file_callback.is_null()) {
2152 params.get_file_callback.Run(error, 2152 params.get_file_callback.Run(error,
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
2668 if (!callback.is_null()) 2668 if (!callback.is_null())
2669 callback.Run(error, result_vec.Pass()); 2669 callback.Run(error, result_vec.Pass());
2670 return; 2670 return;
2671 } 2671 }
2672 2672
2673 // Go through all entires generated by the feed and add them to the search 2673 // Go through all entires generated by the feed and add them to the search
2674 // result directory. 2674 // result directory.
2675 for (size_t i = 0; i < feed->entries().size(); ++i) { 2675 for (size_t i = 0; i < feed->entries().size(); ++i) {
2676 DocumentEntry* doc = const_cast<DocumentEntry*>(feed->entries()[i]); 2676 DocumentEntry* doc = const_cast<DocumentEntry*>(feed->entries()[i]);
2677 scoped_ptr<GDataEntry> entry( 2677 scoped_ptr<GDataEntry> entry(
2678 GDataEntry::FromDocumentEntry(NULL, doc, directory_service_.get())); 2678 GDataEntry::FromDocumentEntry(NULL, doc, directory_service_));
2679 2679
2680 if (!entry.get()) 2680 if (!entry.get())
2681 continue; 2681 continue;
2682 2682
2683 DCHECK_EQ(doc->resource_id(), entry->resource_id()); 2683 DCHECK_EQ(doc->resource_id(), entry->resource_id());
2684 DCHECK(!entry->is_deleted()); 2684 DCHECK(!entry->is_deleted());
2685 2685
2686 std::string entry_resource_id = entry->resource_id(); 2686 std::string entry_resource_id = entry->resource_id();
2687 2687
2688 // This will do nothing if the entry is not already present in file system. 2688 // This will do nothing if the entry is not already present in file system.
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
2985 2985
2986 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); 2986 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data));
2987 if (!doc_entry.get()) { 2987 if (!doc_entry.get()) {
2988 if (!callback.is_null()) 2988 if (!callback.is_null())
2989 callback.Run(GDATA_FILE_ERROR_FAILED); 2989 callback.Run(GDATA_FILE_ERROR_FAILED);
2990 2990
2991 return; 2991 return;
2992 } 2992 }
2993 2993
2994 GDataEntry* entry = GDataEntry::FromDocumentEntry( 2994 GDataEntry* entry = GDataEntry::FromDocumentEntry(
2995 directory_service_->root(), doc_entry.get(), directory_service_.get()); 2995 directory_service_->root(), doc_entry.get(), directory_service_);
2996 if (!entry) { 2996 if (!entry) {
2997 if (!callback.is_null()) 2997 if (!callback.is_null())
2998 callback.Run(GDATA_FILE_ERROR_FAILED); 2998 callback.Run(GDATA_FILE_ERROR_FAILED);
2999 2999
3000 return; 3000 return;
3001 } 3001 }
3002 3002
3003 // |entry| was added in the root directory on the server, so we should 3003 // |entry| was added in the root directory on the server, so we should
3004 // first add it to |root_| to mirror the state and then move it to the 3004 // first add it to |root_| to mirror the state and then move it to the
3005 // destination directory by AddEntryToDirectory(). 3005 // destination directory by AddEntryToDirectory().
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
3486 root_feed_upload_link->href()); 3486 root_feed_upload_link->href());
3487 *feed_changestamp = feed->largest_changestamp(); 3487 *feed_changestamp = feed->largest_changestamp();
3488 DCHECK_GE(*feed_changestamp, 0); 3488 DCHECK_GE(*feed_changestamp, 0);
3489 } 3489 }
3490 3490
3491 for (ScopedVector<DocumentEntry>::const_iterator iter = 3491 for (ScopedVector<DocumentEntry>::const_iterator iter =
3492 feed->entries().begin(); 3492 feed->entries().begin();
3493 iter != feed->entries().end(); ++iter) { 3493 iter != feed->entries().end(); ++iter) {
3494 DocumentEntry* doc = *iter; 3494 DocumentEntry* doc = *iter;
3495 GDataEntry* entry = GDataEntry::FromDocumentEntry( 3495 GDataEntry* entry = GDataEntry::FromDocumentEntry(
3496 NULL, doc, directory_service_.get()); 3496 NULL, doc, directory_service_);
3497 // Some document entries don't map into files (i.e. sites). 3497 // Some document entries don't map into files (i.e. sites).
3498 if (!entry) 3498 if (!entry)
3499 continue; 3499 continue;
3500 // Count the number of files. 3500 // Count the number of files.
3501 GDataFile* as_file = entry->AsGDataFile(); 3501 GDataFile* as_file = entry->AsGDataFile();
3502 if (as_file) { 3502 if (as_file) {
3503 if (as_file->is_hosted_document()) 3503 if (as_file->is_hosted_document())
3504 ++uma_stats->num_hosted_documents; 3504 ++uma_stats->num_hosted_documents;
3505 else 3505 else
3506 ++uma_stats->num_regular_files; 3506 ++uma_stats->num_regular_files;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3584 return GDATA_FILE_ERROR_FAILED; 3584 return GDATA_FILE_ERROR_FAILED;
3585 3585
3586 // Check if parent is a directory since in theory since this is a callback 3586 // Check if parent is a directory since in theory since this is a callback
3587 // something could in the meantime have nuked the parent dir and created a 3587 // something could in the meantime have nuked the parent dir and created a
3588 // file with the exact same name. 3588 // file with the exact same name.
3589 GDataDirectory* parent_dir = entry->AsGDataDirectory(); 3589 GDataDirectory* parent_dir = entry->AsGDataDirectory();
3590 if (!parent_dir) 3590 if (!parent_dir)
3591 return GDATA_FILE_ERROR_FAILED; 3591 return GDATA_FILE_ERROR_FAILED;
3592 3592
3593 GDataEntry* new_entry = GDataEntry::FromDocumentEntry( 3593 GDataEntry* new_entry = GDataEntry::FromDocumentEntry(
3594 parent_dir, doc_entry.get(), directory_service_.get()); 3594 parent_dir, doc_entry.get(), directory_service_);
3595 if (!new_entry) 3595 if (!new_entry)
3596 return GDATA_FILE_ERROR_FAILED; 3596 return GDATA_FILE_ERROR_FAILED;
3597 3597
3598 parent_dir->AddEntry(new_entry); 3598 parent_dir->AddEntry(new_entry);
3599 3599
3600 NotifyDirectoryChanged(directory_path); 3600 NotifyDirectoryChanged(directory_path);
3601 return GDATA_FILE_OK; 3601 return GDATA_FILE_OK;
3602 } 3602 }
3603 3603
3604 GDataFileSystem::FindMissingDirectoryResult 3604 GDataFileSystem::FindMissingDirectoryResult
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
3709 } 3709 }
3710 3710
3711 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); 3711 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory();
3712 if (!parent_dir) { 3712 if (!parent_dir) {
3713 callback.Run(); 3713 callback.Run();
3714 return; 3714 return;
3715 } 3715 }
3716 3716
3717 scoped_ptr<GDataEntry> new_entry( 3717 scoped_ptr<GDataEntry> new_entry(
3718 GDataEntry::FromDocumentEntry( 3718 GDataEntry::FromDocumentEntry(
3719 parent_dir, entry.get(), directory_service_.get())); 3719 parent_dir, entry.get(), directory_service_));
3720 if (!new_entry.get()) { 3720 if (!new_entry.get()) {
3721 callback.Run(); 3721 callback.Run();
3722 return; 3722 return;
3723 } 3723 }
3724 3724
3725 if (upload_mode == UPLOAD_EXISTING_FILE) { 3725 if (upload_mode == UPLOAD_EXISTING_FILE) {
3726 // Remove an existing entry, which should be present. 3726 // Remove an existing entry, which should be present.
3727 const std::string& resource_id = new_entry->resource_id(); 3727 const std::string& resource_id = new_entry->resource_id();
3728 directory_service_->GetEntryByResourceIdAsync(resource_id, 3728 directory_service_->GetEntryByResourceIdAsync(resource_id,
3729 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); 3729 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir));
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
4111 // must go through here. Removes the |file_path| from the remembered set so 4111 // must go through here. Removes the |file_path| from the remembered set so
4112 // that subsequent operations can open the file again. 4112 // that subsequent operations can open the file again.
4113 open_files_.erase(file_path); 4113 open_files_.erase(file_path);
4114 4114
4115 // Then invokes the user-supplied callback function. 4115 // Then invokes the user-supplied callback function.
4116 if (!callback.is_null()) 4116 if (!callback.is_null())
4117 callback.Run(result); 4117 callback.Run(result);
4118 } 4118 }
4119 4119
4120 } // namespace gdata 4120 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698