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 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1944 DCHECK(params); | 1945 DCHECK(params); |
1945 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1946 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1946 | 1947 |
1947 const FilePath& directory_path = params->search_file_path; | 1948 const FilePath& directory_path = params->search_file_path; |
1948 if (error != GDATA_FILE_OK) { | 1949 if (error != GDATA_FILE_OK) { |
1949 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() | 1950 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() |
1950 << ": " << error; | 1951 << ": " << error; |
1951 return; | 1952 return; |
1952 } | 1953 } |
1953 | 1954 |
1954 int unused_delta_feed_changestamp = 0; | 1955 int64 unused_delta_feed_changestamp = 0; |
1955 FeedToFileResourceMapUmaStats unused_uma_stats; | 1956 FeedToFileResourceMapUmaStats unused_uma_stats; |
1956 FileResourceIdMap file_map; | 1957 FileResourceIdMap file_map; |
1957 GDataWapiFeedProcessor feed_processor(directory_service_.get()); | 1958 GDataWapiFeedProcessor feed_processor(directory_service_.get()); |
1958 error = feed_processor.FeedToFileResourceMap( | 1959 error = feed_processor.FeedToFileResourceMap( |
1959 *params->feed_list, | 1960 *params->feed_list, |
1960 &file_map, | 1961 &file_map, |
1961 &unused_delta_feed_changestamp, | 1962 &unused_delta_feed_changestamp, |
1962 &unused_uma_stats); | 1963 &unused_uma_stats); |
1963 if (error != GDATA_FILE_OK) { | 1964 if (error != GDATA_FILE_OK) { |
1964 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() | 1965 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2164 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2165 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2165 RunTaskOnUIThread(base::Bind(&GDataFileSystem::GetAvailableSpaceOnUIThread, | 2166 RunTaskOnUIThread(base::Bind(&GDataFileSystem::GetAvailableSpaceOnUIThread, |
2166 ui_weak_ptr_, | 2167 ui_weak_ptr_, |
2167 CreateRelayCallback(callback))); | 2168 CreateRelayCallback(callback))); |
2168 } | 2169 } |
2169 | 2170 |
2170 void GDataFileSystem::GetAvailableSpaceOnUIThread( | 2171 void GDataFileSystem::GetAvailableSpaceOnUIThread( |
2171 const GetAvailableSpaceCallback& callback) { | 2172 const GetAvailableSpaceCallback& callback) { |
2172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2174 DCHECK(!callback.is_null()); |
| 2175 |
| 2176 if (gdata::util::IsDriveV2ApiEnabled()) { |
| 2177 documents_service_->GetAboutResource( |
| 2178 base::Bind(&GDataFileSystem::OnGetAboutResource, |
| 2179 ui_weak_ptr_, |
| 2180 callback)); |
| 2181 return; |
| 2182 } |
2173 | 2183 |
2174 documents_service_->GetAccountMetadata( | 2184 documents_service_->GetAccountMetadata( |
2175 base::Bind(&GDataFileSystem::OnGetAvailableSpace, | 2185 base::Bind(&GDataFileSystem::OnGetAvailableSpace, |
2176 ui_weak_ptr_, | 2186 ui_weak_ptr_, |
2177 callback)); | 2187 callback)); |
2178 } | 2188 } |
2179 | 2189 |
2180 void GDataFileSystem::OnGetAvailableSpace( | 2190 void GDataFileSystem::OnGetAvailableSpace( |
2181 const GetAvailableSpaceCallback& callback, | 2191 const GetAvailableSpaceCallback& callback, |
2182 GDataErrorCode status, | 2192 GDataErrorCode status, |
2183 scoped_ptr<base::Value> data) { | 2193 scoped_ptr<base::Value> data) { |
2184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2195 DCHECK(!callback.is_null()); |
2185 | 2196 |
2186 GDataFileError error = util::GDataToGDataFileError(status); | 2197 GDataFileError error = util::GDataToGDataFileError(status); |
2187 if (error != GDATA_FILE_OK) { | 2198 if (error != GDATA_FILE_OK) { |
2188 callback.Run(error, -1, -1); | 2199 callback.Run(error, -1, -1); |
2189 return; | 2200 return; |
2190 } | 2201 } |
2191 | 2202 |
2192 scoped_ptr<AccountMetadataFeed> feed; | 2203 scoped_ptr<AccountMetadataFeed> feed; |
2193 if (data.get()) | 2204 if (data.get()) |
2194 feed = AccountMetadataFeed::CreateFrom(*data); | 2205 feed = AccountMetadataFeed::CreateFrom(*data); |
2195 if (!feed.get()) { | 2206 if (!feed.get()) { |
2196 callback.Run(GDATA_FILE_ERROR_FAILED, -1, -1); | 2207 callback.Run(GDATA_FILE_ERROR_FAILED, -1, -1); |
2197 return; | 2208 return; |
2198 } | 2209 } |
2199 | 2210 |
2200 callback.Run(GDATA_FILE_OK, | 2211 callback.Run(GDATA_FILE_OK, |
2201 feed->quota_bytes_total(), | 2212 feed->quota_bytes_total(), |
2202 feed->quota_bytes_used()); | 2213 feed->quota_bytes_used()); |
2203 } | 2214 } |
2204 | 2215 |
| 2216 void GDataFileSystem::OnGetAboutResource( |
| 2217 const GetAvailableSpaceCallback& callback, |
| 2218 GDataErrorCode status, |
| 2219 scoped_ptr<base::Value> resource_json) { |
| 2220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2221 DCHECK(!callback.is_null()); |
| 2222 |
| 2223 GDataFileError error = util::GDataToGDataFileError(status); |
| 2224 if (error != GDATA_FILE_OK) { |
| 2225 callback.Run(error, -1, -1); |
| 2226 return; |
| 2227 } |
| 2228 |
| 2229 scoped_ptr<AboutResource> about; |
| 2230 if (resource_json.get()) |
| 2231 about = AboutResource::CreateFrom(*resource_json); |
| 2232 |
| 2233 if (!about.get()) { |
| 2234 callback.Run(GDATA_FILE_ERROR_FAILED, -1, -1); |
| 2235 return; |
| 2236 } |
| 2237 |
| 2238 callback.Run(GDATA_FILE_OK, |
| 2239 about->quota_bytes_total(), |
| 2240 about->quota_bytes_used()); |
| 2241 } |
| 2242 |
2205 void GDataFileSystem::OnCreateDirectoryCompleted( | 2243 void GDataFileSystem::OnCreateDirectoryCompleted( |
2206 const CreateDirectoryParams& params, | 2244 const CreateDirectoryParams& params, |
2207 GDataErrorCode status, | 2245 GDataErrorCode status, |
2208 scoped_ptr<base::Value> data) { | 2246 scoped_ptr<base::Value> data) { |
2209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2210 | 2248 |
2211 GDataFileError error = util::GDataToGDataFileError(status); | 2249 GDataFileError error = util::GDataToGDataFileError(status); |
2212 if (error != GDATA_FILE_OK) { | 2250 if (error != GDATA_FILE_OK) { |
2213 if (!params.callback.is_null()) | 2251 if (!params.callback.is_null()) |
2214 params.callback.Run(error); | 2252 params.callback.Run(error); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2376 | 2414 |
2377 feed_loader_->LoadFromCache( | 2415 feed_loader_->LoadFromCache( |
2378 false, // should_load_from_server. | 2416 false, // should_load_from_server. |
2379 // search_path doesn't matter if FindEntryCallback parameter is null . | 2417 // search_path doesn't matter if FindEntryCallback parameter is null . |
2380 FilePath(), | 2418 FilePath(), |
2381 FindEntryCallback()); | 2419 FindEntryCallback()); |
2382 } | 2420 } |
2383 | 2421 |
2384 GDataFileError GDataFileSystem::UpdateFromFeedForTesting( | 2422 GDataFileError GDataFileSystem::UpdateFromFeedForTesting( |
2385 const std::vector<DocumentFeed*>& feed_list, | 2423 const std::vector<DocumentFeed*>& feed_list, |
2386 int start_changestamp, | 2424 int64 start_changestamp, |
2387 int root_feed_changestamp) { | 2425 int64 root_feed_changestamp) { |
2388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2389 | 2427 |
2390 return feed_loader_->UpdateFromFeed(feed_list, | 2428 return feed_loader_->UpdateFromFeed(feed_list, |
2391 start_changestamp, | 2429 start_changestamp, |
2392 root_feed_changestamp); | 2430 root_feed_changestamp); |
2393 } | 2431 } |
2394 | 2432 |
2395 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, | 2433 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, |
2396 GDataFileError error, | 2434 GDataFileError error, |
2397 const FilePath& /* file_path */) { | 2435 const FilePath& /* file_path */) { |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3390 } | 3428 } |
3391 | 3429 |
3392 PlatformFileInfoProto entry_file_info; | 3430 PlatformFileInfoProto entry_file_info; |
3393 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3431 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3394 *entry_proto->mutable_file_info() = entry_file_info; | 3432 *entry_proto->mutable_file_info() = entry_file_info; |
3395 if (!callback.is_null()) | 3433 if (!callback.is_null()) |
3396 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3434 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
3397 } | 3435 } |
3398 | 3436 |
3399 } // namespace gdata | 3437 } // namespace gdata |
OLD | NEW |