Chromium Code Reviews| 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/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/json/json_file_value_serializer.h" | 12 #include "base/json/json_file_value_serializer.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/message_loop_proxy.h" | 14 #include "base/message_loop_proxy.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/platform_file.h" | 16 #include "base/platform_file.h" |
| 17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" | |
| 19 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" | 20 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" |
| 20 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 21 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
| 21 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" | 22 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" |
| 22 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" | 23 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" |
| 23 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h" | 24 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h" |
| 24 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 25 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
| 25 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 26 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 26 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
| (...skipping 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1955 DCHECK(params); | 1956 DCHECK(params); |
| 1956 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1957 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1957 | 1958 |
| 1958 const FilePath& directory_path = params->search_file_path; | 1959 const FilePath& directory_path = params->search_file_path; |
| 1959 if (error != GDATA_FILE_OK) { | 1960 if (error != GDATA_FILE_OK) { |
| 1960 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() | 1961 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() |
| 1961 << ": " << error; | 1962 << ": " << error; |
| 1962 return; | 1963 return; |
| 1963 } | 1964 } |
| 1964 | 1965 |
| 1965 int unused_delta_feed_changestamp = 0; | 1966 int64 unused_delta_feed_changestamp = 0; |
| 1966 FeedToFileResourceMapUmaStats unused_uma_stats; | 1967 FeedToFileResourceMapUmaStats unused_uma_stats; |
| 1967 FileResourceIdMap file_map; | 1968 FileResourceIdMap file_map; |
| 1968 GDataWapiFeedProcessor feed_processor(directory_service_.get()); | 1969 GDataWapiFeedProcessor feed_processor(directory_service_.get()); |
| 1969 error = feed_processor.FeedToFileResourceMap( | 1970 error = feed_processor.FeedToFileResourceMap( |
| 1970 *params->feed_list, | 1971 *params->feed_list, |
| 1971 &file_map, | 1972 &file_map, |
| 1972 &unused_delta_feed_changestamp, | 1973 &unused_delta_feed_changestamp, |
| 1973 &unused_uma_stats); | 1974 &unused_uma_stats); |
| 1974 if (error != GDATA_FILE_OK) { | 1975 if (error != GDATA_FILE_OK) { |
| 1975 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() | 1976 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2176 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2177 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2177 RunTaskOnUIThread(base::Bind(&GDataFileSystem::GetAvailableSpaceOnUIThread, | 2178 RunTaskOnUIThread(base::Bind(&GDataFileSystem::GetAvailableSpaceOnUIThread, |
| 2178 ui_weak_ptr_, | 2179 ui_weak_ptr_, |
| 2179 CreateRelayCallback(callback))); | 2180 CreateRelayCallback(callback))); |
| 2180 } | 2181 } |
| 2181 | 2182 |
| 2182 void GDataFileSystem::GetAvailableSpaceOnUIThread( | 2183 void GDataFileSystem::GetAvailableSpaceOnUIThread( |
| 2183 const GetAvailableSpaceCallback& callback) { | 2184 const GetAvailableSpaceCallback& callback) { |
| 2184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2185 | 2186 |
| 2187 if (gdata::util::IsDriveV2ApiEnabled()) { | |
| 2188 documents_service_->GetAboutResource( | |
| 2189 base::Bind(&GDataFileSystem::OnGetQuotaStats, | |
|
satorux1
2012/08/08 13:18:51
OnGetAboutResource
We usually match the function
kochi
2012/08/08 16:53:27
Done.
| |
| 2190 ui_weak_ptr_, | |
| 2191 callback)); | |
| 2192 return; | |
| 2193 } | |
| 2194 | |
| 2186 documents_service_->GetAccountMetadata( | 2195 documents_service_->GetAccountMetadata( |
| 2187 base::Bind(&GDataFileSystem::OnGetAvailableSpace, | 2196 base::Bind(&GDataFileSystem::OnGetAvailableSpace, |
| 2188 ui_weak_ptr_, | 2197 ui_weak_ptr_, |
| 2189 callback)); | 2198 callback)); |
| 2190 } | 2199 } |
| 2191 | 2200 |
| 2192 void GDataFileSystem::OnGetAvailableSpace( | 2201 void GDataFileSystem::OnGetAvailableSpace( |
| 2193 const GetAvailableSpaceCallback& callback, | 2202 const GetAvailableSpaceCallback& callback, |
| 2194 GDataErrorCode status, | 2203 GDataErrorCode status, |
| 2195 scoped_ptr<base::Value> data) { | 2204 scoped_ptr<base::Value> data) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2207 if (!feed.get()) { | 2216 if (!feed.get()) { |
| 2208 callback.Run(GDATA_FILE_ERROR_FAILED, -1, -1); | 2217 callback.Run(GDATA_FILE_ERROR_FAILED, -1, -1); |
| 2209 return; | 2218 return; |
| 2210 } | 2219 } |
| 2211 | 2220 |
| 2212 callback.Run(GDATA_FILE_OK, | 2221 callback.Run(GDATA_FILE_OK, |
| 2213 feed->quota_bytes_total(), | 2222 feed->quota_bytes_total(), |
| 2214 feed->quota_bytes_used()); | 2223 feed->quota_bytes_used()); |
| 2215 } | 2224 } |
| 2216 | 2225 |
| 2226 void GDataFileSystem::OnGetQuotaStats( | |
| 2227 const GetAvailableSpaceCallback& callback, | |
| 2228 GDataErrorCode status, | |
| 2229 scoped_ptr<base::Value> data) { | |
|
satorux1
2012/08/08 13:18:51
data -> better name?
kochi
2012/08/08 16:53:27
Done.
named resource_json.
| |
| 2230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 2231 | |
| 2232 GDataFileError error = util::GDataToGDataFileError(status); | |
| 2233 if (error != GDATA_FILE_OK) { | |
| 2234 callback.Run(error, -1, -1); | |
|
satorux1
2012/08/08 13:18:51
Historically, we check if the callback is null alm
kochi
2012/08/08 16:53:27
Done.
| |
| 2235 return; | |
| 2236 } | |
| 2237 | |
| 2238 scoped_ptr<AboutResource> about; | |
| 2239 if (data.get()) | |
| 2240 about = AboutResource::CreateFrom(*data); | |
| 2241 | |
| 2242 if (!about.get()) { | |
| 2243 callback.Run(GDATA_FILE_ERROR_FAILED, -1, -1); | |
| 2244 return; | |
| 2245 } | |
| 2246 | |
| 2247 callback.Run(GDATA_FILE_OK, | |
| 2248 about->quota_bytes_total(), | |
| 2249 about->quota_bytes_used()); | |
| 2250 } | |
| 2251 | |
| 2217 void GDataFileSystem::OnCreateDirectoryCompleted( | 2252 void GDataFileSystem::OnCreateDirectoryCompleted( |
| 2218 const CreateDirectoryParams& params, | 2253 const CreateDirectoryParams& params, |
| 2219 GDataErrorCode status, | 2254 GDataErrorCode status, |
| 2220 scoped_ptr<base::Value> data) { | 2255 scoped_ptr<base::Value> data) { |
| 2221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2222 | 2257 |
| 2223 GDataFileError error = util::GDataToGDataFileError(status); | 2258 GDataFileError error = util::GDataToGDataFileError(status); |
| 2224 if (error != GDATA_FILE_OK) { | 2259 if (error != GDATA_FILE_OK) { |
| 2225 if (!params.callback.is_null()) | 2260 if (!params.callback.is_null()) |
| 2226 params.callback.Run(error); | 2261 params.callback.Run(error); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2388 | 2423 |
| 2389 feed_loader_->LoadFromCache( | 2424 feed_loader_->LoadFromCache( |
| 2390 false, // should_load_from_server. | 2425 false, // should_load_from_server. |
| 2391 // search_path doesn't matter if FindEntryCallback parameter is null . | 2426 // search_path doesn't matter if FindEntryCallback parameter is null . |
| 2392 FilePath(), | 2427 FilePath(), |
| 2393 FindEntryCallback()); | 2428 FindEntryCallback()); |
| 2394 } | 2429 } |
| 2395 | 2430 |
| 2396 GDataFileError GDataFileSystem::UpdateFromFeedForTesting( | 2431 GDataFileError GDataFileSystem::UpdateFromFeedForTesting( |
| 2397 const std::vector<DocumentFeed*>& feed_list, | 2432 const std::vector<DocumentFeed*>& feed_list, |
| 2398 int start_changestamp, | 2433 int64 start_changestamp, |
| 2399 int root_feed_changestamp) { | 2434 int64 root_feed_changestamp) { |
| 2400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2401 | 2436 |
| 2402 return feed_loader_->UpdateFromFeed(feed_list, | 2437 return feed_loader_->UpdateFromFeed(feed_list, |
| 2403 start_changestamp, | 2438 start_changestamp, |
| 2404 root_feed_changestamp); | 2439 root_feed_changestamp); |
| 2405 } | 2440 } |
| 2406 | 2441 |
| 2407 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, | 2442 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, |
| 2408 GDataFileError error, | 2443 GDataFileError error, |
| 2409 const FilePath& file_path) { | 2444 const FilePath& file_path) { |
| (...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3424 } | 3459 } |
| 3425 | 3460 |
| 3426 PlatformFileInfoProto entry_file_info; | 3461 PlatformFileInfoProto entry_file_info; |
| 3427 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3462 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
| 3428 *entry_proto->mutable_file_info() = entry_file_info; | 3463 *entry_proto->mutable_file_info() = entry_file_info; |
| 3429 if (!callback.is_null()) | 3464 if (!callback.is_null()) |
| 3430 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3465 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
| 3431 } | 3466 } |
| 3432 | 3467 |
| 3433 } // namespace gdata | 3468 } // namespace gdata |
| OLD | NEW |