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 "chrome/browser/chromeos/gdata/gdata_file_system_proxy.h" | |
11 #include "content/public/browser/browser_context.h" | |
12 | |
10 #include "base/bind.h" | 13 #include "base/bind.h" |
11 #include "base/file_util.h" | 14 #include "base/file_util.h" |
12 #include "base/json/json_file_value_serializer.h" | 15 #include "base/json/json_file_value_serializer.h" |
13 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
14 #include "base/json/json_writer.h" | 17 #include "base/json/json_writer.h" |
15 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
16 #include "base/message_loop_proxy.h" | 19 #include "base/message_loop_proxy.h" |
17 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
18 #include "base/platform_file.h" | 21 #include "base/platform_file.h" |
19 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
20 #include "base/values.h" | 23 #include "base/values.h" |
21 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" | 24 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" |
22 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 25 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
23 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" | 26 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" |
24 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" | 27 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" |
25 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h" | 28 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h" |
26 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 29 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
27 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 30 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
28 #include "chrome/browser/prefs/pref_service.h" | 31 #include "chrome/browser/prefs/pref_service.h" |
29 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
31 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
32 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/notification_details.h" | 36 #include "content/public/browser/notification_details.h" |
34 #include "net/base/mime_util.h" | 37 #include "net/base/mime_util.h" |
38 #include "webkit/fileapi/file_system_context.h" | |
39 #include "webkit/fileapi/file_system_mount_point_provider.h" | |
35 | 40 |
36 using content::BrowserThread; | 41 using content::BrowserThread; |
37 | 42 |
38 namespace gdata { | 43 namespace gdata { |
39 namespace { | 44 namespace { |
40 | 45 |
41 const char kMimeTypeJson[] = "application/json"; | 46 const char kMimeTypeJson[] = "application/json"; |
42 const char kMimeTypeOctetStream[] = "application/octet-stream"; | 47 const char kMimeTypeOctetStream[] = "application/octet-stream"; |
43 | 48 |
44 const FilePath::CharType kAccountMetadataFile[] = | 49 const FilePath::CharType kAccountMetadataFile[] = |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 | 845 |
841 DCHECK(!update_timer_.IsRunning()); | 846 DCHECK(!update_timer_.IsRunning()); |
842 update_timer_.Start(FROM_HERE, | 847 update_timer_.Start(FROM_HERE, |
843 base::TimeDelta::FromSeconds( | 848 base::TimeDelta::FromSeconds( |
844 kGDataUpdateCheckIntervalInSec), | 849 kGDataUpdateCheckIntervalInSec), |
845 base::Bind(&GDataFileSystem::CheckForUpdates, | 850 base::Bind(&GDataFileSystem::CheckForUpdates, |
846 ui_weak_ptr_)); | 851 ui_weak_ptr_)); |
847 } | 852 } |
848 | 853 |
849 void GDataFileSystem::StopUpdates() { | 854 void GDataFileSystem::StopUpdates() { |
855 // If unmount request comes from filesystem side, this method may be called | |
856 // twice. First is just after unmounting on filesystem, second is after | |
857 // unmounting on filemanager on JS. In other words, if this is called from | |
858 // GDataFileSystem::RemoveDriveMountPoint(), this will be called again from | |
859 // FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(). | |
860 // We choose to stopping updates asynchronous without waiting for filemanager, | |
861 // rather than waiting for completion of unmounting on filemanager. | |
850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 862 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
851 DCHECK(update_timer_.IsRunning()); | 863 if (update_timer_.IsRunning()) |
852 update_timer_.Stop(); | 864 update_timer_.Stop(); |
853 } | 865 } |
854 | 866 |
855 void GDataFileSystem::GetEntryInfoByResourceId( | 867 void GDataFileSystem::GetEntryInfoByResourceId( |
856 const std::string& resource_id, | 868 const std::string& resource_id, |
857 const GetEntryInfoWithFilePathCallback& callback) { | 869 const GetEntryInfoWithFilePathCallback& callback) { |
858 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 870 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
859 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 871 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
860 RunTaskOnUIThread( | 872 RunTaskOnUIThread( |
861 base::Bind(&GDataFileSystem::GetEntryInfoByResourceIdOnUIThread, | 873 base::Bind(&GDataFileSystem::GetEntryInfoByResourceIdOnUIThread, |
862 ui_weak_ptr_, | 874 ui_weak_ptr_, |
(...skipping 2016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2879 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { | 2891 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { |
2880 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2892 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2881 | 2893 |
2882 LoadRootFeedFromCache( | 2894 LoadRootFeedFromCache( |
2883 false, // should_load_from_server. | 2895 false, // should_load_from_server. |
2884 // search_path doesn't matter if FindEntryCallback parameter is null . | 2896 // search_path doesn't matter if FindEntryCallback parameter is null . |
2885 FilePath(), | 2897 FilePath(), |
2886 FindEntryCallback()); | 2898 FindEntryCallback()); |
2887 } | 2899 } |
2888 | 2900 |
2901 void GDataFileSystem::AddDriveMountPoint() { | |
2902 const FilePath mount_point = gdata::util::GetGDataMountPointPath(); | |
2903 fileapi::ExternalFileSystemMountPointProvider* provider = | |
2904 content::BrowserContext::GetFileSystemContext(profile_)-> | |
2905 external_provider(); | |
2906 if (provider && !provider->HasMountPoint(mount_point)) { | |
2907 provider->AddRemoteMountPoint( | |
2908 mount_point, | |
2909 new GDataFileSystemProxy(this)); | |
satorux1
2012/08/01 20:59:01
Hmm, why do we need to move the code to GDataFileS
yoshiki
2012/08/01 22:23:39
I moved this code in order to call NotifyFileSyste
satorux1
2012/08/02 01:17:12
What classes are interested in NotifyFileSystemMou
yoshiki
2012/08/02 05:53:42
Sorry for my confusing explanation.
This method (
satorux1
2012/08/02 06:19:44
My question was, why NotifyFileSystemMounted() has
satorux1
2012/08/02 06:38:32
I meant:
why OnFileSystemMounted() has to be part
| |
2910 directory_service_.reset(new GDataDirectoryService); | |
2911 NotifyFileSystemMounted(); | |
2912 } | |
2913 } | |
2914 | |
2915 void GDataFileSystem::RemoveDriveMountPoint() { | |
2916 const FilePath mount_point = gdata::util::GetGDataMountPointPath(); | |
2917 fileapi::ExternalFileSystemMountPointProvider* provider = | |
2918 content::BrowserContext::GetFileSystemContext(profile_)-> | |
2919 external_provider(); | |
2920 if (provider && provider->HasMountPoint(mount_point)) { | |
2921 NotifyFileSystemUnmounting(); | |
2922 // We have to stop update before removing mount point. | |
2923 StopUpdates(); | |
2924 provider->RemoveMountPoint(mount_point); | |
2925 } | |
2926 } | |
2927 | |
2889 void GDataFileSystem::OnProtoLoaded(LoadRootFeedParams* params) { | 2928 void GDataFileSystem::OnProtoLoaded(LoadRootFeedParams* params) { |
2890 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2929 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2891 | 2930 |
2892 // If we have already received updates from the server, bail out. | 2931 // If we have already received updates from the server, bail out. |
2893 if (directory_service_->origin() == FROM_SERVER) | 2932 if (directory_service_->origin() == FROM_SERVER) |
2894 return; | 2933 return; |
2895 | 2934 |
2896 int local_changestamp = 0; | 2935 int local_changestamp = 0; |
2897 // Update directory structure only if everything is OK and we haven't yet | 2936 // Update directory structure only if everything is OK and we haven't yet |
2898 // received the feed from the server yet. | 2937 // received the feed from the server yet. |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3598 | 3637 |
3599 void GDataFileSystem::NotifyDocumentFeedFetched(int num_accumulated_entries) { | 3638 void GDataFileSystem::NotifyDocumentFeedFetched(int num_accumulated_entries) { |
3600 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3601 | 3640 |
3602 DVLOG(1) << "Document feed fetched: " << num_accumulated_entries; | 3641 DVLOG(1) << "Document feed fetched: " << num_accumulated_entries; |
3603 // Notify the observers that a document feed is fetched. | 3642 // Notify the observers that a document feed is fetched. |
3604 FOR_EACH_OBSERVER(Observer, observers_, | 3643 FOR_EACH_OBSERVER(Observer, observers_, |
3605 OnDocumentFeedFetched(num_accumulated_entries)); | 3644 OnDocumentFeedFetched(num_accumulated_entries)); |
3606 } | 3645 } |
3607 | 3646 |
3647 void GDataFileSystem::NotifyFileSystemMounted() { | |
3648 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
3649 | |
3650 DVLOG(1) << "File System is mounted"; | |
3651 // Notify the observers that the file system is mounted. | |
3652 FOR_EACH_OBSERVER(Observer, observers_, OnFileSystemMounted()); | |
3653 } | |
3654 | |
3655 void GDataFileSystem::NotifyFileSystemUnmounting() { | |
3656 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
3657 | |
3658 DVLOG(1) << "File System is getting unmounted"; | |
3659 // Notify the observers that the file system is getting unmounted. | |
3660 FOR_EACH_OBSERVER(Observer, observers_, OnFileSystemUnmounting()); | |
3661 } | |
3662 | |
3608 void GDataFileSystem::RunAndNotifyInitialLoadFinished( | 3663 void GDataFileSystem::RunAndNotifyInitialLoadFinished( |
3609 const FindEntryCallback& callback, | 3664 const FindEntryCallback& callback, |
3610 GDataFileError error, | 3665 GDataFileError error, |
3611 GDataEntry* entry) { | 3666 GDataEntry* entry) { |
3612 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3613 | 3668 |
3614 DVLOG(1) << "Initial load finished"; | 3669 DVLOG(1) << "Initial load finished"; |
3615 if (!callback.is_null()) | 3670 if (!callback.is_null()) |
3616 callback.Run(error, entry); | 3671 callback.Run(error, entry); |
3617 | 3672 |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4269 } | 4324 } |
4270 | 4325 |
4271 PlatformFileInfoProto entry_file_info; | 4326 PlatformFileInfoProto entry_file_info; |
4272 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 4327 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
4273 *entry_proto->mutable_file_info() = entry_file_info; | 4328 *entry_proto->mutable_file_info() = entry_file_info; |
4274 if (!callback.is_null()) | 4329 if (!callback.is_null()) |
4275 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 4330 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
4276 } | 4331 } |
4277 | 4332 |
4278 } // namespace gdata | 4333 } // namespace gdata |
OLD | NEW |