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" |
11 #include "base/command_line.h" | |
11 #include "base/file_util.h" | 12 #include "base/file_util.h" |
12 #include "base/json/json_file_value_serializer.h" | 13 #include "base/json/json_file_value_serializer.h" |
13 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
14 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
15 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
16 #include "base/message_loop_proxy.h" | 17 #include "base/message_loop_proxy.h" |
17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
18 #include "base/platform_file.h" | 19 #include "base/platform_file.h" |
19 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
20 #include "base/values.h" | 21 #include "base/values.h" |
21 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" | 22 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" |
22 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 23 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
23 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" | 24 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" |
24 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" | 25 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" |
25 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h" | 26 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h" |
26 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 27 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
27 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 28 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
28 #include "chrome/browser/prefs/pref_service.h" | 29 #include "chrome/browser/prefs/pref_service.h" |
29 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/common/chrome_switches.h" | |
30 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
31 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
32 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/notification_details.h" | 35 #include "content/public/browser/notification_details.h" |
34 #include "net/base/mime_util.h" | 36 #include "net/base/mime_util.h" |
35 | 37 |
36 using content::BrowserThread; | 38 using content::BrowserThread; |
37 | 39 |
38 namespace gdata { | 40 namespace gdata { |
39 namespace { | 41 namespace { |
40 | 42 |
41 const char kMimeTypeJson[] = "application/json"; | 43 const char kMimeTypeJson[] = "application/json"; |
42 const char kMimeTypeOctetStream[] = "application/octet-stream"; | 44 const char kMimeTypeOctetStream[] = "application/octet-stream"; |
43 | 45 |
44 const FilePath::CharType kAccountMetadataFile[] = | 46 const FilePath::CharType kAccountMetadataFile[] = |
45 FILE_PATH_LITERAL("account_metadata.json"); | 47 FILE_PATH_LITERAL("account_metadata.json"); |
46 const FilePath::CharType kFilesystemProtoFile[] = | 48 const FilePath::CharType kFilesystemProtoFile[] = |
47 FILE_PATH_LITERAL("file_system.pb"); | 49 FILE_PATH_LITERAL("file_system.pb"); |
50 const FilePath::CharType kResourceMetadataDBFile[] = | |
51 FILE_PATH_LITERAL("resource_metadata.db"); | |
48 | 52 |
49 const char kEmptyFilePath[] = "/dev/null"; | 53 const char kEmptyFilePath[] = "/dev/null"; |
50 | 54 |
55 #ifndef NDEBUG | |
56 static base::Time kTimerStart; | |
satorux1
2012/08/02 17:24:03
this is not allowed
http://google-styleguide.goog
achuithb
2012/08/02 20:26:25
Done.
| |
57 #endif | |
58 | |
51 // GData update check interval (in seconds). | 59 // GData update check interval (in seconds). |
52 #ifndef NDEBUG | 60 #ifndef NDEBUG |
53 const int kGDataUpdateCheckIntervalInSec = 5; | 61 const int kGDataUpdateCheckIntervalInSec = 5; |
54 #else | 62 #else |
55 const int kGDataUpdateCheckIntervalInSec = 60; | 63 const int kGDataUpdateCheckIntervalInSec = 60; |
56 #endif | 64 #endif |
57 | 65 |
58 // Schedule for dumping root file system proto buffers to disk depending its | 66 // Schedule for dumping root file system proto buffers to disk depending its |
59 // total protobuffer size in MB. | 67 // total protobuffer size in MB. |
60 typedef struct { | 68 typedef struct { |
61 double size; | 69 double size; |
62 int timeout; | 70 int timeout; |
63 } SerializationTimetable; | 71 } SerializationTimetable; |
64 | 72 |
65 SerializationTimetable kSerializeTimetable[] = { | 73 SerializationTimetable kSerializeTimetable[] = { |
66 #ifndef NDEBUG | 74 #ifndef NDEBUG |
67 {0.5, 0}, // Less than 0.5MB, dump immediately. | 75 {0.5, 0}, // Less than 0.5MB, dump immediately. |
68 {-1, 1}, // Any size, dump if older than 1 minute. | 76 {-1, 1}, // Any size, dump if older than 1 minute. |
69 #else | 77 #else |
70 {0.5, 0}, // Less than 0.5MB, dump immediately. | 78 {0.5, 0}, // Less than 0.5MB, dump immediately. |
71 {1.0, 15}, // Less than 1.0MB, dump after 15 minutes. | 79 {1.0, 15}, // Less than 1.0MB, dump after 15 minutes. |
72 {2.0, 30}, | 80 {2.0, 30}, |
73 {4.0, 60}, | 81 {4.0, 60}, |
74 {-1, 120}, // Any size, dump if older than 120 minutes. | 82 {-1, 120}, // Any size, dump if older than 120 minutes. |
75 #endif | 83 #endif |
76 }; | 84 }; |
77 | 85 |
78 // Defines set of parameters sent to callback OnProtoLoaded(). | |
79 struct LoadRootFeedParams { | |
80 LoadRootFeedParams( | |
81 FilePath search_file_path, | |
82 bool should_load_from_server, | |
83 const FindEntryCallback& callback) | |
84 : search_file_path(search_file_path), | |
85 should_load_from_server(should_load_from_server), | |
86 load_error(GDATA_FILE_OK), | |
87 callback(callback) { | |
88 } | |
89 ~LoadRootFeedParams() { | |
90 } | |
91 | |
92 FilePath search_file_path; | |
93 bool should_load_from_server; | |
94 std::string proto; | |
95 GDataFileError load_error; | |
96 base::Time last_modified; | |
97 const FindEntryCallback callback; | |
98 }; | |
99 | |
100 // Returns true if file system is due to be serialized on disk based on it | 86 // Returns true if file system is due to be serialized on disk based on it |
101 // |serialized_size| and |last_serialized| timestamp. | 87 // |serialized_size| and |last_serialized| timestamp. |
102 bool ShouldSerializeFileSystemNow(size_t serialized_size, | 88 bool ShouldSerializeFileSystemNow(size_t serialized_size, |
103 const base::Time& last_serialized) { | 89 const base::Time& last_serialized) { |
104 const double size_in_mb = serialized_size / 1048576.0; | 90 const double size_in_mb = serialized_size / 1048576.0; |
105 const int last_proto_dump_in_min = | 91 const int last_proto_dump_in_min = |
106 (base::Time::Now() - last_serialized).InMinutes(); | 92 (base::Time::Now() - last_serialized).InMinutes(); |
107 for (size_t i = 0; i < arraysize(kSerializeTimetable); i++) { | 93 for (size_t i = 0; i < arraysize(kSerializeTimetable); i++) { |
108 if ((size_in_mb < kSerializeTimetable[i].size || | 94 if ((size_in_mb < kSerializeTimetable[i].size || |
109 kSerializeTimetable[i].size == -1) && | 95 kSerializeTimetable[i].size == -1) && |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 LOG(WARNING) << "GData metadata file can't be stored at " | 249 LOG(WARNING) << "GData metadata file can't be stored at " |
264 << file_path.value(); | 250 << file_path.value(); |
265 if (!file_util::Delete(file_path, true)) { | 251 if (!file_util::Delete(file_path, true)) { |
266 LOG(WARNING) << "GData metadata file can't be deleted at " | 252 LOG(WARNING) << "GData metadata file can't be deleted at " |
267 << file_path.value(); | 253 << file_path.value(); |
268 return; | 254 return; |
269 } | 255 } |
270 } | 256 } |
271 } | 257 } |
272 | 258 |
259 bool UseLevelDB() { | |
260 return CommandLine::ForCurrentProcess()->HasSwitch( | |
261 switches::kUseLevelDBForGData); | |
262 } | |
263 | |
273 // Gets the file size of |local_file|. | 264 // Gets the file size of |local_file|. |
274 void GetLocalFileSizeOnBlockingPool(const FilePath& local_file, | 265 void GetLocalFileSizeOnBlockingPool(const FilePath& local_file, |
275 GDataFileError* error, | 266 GDataFileError* error, |
276 int64* file_size) { | 267 int64* file_size) { |
277 DCHECK(error); | 268 DCHECK(error); |
278 DCHECK(file_size); | 269 DCHECK(file_size); |
279 | 270 |
280 *file_size = 0; | 271 *file_size = 0; |
281 *error = file_util::GetFileSize(local_file, file_size) ? | 272 *error = file_util::GetFileSize(local_file, file_size) ? |
282 GDATA_FILE_OK : | 273 GDATA_FILE_OK : |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
907 callback.Run(entry ? GDATA_FILE_OK : GDATA_FILE_ERROR_NOT_FOUND, entry); | 898 callback.Run(entry ? GDATA_FILE_OK : GDATA_FILE_ERROR_NOT_FOUND, entry); |
908 } | 899 } |
909 | 900 |
910 void GDataFileSystem::ReloadFeedFromServerIfNeeded( | 901 void GDataFileSystem::ReloadFeedFromServerIfNeeded( |
911 ContentOrigin initial_origin, | 902 ContentOrigin initial_origin, |
912 int local_changestamp, | 903 int local_changestamp, |
913 const FilePath& search_file_path, | 904 const FilePath& search_file_path, |
914 const FindEntryCallback& callback) { | 905 const FindEntryCallback& callback) { |
915 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
916 | 907 |
908 DVLOG(1) << "ReloadFeedFromServerIfNeeded local_changestamp=" | |
909 << local_changestamp << ", initial_origin=" << initial_origin; | |
910 | |
917 // First fetch the latest changestamp to see if there were any new changes | 911 // First fetch the latest changestamp to see if there were any new changes |
918 // there at all. | 912 // there at all. |
919 documents_service_->GetAccountMetadata( | 913 documents_service_->GetAccountMetadata( |
920 base::Bind(&GDataFileSystem::OnGetAccountMetadata, | 914 base::Bind(&GDataFileSystem::OnGetAccountMetadata, |
921 ui_weak_ptr_, | 915 ui_weak_ptr_, |
922 initial_origin, | 916 initial_origin, |
923 local_changestamp, | 917 local_changestamp, |
924 search_file_path, | 918 search_file_path, |
925 callback)); | 919 callback)); |
926 } | 920 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1067 params->root_feed_changestamp); | 1061 params->root_feed_changestamp); |
1068 | 1062 |
1069 if (error != GDATA_FILE_OK) { | 1063 if (error != GDATA_FILE_OK) { |
1070 if (!params->callback.is_null()) | 1064 if (!params->callback.is_null()) |
1071 params->callback.Run(error, NULL); | 1065 params->callback.Run(error, NULL); |
1072 | 1066 |
1073 return; | 1067 return; |
1074 } | 1068 } |
1075 | 1069 |
1076 // Save file system metadata to disk. | 1070 // Save file system metadata to disk. |
1077 SaveFileSystemAsProto(); | 1071 SaveFileSystem(); |
1078 | 1072 |
1079 // If we had someone to report this too, then this retrieval was done in a | 1073 // If we had someone to report this too, then this retrieval was done in a |
1080 // context of search... so continue search. | 1074 // context of search... so continue search. |
1081 if (!params->callback.is_null()) | 1075 if (!params->callback.is_null()) |
1082 FindEntryByPathSyncOnUIThread(params->search_file_path, params->callback); | 1076 FindEntryByPathSyncOnUIThread(params->search_file_path, params->callback); |
1083 | 1077 |
1084 FOR_EACH_OBSERVER(Observer, observers_, OnFeedFromServerLoaded()); | 1078 FOR_EACH_OBSERVER(Observer, observers_, OnFeedFromServerLoaded()); |
1085 } | 1079 } |
1086 | 1080 |
1087 void GDataFileSystem::TransferFileFromRemoteToLocal( | 1081 void GDataFileSystem::TransferFileFromRemoteToLocal( |
(...skipping 1737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2825 if (!callback.is_null()) | 2819 if (!callback.is_null()) |
2826 callback.Run(params, error); | 2820 callback.Run(params, error); |
2827 } | 2821 } |
2828 | 2822 |
2829 void GDataFileSystem::LoadRootFeedFromCache( | 2823 void GDataFileSystem::LoadRootFeedFromCache( |
2830 bool should_load_from_server, | 2824 bool should_load_from_server, |
2831 const FilePath& search_file_path, | 2825 const FilePath& search_file_path, |
2832 const FindEntryCallback& callback) { | 2826 const FindEntryCallback& callback) { |
2833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2827 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2834 | 2828 |
2835 const FilePath path = | |
2836 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( | |
2837 kFilesystemProtoFile); | |
2838 LoadRootFeedParams* params = new LoadRootFeedParams(search_file_path, | 2829 LoadRootFeedParams* params = new LoadRootFeedParams(search_file_path, |
2839 should_load_from_server, | 2830 should_load_from_server, |
2840 callback); | 2831 callback); |
2841 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, | 2832 |
2842 base::Bind(&LoadProtoOnBlockingPool, path, params), | 2833 #ifndef NDEBUG |
2843 base::Bind(&GDataFileSystem::OnProtoLoaded, | 2834 kTimerStart = base::Time::Now(); |
2844 ui_weak_ptr_, | 2835 #endif |
satorux1
2012/08/02 17:24:03
Let's get rid of the #ifdef. Time object is cheap.
achuithb
2012/08/02 20:26:25
Done.
| |
2845 base::Owned(params))); | 2836 |
2837 FilePath path = cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META); | |
2838 if (UseLevelDB()) { | |
2839 path = path.Append(kResourceMetadataDBFile); | |
2840 directory_service_->InitFromDB(path, blocking_task_runner_, params, | |
2841 base::Bind(&GDataFileSystem::ContinueWithInitializedDirectoryService, | |
2842 ui_weak_ptr_, | |
2843 base::Owned(params))); | |
2844 } else { | |
2845 path = path.Append(kFilesystemProtoFile); | |
2846 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, | |
2847 base::Bind(&LoadProtoOnBlockingPool, path, params), | |
2848 base::Bind(&GDataFileSystem::OnProtoLoaded, | |
2849 ui_weak_ptr_, | |
2850 base::Owned(params))); | |
2851 } | |
2846 } | 2852 } |
2847 | 2853 |
2848 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { | 2854 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { |
2849 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2855 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2850 | 2856 |
2851 LoadRootFeedFromCache( | 2857 LoadRootFeedFromCache( |
2852 false, // should_load_from_server. | 2858 false, // should_load_from_server. |
2853 // search_path doesn't matter if FindEntryCallback parameter is null . | 2859 // search_path doesn't matter if FindEntryCallback parameter is null . |
2854 FilePath(), | 2860 FilePath(), |
2855 FindEntryCallback()); | 2861 FindEntryCallback()); |
2856 } | 2862 } |
2857 | 2863 |
2858 void GDataFileSystem::OnProtoLoaded(LoadRootFeedParams* params) { | 2864 void GDataFileSystem::OnProtoLoaded(LoadRootFeedParams* params) { |
2859 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2865 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2860 | 2866 |
2861 // If we have already received updates from the server, bail out. | 2867 // If we have already received updates from the server, bail out. |
2862 if (directory_service_->origin() == FROM_SERVER) | 2868 if (directory_service_->origin() == FROM_SERVER) |
2863 return; | 2869 return; |
2864 | 2870 |
2865 int local_changestamp = 0; | |
2866 // Update directory structure only if everything is OK and we haven't yet | 2871 // Update directory structure only if everything is OK and we haven't yet |
2867 // received the feed from the server yet. | 2872 // received the feed from the server yet. |
2868 if (params->load_error == GDATA_FILE_OK) { | 2873 if (params->load_error == GDATA_FILE_OK) { |
2869 DVLOG(1) << "ParseFromString"; | 2874 DVLOG(1) << "ParseFromString"; |
2870 if (directory_service_->ParseFromString(params->proto)) { | 2875 if (directory_service_->ParseFromString(params->proto)) { |
2871 directory_service_->set_last_serialized(params->last_modified); | 2876 directory_service_->set_last_serialized(params->last_modified); |
2872 directory_service_->set_serialized_size(params->proto.size()); | 2877 directory_service_->set_serialized_size(params->proto.size()); |
2873 local_changestamp = directory_service_->largest_changestamp(); | |
2874 } else { | 2878 } else { |
2875 params->load_error = GDATA_FILE_ERROR_FAILED; | 2879 params->load_error = GDATA_FILE_ERROR_FAILED; |
2876 LOG(WARNING) << "Parse of cached proto file failed"; | 2880 LOG(WARNING) << "Parse of cached proto file failed"; |
2877 } | 2881 } |
2878 } | 2882 } |
2879 | 2883 |
2884 ContinueWithInitializedDirectoryService(params); | |
2885 } | |
2886 | |
2887 void GDataFileSystem::ContinueWithInitializedDirectoryService( | |
2888 LoadRootFeedParams* params) { | |
2889 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2890 | |
2891 #ifndef NDEBUG | |
2892 DVLOG(1) << "Time elapsed to load directory service from disk=" | |
2893 << (base::Time::Now() - kTimerStart).InMilliseconds() | |
2894 << " milliseconds"; | |
2895 #endif | |
satorux1
2012/08/02 17:24:03
let's remove #ifdef, and pass the start time nicel
achuithb
2012/08/02 20:26:25
Done.
| |
2896 | |
2880 FindEntryCallback callback = params->callback; | 2897 FindEntryCallback callback = params->callback; |
2881 // If we got feed content from cache, try search over it. | 2898 // If we got feed content from cache, try search over it. |
2882 if (params->load_error == GDATA_FILE_OK && !callback.is_null()) { | 2899 if (params->load_error == GDATA_FILE_OK && !callback.is_null()) { |
2883 // Continue file content search operation if the delegate hasn't terminated | 2900 // Continue file content search operation if the delegate hasn't terminated |
2884 // this search branch already. | 2901 // this search branch already. |
2885 FindEntryByPathSyncOnUIThread(params->search_file_path, callback); | 2902 FindEntryByPathSyncOnUIThread(params->search_file_path, callback); |
2886 callback.Reset(); | 2903 callback.Reset(); |
2887 } | 2904 } |
2888 | 2905 |
2889 if (!params->should_load_from_server) | 2906 if (!params->should_load_from_server) |
2890 return; | 2907 return; |
2891 | 2908 |
2892 // Decide the |initial_origin| to pass to ReloadFeedFromServerIfNeeded(). | 2909 // Decide the |initial_origin| to pass to ReloadFeedFromServerIfNeeded(). |
2893 // This is used to restore directory content origin to its initial value when | 2910 // This is used to restore directory content origin to its initial value when |
2894 // we fail to retrieve the feed from server. | 2911 // we fail to retrieve the feed from server. |
2895 // By default, if directory content is not yet initialized, restore content | 2912 // By default, if directory content is not yet initialized, restore content |
2896 // origin to UNINITIALIZED in case of failure. | 2913 // origin to UNINITIALIZED in case of failure. |
2897 ContentOrigin initial_origin = UNINITIALIZED; | 2914 ContentOrigin initial_origin = UNINITIALIZED; |
2898 if (directory_service_->origin() != INITIALIZING) { | 2915 if (directory_service_->origin() != INITIALIZING) { |
2899 // If directory content is already initialized, restore content origin | 2916 // If directory content is already initialized, restore content origin |
2900 // to FROM_CACHE in case of failure. | 2917 // to FROM_CACHE in case of failure. |
2901 initial_origin = FROM_CACHE; | 2918 initial_origin = FROM_CACHE; |
2902 directory_service_->set_origin(REFRESHING); | 2919 directory_service_->set_origin(REFRESHING); |
2903 } | 2920 } |
2904 | 2921 |
2905 // Kick of the retrieval of the feed from server. If we have previously | 2922 // Kick of the retrieval of the feed from server. If we have previously |
2906 // |reported| to the original callback, then we just need to refresh the | 2923 // |reported| to the original callback, then we just need to refresh the |
2907 // content without continuing search upon operation completion. | 2924 // content without continuing search upon operation completion. |
2908 ReloadFeedFromServerIfNeeded(initial_origin, | 2925 ReloadFeedFromServerIfNeeded(initial_origin, |
2909 local_changestamp, | 2926 directory_service_->largest_changestamp(), |
2910 params->search_file_path, | 2927 params->search_file_path, |
2911 callback); | 2928 callback); |
2912 } | 2929 } |
2913 | 2930 |
2914 void GDataFileSystem::SaveFileSystemAsProto() { | 2931 void GDataFileSystem::SaveFileSystem() { |
2915 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2932 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2916 | 2933 |
2917 DVLOG(1) << "SaveFileSystemAsProto"; | |
2918 | |
2919 if (!ShouldSerializeFileSystemNow(directory_service_->serialized_size(), | 2934 if (!ShouldSerializeFileSystemNow(directory_service_->serialized_size(), |
2920 directory_service_->last_serialized())) { | 2935 directory_service_->last_serialized())) { |
2921 return; | 2936 return; |
2922 } | 2937 } |
2923 | 2938 |
2924 const FilePath path = | 2939 if (UseLevelDB()) { |
2925 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( | 2940 directory_service_->SaveToDB(); |
2926 kFilesystemProtoFile); | 2941 } else { |
2927 scoped_ptr<std::string> serialized_proto(new std::string()); | 2942 const FilePath path = |
2928 directory_service_->SerializeToString(serialized_proto.get()); | 2943 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( |
2929 directory_service_->set_last_serialized(base::Time::Now()); | 2944 kFilesystemProtoFile); |
2930 directory_service_->set_serialized_size(serialized_proto->size()); | 2945 scoped_ptr<std::string> serialized_proto(new std::string()); |
2931 PostBlockingPoolSequencedTask( | 2946 directory_service_->SerializeToString(serialized_proto.get()); |
2932 FROM_HERE, | 2947 directory_service_->set_last_serialized(base::Time::Now()); |
2933 blocking_task_runner_, | 2948 directory_service_->set_serialized_size(serialized_proto->size()); |
2934 base::Bind(&SaveProtoOnBlockingPool, path, | 2949 PostBlockingPoolSequencedTask( |
2935 base::Passed(serialized_proto.Pass()))); | 2950 FROM_HERE, |
2951 blocking_task_runner_, | |
2952 base::Bind(&SaveProtoOnBlockingPool, path, | |
2953 base::Passed(serialized_proto.Pass()))); | |
2954 } | |
2936 } | 2955 } |
2937 | 2956 |
2938 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, | 2957 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, |
2939 GDataFileError error, | 2958 GDataFileError error, |
2940 const FilePath& file_path) { | 2959 const FilePath& file_path) { |
2941 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2960 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2942 if (!callback.is_null()) | 2961 if (!callback.is_null()) |
2943 callback.Run(error); | 2962 callback.Run(error); |
2944 } | 2963 } |
2945 | 2964 |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3304 | 3323 |
3305 DVLOG(1) << "Content changed of " << directory_path.value(); | 3324 DVLOG(1) << "Content changed of " << directory_path.value(); |
3306 // Notify the observers that content of |directory_path| has been changed. | 3325 // Notify the observers that content of |directory_path| has been changed. |
3307 FOR_EACH_OBSERVER(Observer, observers_, OnDirectoryChanged(directory_path)); | 3326 FOR_EACH_OBSERVER(Observer, observers_, OnDirectoryChanged(directory_path)); |
3308 } | 3327 } |
3309 | 3328 |
3310 void GDataFileSystem::NotifyDocumentFeedFetched(int num_accumulated_entries) { | 3329 void GDataFileSystem::NotifyDocumentFeedFetched(int num_accumulated_entries) { |
3311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3312 | 3331 |
3313 DVLOG(1) << "Document feed fetched: " << num_accumulated_entries; | 3332 DVLOG(1) << "NotifyDocumentFeedFetched: " << num_accumulated_entries |
3333 << ", origin: " << directory_service_->origin(); | |
3314 // Notify the observers that a document feed is fetched. | 3334 // Notify the observers that a document feed is fetched. |
3315 FOR_EACH_OBSERVER(Observer, observers_, | 3335 FOR_EACH_OBSERVER(Observer, observers_, |
3316 OnDocumentFeedFetched(num_accumulated_entries)); | 3336 OnDocumentFeedFetched(num_accumulated_entries)); |
3317 } | 3337 } |
3318 | 3338 |
3319 void GDataFileSystem::RunAndNotifyInitialLoadFinished( | 3339 void GDataFileSystem::RunAndNotifyInitialLoadFinished( |
3320 const FindEntryCallback& callback, | 3340 const FindEntryCallback& callback, |
3321 GDataFileError error, | 3341 GDataFileError error, |
3322 GDataEntry* entry) { | 3342 GDataEntry* entry) { |
3323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3324 | 3344 |
3325 DVLOG(1) << "Initial load finished"; | |
3326 if (!callback.is_null()) | 3345 if (!callback.is_null()) |
3327 callback.Run(error, entry); | 3346 callback.Run(error, entry); |
3328 | 3347 |
3348 DVLOG(1) << "RunAndNotifyInitialLoadFinished"; | |
3349 | |
3329 // Notify the observers that root directory has been initialized. | 3350 // Notify the observers that root directory has been initialized. |
3330 FOR_EACH_OBSERVER(Observer, observers_, OnInitialLoadFinished()); | 3351 FOR_EACH_OBSERVER(Observer, observers_, OnInitialLoadFinished()); |
3331 } | 3352 } |
3332 | 3353 |
3333 GDataFileError GDataFileSystem::AddNewDirectory( | 3354 GDataFileError GDataFileSystem::AddNewDirectory( |
3334 const FilePath& directory_path, base::Value* entry_value) { | 3355 const FilePath& directory_path, base::Value* entry_value) { |
3335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3336 | 3357 |
3337 if (!entry_value) | 3358 if (!entry_value) |
3338 return GDATA_FILE_ERROR_FAILED; | 3359 return GDATA_FILE_ERROR_FAILED; |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3980 } | 4001 } |
3981 | 4002 |
3982 PlatformFileInfoProto entry_file_info; | 4003 PlatformFileInfoProto entry_file_info; |
3983 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 4004 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3984 *entry_proto->mutable_file_info() = entry_file_info; | 4005 *entry_proto->mutable_file_info() = entry_file_info; |
3985 if (!callback.is_null()) | 4006 if (!callback.is_null()) |
3986 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 4007 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
3987 } | 4008 } |
3988 | 4009 |
3989 } // namespace gdata | 4010 } // namespace gdata |
OLD | NEW |