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 "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 if (!ConvertTeamDriveChangeResourceToResourceEntry(input, &converted)) { |
| 31 &parent_resource_id)) | |
| 32 return false; | 31 return false; |
| 33 | 32 } |
| 34 converted.set_resource_id(input.file_id()); | 33 } else { |
| 34 if (input.file() && !ConvertFileResourceToResourceEntry( | |
| 35 *input.file(), &converted, &parent_resource_id)) | |
| 36 return false; | |
| 37 converted.set_resource_id(input.file_id()); | |
| 38 } | |
| 35 converted.set_deleted(converted.deleted() || input.is_deleted()); | 39 converted.set_deleted(converted.deleted() || input.is_deleted()); |
| 36 converted.set_modification_date(input.modification_date().ToInternalValue()); | 40 converted.set_modification_date(input.modification_date().ToInternalValue()); |
| 37 | 41 |
| 38 out_entry->Swap(&converted); | 42 out_entry->Swap(&converted); |
| 39 swap(*out_parent_resource_id, parent_resource_id); | 43 swap(*out_parent_resource_id, parent_resource_id); |
| 40 return true; | 44 return true; |
| 41 } | 45 } |
| 42 | 46 |
| 43 bool ConvertFileResourceToResourceEntry( | 47 bool ConvertFileResourceToResourceEntry( |
| 44 const google_apis::FileResource& input, | 48 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(); | 125 const int64_t image_rotation = input.image_media_metadata().rotation(); |
| 122 if (image_rotation != -1) | 126 if (image_rotation != -1) |
| 123 file_specific_info->set_image_rotation(image_rotation); | 127 file_specific_info->set_image_rotation(image_rotation); |
| 124 } | 128 } |
| 125 | 129 |
| 126 out_entry->Swap(&converted); | 130 out_entry->Swap(&converted); |
| 127 swap(*out_parent_resource_id, parent_resource_id); | 131 swap(*out_parent_resource_id, parent_resource_id); |
| 128 return true; | 132 return true; |
| 129 } | 133 } |
| 130 | 134 |
| 135 bool ConvertTeamDriveResourceToResourceEntry( | |
| 136 const google_apis::TeamDriveResource& input, | |
| 137 ResourceEntry* out_entry) { | |
| 138 DCHECK(out_entry); | |
| 139 if (input.id().empty()) | |
| 140 return false; | |
| 141 out_entry->set_title(input.name()); | |
| 142 out_entry->set_base_name(input.name()); | |
| 143 out_entry->set_resource_id(input.id()); | |
|
hashimoto
2017/04/11 07:55:14
set_resource_id() is called with input.team_drive_
yamaguchi
2017/04/11 10:11:41
Done.
This will be needed when we call this functi
| |
| 144 return true; | |
| 145 } | |
| 146 | |
| 147 bool ConvertTeamDriveChangeResourceToResourceEntry( | |
|
hashimoto
2017/04/11 07:55:14
This code should be part of ConvertChangeResourceT
yamaguchi
2017/04/11 10:11:41
Done.
| |
| 148 const google_apis::ChangeResource& input, | |
| 149 ResourceEntry* out_entry) { | |
| 150 DCHECK(out_entry); | |
| 151 DCHECK_EQ(google_apis::ChangeResource::TEAM_DRIVE, input.type()); | |
| 152 ResourceEntry converted; | |
| 153 converted.mutable_file_info()->set_is_directory(true); | |
| 154 converted.set_parent_local_id(util::kDriveTeamDrivesDirLocalId); | |
| 155 if (input.team_drive()) | |
| 156 if (!ConvertTeamDriveResourceToResourceEntry(*input.team_drive(), | |
| 157 &converted)) | |
| 158 return false; | |
| 159 if (!input.team_drive_id().empty()) { | |
|
hashimoto
2017/04/11 07:55:14
I don't think we need to do this check
yamaguchi
2017/04/11 10:11:41
Done.
| |
| 160 converted.set_resource_id(input.team_drive_id()); | |
| 161 } | |
| 162 if (converted.resource_id().empty()) | |
|
hashimoto
2017/04/11 07:55:14
and this (are you receiving Team Drive resource wi
yamaguchi
2017/04/11 10:11:41
Done.
| |
| 163 return false; | |
| 164 out_entry->Swap(&converted); | |
| 165 return true; | |
| 166 } | |
| 167 | |
| 131 void ConvertResourceEntryToFileInfo(const ResourceEntry& entry, | 168 void ConvertResourceEntryToFileInfo(const ResourceEntry& entry, |
| 132 base::File::Info* file_info) { | 169 base::File::Info* file_info) { |
| 133 file_info->size = entry.file_info().size(); | 170 file_info->size = entry.file_info().size(); |
| 134 file_info->is_directory = entry.file_info().is_directory(); | 171 file_info->is_directory = entry.file_info().is_directory(); |
| 135 file_info->is_symbolic_link = entry.file_info().is_symbolic_link(); | 172 file_info->is_symbolic_link = entry.file_info().is_symbolic_link(); |
| 136 file_info->last_modified = base::Time::FromInternalValue( | 173 file_info->last_modified = base::Time::FromInternalValue( |
| 137 entry.file_info().last_modified()); | 174 entry.file_info().last_modified()); |
| 138 file_info->last_accessed = base::Time::FromInternalValue( | 175 file_info->last_accessed = base::Time::FromInternalValue( |
| 139 entry.file_info().last_accessed()); | 176 entry.file_info().last_accessed()); |
| 140 file_info->creation_time = base::Time::FromInternalValue( | 177 file_info->creation_time = base::Time::FromInternalValue( |
| 141 entry.file_info().creation_time()); | 178 entry.file_info().creation_time()); |
| 142 } | 179 } |
| 143 | 180 |
| 144 } // namespace drive | 181 } // namespace drive |
| OLD | NEW |