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/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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 DocumentsServiceInterface* documents_service, | 509 DocumentsServiceInterface* documents_service, |
510 GDataUploaderInterface* uploader, | 510 GDataUploaderInterface* uploader, |
511 DriveWebAppsRegistryInterface* webapps_registry, | 511 DriveWebAppsRegistryInterface* webapps_registry, |
512 base::SequencedTaskRunner* blocking_task_runner) | 512 base::SequencedTaskRunner* blocking_task_runner) |
513 : profile_(profile), | 513 : profile_(profile), |
514 cache_(cache), | 514 cache_(cache), |
515 uploader_(uploader), | 515 uploader_(uploader), |
516 documents_service_(documents_service), | 516 documents_service_(documents_service), |
517 webapps_registry_(webapps_registry), | 517 webapps_registry_(webapps_registry), |
518 update_timer_(true /* retain_user_task */, true /* is_repeating */), | 518 update_timer_(true /* retain_user_task */, true /* is_repeating */), |
519 hide_hosted_docs_(false), | |
520 blocking_task_runner_(blocking_task_runner), | 519 blocking_task_runner_(blocking_task_runner), |
521 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 520 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
522 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()) { | 521 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()) { |
523 // Should be created from the file browser extension API on UI thread. | 522 // Should be created from the file browser extension API on UI thread. |
524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
525 } | 524 } |
526 | 525 |
527 void GDataFileSystem::Initialize() { | 526 void GDataFileSystem::Initialize() { |
528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
529 | 528 |
530 documents_service_->Initialize(profile_); | 529 documents_service_->Initialize(profile_); |
531 | 530 |
532 directory_service_.reset(new GDataDirectoryService); | 531 directory_service_.reset(new GDataDirectoryService); |
533 feed_loader_.reset(new GDataWapiFeedLoader(directory_service_.get(), | 532 feed_loader_.reset(new GDataWapiFeedLoader(directory_service_.get(), |
534 documents_service_, | 533 documents_service_, |
535 webapps_registry_, | 534 webapps_registry_, |
536 cache_, | 535 cache_, |
537 blocking_task_runner_)); | 536 blocking_task_runner_)); |
538 feed_loader_->AddObserver(this); | 537 feed_loader_->AddObserver(this); |
539 | 538 |
540 PrefService* pref_service = profile_->GetPrefs(); | |
541 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); | |
542 | |
543 InitializePreferenceObserver(); | 539 InitializePreferenceObserver(); |
544 } | 540 } |
545 | 541 |
546 void GDataFileSystem::CheckForUpdates() { | 542 void GDataFileSystem::CheckForUpdates() { |
547 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
548 ContentOrigin initial_origin = directory_service_->origin(); | 544 ContentOrigin initial_origin = directory_service_->origin(); |
549 if (initial_origin == FROM_SERVER) { | 545 if (initial_origin == FROM_SERVER) { |
550 directory_service_->set_origin(REFRESHING); | 546 directory_service_->set_origin(REFRESHING); |
551 feed_loader_->ReloadFromServerIfNeeded( | 547 feed_loader_->ReloadFromServerIfNeeded( |
552 initial_origin, | 548 initial_origin, |
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 } | 1855 } |
1860 | 1856 |
1861 void GDataFileSystem::OnReadDirectory(const ReadDirectoryCallback& callback, | 1857 void GDataFileSystem::OnReadDirectory(const ReadDirectoryCallback& callback, |
1862 GDataFileError error, | 1858 GDataFileError error, |
1863 GDataEntry* entry) { | 1859 GDataEntry* entry) { |
1864 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1860 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1865 | 1861 |
1866 if (error != GDATA_FILE_OK) { | 1862 if (error != GDATA_FILE_OK) { |
1867 if (!callback.is_null()) | 1863 if (!callback.is_null()) |
1868 callback.Run(error, | 1864 callback.Run(error, |
1869 hide_hosted_docs_, | |
1870 scoped_ptr<GDataEntryProtoVector>()); | 1865 scoped_ptr<GDataEntryProtoVector>()); |
1871 return; | 1866 return; |
1872 } | 1867 } |
1873 DCHECK(entry); | 1868 DCHECK(entry); |
1874 | 1869 |
1875 GDataDirectory* directory = entry->AsGDataDirectory(); | 1870 GDataDirectory* directory = entry->AsGDataDirectory(); |
1876 if (!directory) { | 1871 if (!directory) { |
1877 if (!callback.is_null()) | 1872 if (!callback.is_null()) |
1878 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, | 1873 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, |
1879 hide_hosted_docs_, | |
1880 scoped_ptr<GDataEntryProtoVector>()); | 1874 scoped_ptr<GDataEntryProtoVector>()); |
1881 return; | 1875 return; |
1882 } | 1876 } |
1883 | 1877 |
1884 scoped_ptr<GDataEntryProtoVector> entries(new GDataEntryProtoVector); | 1878 scoped_ptr<GDataEntryProtoVector> entries(new GDataEntryProtoVector); |
1885 for (GDataFileCollection::const_iterator iter = | 1879 for (GDataFileCollection::const_iterator iter = |
1886 directory->child_files().begin(); | 1880 directory->child_files().begin(); |
1887 iter != directory->child_files().end(); ++iter) { | 1881 iter != directory->child_files().end(); ++iter) { |
1888 GDataEntryProto proto; | 1882 GDataEntryProto proto; |
1889 static_cast<const GDataEntry*>(iter->second)->ToProtoFull(&proto); | 1883 static_cast<const GDataEntry*>(iter->second)->ToProtoFull(&proto); |
1890 entries->push_back(proto); | 1884 entries->push_back(proto); |
1891 } | 1885 } |
1892 for (GDataDirectoryCollection::const_iterator iter = | 1886 for (GDataDirectoryCollection::const_iterator iter = |
1893 directory->child_directories().begin(); | 1887 directory->child_directories().begin(); |
1894 iter != directory->child_directories().end(); ++iter) { | 1888 iter != directory->child_directories().end(); ++iter) { |
1895 GDataEntryProto proto; | 1889 GDataEntryProto proto; |
1896 static_cast<const GDataEntry*>(iter->second)->ToProtoFull(&proto); | 1890 static_cast<const GDataEntry*>(iter->second)->ToProtoFull(&proto); |
1897 entries->push_back(proto); | 1891 entries->push_back(proto); |
1898 } | 1892 } |
1899 | 1893 |
1900 if (!callback.is_null()) | 1894 if (!callback.is_null()) |
1901 callback.Run(GDATA_FILE_OK, hide_hosted_docs_, entries.Pass()); | 1895 callback.Run(GDATA_FILE_OK, entries.Pass()); |
1902 } | 1896 } |
1903 | 1897 |
1904 void GDataFileSystem::RequestDirectoryRefresh(const FilePath& file_path) { | 1898 void GDataFileSystem::RequestDirectoryRefresh(const FilePath& file_path) { |
1905 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1899 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1906 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1900 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1907 RunTaskOnUIThread( | 1901 RunTaskOnUIThread( |
1908 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread, | 1902 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread, |
1909 ui_weak_ptr_, | 1903 ui_weak_ptr_, |
1910 file_path)); | 1904 file_path)); |
1911 } | 1905 } |
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2964 NOTREACHED() << "Unexpected upload mode: " << upload_mode; | 2958 NOTREACHED() << "Unexpected upload mode: " << upload_mode; |
2965 } | 2959 } |
2966 } | 2960 } |
2967 | 2961 |
2968 void GDataFileSystem::Observe(int type, | 2962 void GDataFileSystem::Observe(int type, |
2969 const content::NotificationSource& source, | 2963 const content::NotificationSource& source, |
2970 const content::NotificationDetails& details) { | 2964 const content::NotificationDetails& details) { |
2971 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2972 | 2966 |
2973 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 2967 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
2974 PrefService* pref_service = profile_->GetPrefs(); | |
2975 std::string* pref_name = content::Details<std::string>(details).ptr(); | 2968 std::string* pref_name = content::Details<std::string>(details).ptr(); |
2976 if (*pref_name == prefs::kDisableGDataHostedFiles) { | 2969 if (*pref_name == prefs::kDisableGDataHostedFiles) { |
2977 SetHideHostedDocuments( | 2970 const FilePath root_path = directory_service_->root()->GetFilePath(); |
2978 pref_service->GetBoolean(prefs::kDisableGDataHostedFiles)); | 2971 // Kick off directory refresh when this setting changes. |
| 2972 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
| 2973 OnDirectoryChanged(root_path)); |
2979 } | 2974 } |
2980 } else { | 2975 } else { |
2981 NOTREACHED(); | 2976 NOTREACHED(); |
2982 } | 2977 } |
2983 } | 2978 } |
2984 | 2979 |
2985 void GDataFileSystem::SetHideHostedDocuments(bool hide) { | |
2986 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2987 | |
2988 if (hide == hide_hosted_docs_) | |
2989 return; | |
2990 | |
2991 hide_hosted_docs_ = hide; | |
2992 const FilePath root_path = directory_service_->root()->GetFilePath(); | |
2993 | |
2994 // Kick off directory refresh when this setting changes. | |
2995 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | |
2996 OnDirectoryChanged(root_path)); | |
2997 } | |
2998 | |
2999 //============= GDataFileSystem: internal helper functions ===================== | 2980 //============= GDataFileSystem: internal helper functions ===================== |
3000 | 2981 |
3001 void GDataFileSystem::InitializePreferenceObserver() { | 2982 void GDataFileSystem::InitializePreferenceObserver() { |
3002 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2983 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3003 | 2984 |
3004 pref_registrar_.reset(new PrefChangeRegistrar()); | 2985 pref_registrar_.reset(new PrefChangeRegistrar()); |
3005 pref_registrar_->Init(profile_->GetPrefs()); | 2986 pref_registrar_->Init(profile_->GetPrefs()); |
3006 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 2987 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
3007 } | 2988 } |
3008 | 2989 |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3425 } | 3406 } |
3426 | 3407 |
3427 PlatformFileInfoProto entry_file_info; | 3408 PlatformFileInfoProto entry_file_info; |
3428 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3409 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3429 *entry_proto->mutable_file_info() = entry_file_info; | 3410 *entry_proto->mutable_file_info() = entry_file_info; |
3430 if (!callback.is_null()) | 3411 if (!callback.is_null()) |
3431 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3412 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
3432 } | 3413 } |
3433 | 3414 |
3434 } // namespace gdata | 3415 } // namespace gdata |
OLD | NEW |