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/drive/change_list_processor.h" | 5 #include "chrome/browser/chromeos/drive/change_list_processor.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/strings/string_number_conversions.h" |
8 #include "chrome/browser/chromeos/drive/drive.pb.h" | 9 #include "chrome/browser/chromeos/drive/drive.pb.h" |
9 #include "chrome/browser/chromeos/drive/file_system_util.h" | 10 #include "chrome/browser/chromeos/drive/file_system_util.h" |
10 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" | 11 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" |
11 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 12 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
12 #include "chrome/browser/google_apis/drive_api_parser.h" | 13 #include "chrome/browser/google_apis/drive_api_parser.h" |
13 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 14 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
14 | 15 |
15 namespace drive { | 16 namespace drive { |
16 namespace internal { | 17 namespace internal { |
17 | 18 |
| 19 std::string DirectoryFetchInfo::ToString() const { |
| 20 return ("resource_id: " + resource_id_ + |
| 21 ", changestamp: " + base::Int64ToString(changestamp_)); |
| 22 } |
| 23 |
18 ChangeList::ChangeList(const google_apis::ResourceList& resource_list) | 24 ChangeList::ChangeList(const google_apis::ResourceList& resource_list) |
19 : largest_changestamp_(resource_list.largest_changestamp()) { | 25 : largest_changestamp_(resource_list.largest_changestamp()) { |
20 resource_list.GetNextFeedURL(&next_url_); | 26 resource_list.GetNextFeedURL(&next_url_); |
21 | 27 |
22 entries_.resize(resource_list.entries().size()); | 28 entries_.resize(resource_list.entries().size()); |
23 size_t entries_index = 0; | 29 size_t entries_index = 0; |
24 for (size_t i = 0; i < resource_list.entries().size(); ++i) { | 30 for (size_t i = 0; i < resource_list.entries().size(); ++i) { |
25 if (ConvertToResourceEntry(*resource_list.entries()[i], | 31 if (ConvertToResourceEntry(*resource_list.entries()[i], |
26 &entries_[entries_index])) | 32 &entries_[entries_index])) |
27 ++entries_index; | 33 ++entries_index; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 uma_stats->IncrementNumSharedWithMeEntries(); | 284 uma_stats->IncrementNumSharedWithMeEntries(); |
279 } | 285 } |
280 | 286 |
281 (*entry_map)[entry->resource_id()].Swap(entry); | 287 (*entry_map)[entry->resource_id()].Swap(entry); |
282 LOG_IF(WARNING, !entry->resource_id().empty()) | 288 LOG_IF(WARNING, !entry->resource_id().empty()) |
283 << "Found duplicated file: " << entry->base_name(); | 289 << "Found duplicated file: " << entry->base_name(); |
284 } | 290 } |
285 } | 291 } |
286 } | 292 } |
287 | 293 |
| 294 // static |
| 295 FileError ChangeListProcessor::RefreshDirectory( |
| 296 ResourceMetadata* resource_metadata, |
| 297 const DirectoryFetchInfo& directory_fetch_info, |
| 298 const ResourceEntryMap& entry_map, |
| 299 base::FilePath* out_file_path) { |
| 300 DCHECK(!directory_fetch_info.empty()); |
| 301 |
| 302 ResourceEntry directory; |
| 303 FileError error = resource_metadata->GetResourceEntryById( |
| 304 directory_fetch_info.resource_id(), &directory); |
| 305 if (error != FILE_ERROR_OK) |
| 306 return error; |
| 307 |
| 308 if (!directory.file_info().is_directory()) |
| 309 return FILE_ERROR_NOT_A_DIRECTORY; |
| 310 |
| 311 // Go through the entry map. Handle existing entries and new entries. |
| 312 for (ResourceEntryMap::const_iterator it = entry_map.begin(); |
| 313 it != entry_map.end(); ++it) { |
| 314 const ResourceEntry& entry = it->second; |
| 315 // Skip if the parent resource ID does not match. This is needed to |
| 316 // handle entries with multiple parents. For such entries, the first |
| 317 // parent is picked and other parents are ignored, hence some entries may |
| 318 // have a parent resource ID which does not match the target directory's. |
| 319 if (entry.parent_local_id() != directory_fetch_info.resource_id()) { |
| 320 DVLOG(1) << "Wrong-parent entry rejected: " << entry.resource_id(); |
| 321 continue; |
| 322 } |
| 323 |
| 324 error = resource_metadata->RefreshEntry(entry); |
| 325 if (error == FILE_ERROR_NOT_FOUND) // If refreshing fails, try adding. |
| 326 error = resource_metadata->AddEntry(entry); |
| 327 |
| 328 if (error != FILE_ERROR_OK) |
| 329 return error; |
| 330 } |
| 331 |
| 332 directory.mutable_directory_specific_info()->set_changestamp( |
| 333 directory_fetch_info.changestamp()); |
| 334 error = resource_metadata->RefreshEntry(directory); |
| 335 if (error != FILE_ERROR_OK) |
| 336 return error; |
| 337 |
| 338 *out_file_path = resource_metadata->GetFilePath(directory.resource_id()); |
| 339 return FILE_ERROR_OK; |
| 340 } |
| 341 |
288 void ChangeListProcessor::UpdateRootEntry(int64 largest_changestamp) { | 342 void ChangeListProcessor::UpdateRootEntry(int64 largest_changestamp) { |
289 ResourceEntry root; | 343 ResourceEntry root; |
290 FileError error = resource_metadata_->GetResourceEntryByPath( | 344 FileError error = resource_metadata_->GetResourceEntryByPath( |
291 util::GetDriveMyDriveRootPath(), &root); | 345 util::GetDriveMyDriveRootPath(), &root); |
292 | 346 |
293 if (error != FILE_ERROR_OK) { | 347 if (error != FILE_ERROR_OK) { |
294 // TODO(satorux): Need to trigger recovery if root is corrupt. | 348 // TODO(satorux): Need to trigger recovery if root is corrupt. |
295 LOG(WARNING) << "Failed to get the entry for root directory"; | 349 LOG(WARNING) << "Failed to get the entry for root directory"; |
296 return; | 350 return; |
297 } | 351 } |
(...skipping 25 matching lines...) Expand all Loading... |
323 &child_directories); | 377 &child_directories); |
324 changed_dirs_.insert(child_directories.begin(), | 378 changed_dirs_.insert(child_directories.begin(), |
325 child_directories.end()); | 379 child_directories.end()); |
326 } | 380 } |
327 } | 381 } |
328 } | 382 } |
329 } | 383 } |
330 | 384 |
331 } // namespace internal | 385 } // namespace internal |
332 } // namespace drive | 386 } // namespace drive |
OLD | NEW |