| 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 "components/drive/resource_entry_conversion.h" | 5 #include "components/drive/resource_entry_conversion.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "components/drive/drive.pb.h" | 13 #include "components/drive/drive.pb.h" |
| 14 #include "components/drive/drive_api_util.h" | 14 #include "components/drive/drive_api_util.h" |
| 15 #include "components/drive/file_system_core_util.h" | 15 #include "components/drive/file_system_core_util.h" |
| 16 #include "google_apis/drive/drive_api_parser.h" | 16 #include "google_apis/drive/drive_api_parser.h" |
| 17 | 17 |
| 18 namespace drive { | 18 namespace drive { |
| 19 | 19 |
| 20 bool ConvertChangeResourceToResourceEntry( | 20 bool ConvertChangeResourceToResourceEntry( |
| 21 const google_apis::ChangeResource& input, | 21 const google_apis::ChangeResource& input, |
| 22 ResourceEntry* out_entry, | 22 ResourceEntry* out_entry, |
| 23 std::string* out_parent_resource_id) { | 23 std::string* out_parent_resource_id) { |
| 24 DCHECK(out_entry); | 24 DCHECK(out_entry); |
| 25 DCHECK(out_parent_resource_id); | 25 DCHECK(out_parent_resource_id); |
| 26 | 26 |
| 27 ResourceEntry converted; | 27 ResourceEntry converted; |
| 28 std::string parent_resource_id; | 28 std::string parent_resource_id; |
| 29 if (input.file() && | 29 if (input.type() == google_apis::ChangeResource::TEAM_DRIVE) { |
| 30 !ConvertFileResourceToResourceEntry(*input.file(), &converted, | 30 converted.mutable_file_info()->set_is_directory(true); |
| 31 &parent_resource_id)) | 31 converted.set_parent_local_id(util::kDriveTeamDrivesDirLocalId); |
| 32 if (input.team_drive()) |
| 33 ConvertTeamDriveResourceToResourceEntry(*input.team_drive(), &converted); |
| 34 converted.set_resource_id(input.team_drive_id()); |
| 35 } else { |
| 36 if (input.file() && !ConvertFileResourceToResourceEntry( |
| 37 *input.file(), &converted, &parent_resource_id)) |
| 32 return false; | 38 return false; |
| 33 | 39 converted.set_resource_id(input.file_id()); |
| 34 converted.set_resource_id(input.file_id()); | 40 } |
| 35 converted.set_deleted(converted.deleted() || input.is_deleted()); | 41 converted.set_deleted(converted.deleted() || input.is_deleted()); |
| 36 converted.set_modification_date(input.modification_date().ToInternalValue()); | 42 converted.set_modification_date(input.modification_date().ToInternalValue()); |
| 37 | 43 |
| 38 out_entry->Swap(&converted); | 44 out_entry->Swap(&converted); |
| 39 swap(*out_parent_resource_id, parent_resource_id); | 45 swap(*out_parent_resource_id, parent_resource_id); |
| 40 return true; | 46 return true; |
| 41 } | 47 } |
| 42 | 48 |
| 43 bool ConvertFileResourceToResourceEntry( | 49 bool ConvertFileResourceToResourceEntry( |
| 44 const google_apis::FileResource& input, | 50 const google_apis::FileResource& input, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 const int64_t image_rotation = input.image_media_metadata().rotation(); | 127 const int64_t image_rotation = input.image_media_metadata().rotation(); |
| 122 if (image_rotation != -1) | 128 if (image_rotation != -1) |
| 123 file_specific_info->set_image_rotation(image_rotation); | 129 file_specific_info->set_image_rotation(image_rotation); |
| 124 } | 130 } |
| 125 | 131 |
| 126 out_entry->Swap(&converted); | 132 out_entry->Swap(&converted); |
| 127 swap(*out_parent_resource_id, parent_resource_id); | 133 swap(*out_parent_resource_id, parent_resource_id); |
| 128 return true; | 134 return true; |
| 129 } | 135 } |
| 130 | 136 |
| 137 void ConvertTeamDriveResourceToResourceEntry( |
| 138 const google_apis::TeamDriveResource& input, |
| 139 ResourceEntry* out_entry) { |
| 140 DCHECK(out_entry); |
| 141 out_entry->set_title(input.name()); |
| 142 out_entry->set_base_name(input.name()); |
| 143 } |
| 144 |
| 131 void ConvertResourceEntryToFileInfo(const ResourceEntry& entry, | 145 void ConvertResourceEntryToFileInfo(const ResourceEntry& entry, |
| 132 base::File::Info* file_info) { | 146 base::File::Info* file_info) { |
| 133 file_info->size = entry.file_info().size(); | 147 file_info->size = entry.file_info().size(); |
| 134 file_info->is_directory = entry.file_info().is_directory(); | 148 file_info->is_directory = entry.file_info().is_directory(); |
| 135 file_info->is_symbolic_link = entry.file_info().is_symbolic_link(); | 149 file_info->is_symbolic_link = entry.file_info().is_symbolic_link(); |
| 136 file_info->last_modified = base::Time::FromInternalValue( | 150 file_info->last_modified = base::Time::FromInternalValue( |
| 137 entry.file_info().last_modified()); | 151 entry.file_info().last_modified()); |
| 138 file_info->last_accessed = base::Time::FromInternalValue( | 152 file_info->last_accessed = base::Time::FromInternalValue( |
| 139 entry.file_info().last_accessed()); | 153 entry.file_info().last_accessed()); |
| 140 file_info->creation_time = base::Time::FromInternalValue( | 154 file_info->creation_time = base::Time::FromInternalValue( |
| 141 entry.file_info().creation_time()); | 155 entry.file_info().creation_time()); |
| 142 } | 156 } |
| 143 | 157 |
| 144 } // namespace drive | 158 } // namespace drive |
| OLD | NEW |