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)) | 31 &parent_resource_id)) { |
32 return false; | 32 return false; |
33 | 33 } |
34 converted.set_resource_id(input.file_id()); | 34 } else { |
35 if (input.file() && !ConvertFileResourceToResourceEntry( | |
36 *input.file(), &converted, &parent_resource_id)) | |
37 return false; | |
38 converted.set_resource_id(input.file_id()); | |
39 } | |
35 converted.set_deleted(converted.deleted() || input.is_deleted()); | 40 converted.set_deleted(converted.deleted() || input.is_deleted()); |
36 converted.set_modification_date(input.modification_date().ToInternalValue()); | 41 converted.set_modification_date(input.modification_date().ToInternalValue()); |
37 | 42 |
38 out_entry->Swap(&converted); | 43 out_entry->Swap(&converted); |
39 swap(*out_parent_resource_id, parent_resource_id); | 44 swap(*out_parent_resource_id, parent_resource_id); |
40 return true; | 45 return true; |
41 } | 46 } |
42 | 47 |
43 bool ConvertFileResourceToResourceEntry( | 48 bool ConvertFileResourceToResourceEntry( |
44 const google_apis::FileResource& input, | 49 const google_apis::FileResource& input, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 file_info->is_directory = entry.file_info().is_directory(); | 139 file_info->is_directory = entry.file_info().is_directory(); |
135 file_info->is_symbolic_link = entry.file_info().is_symbolic_link(); | 140 file_info->is_symbolic_link = entry.file_info().is_symbolic_link(); |
136 file_info->last_modified = base::Time::FromInternalValue( | 141 file_info->last_modified = base::Time::FromInternalValue( |
137 entry.file_info().last_modified()); | 142 entry.file_info().last_modified()); |
138 file_info->last_accessed = base::Time::FromInternalValue( | 143 file_info->last_accessed = base::Time::FromInternalValue( |
139 entry.file_info().last_accessed()); | 144 entry.file_info().last_accessed()); |
140 file_info->creation_time = base::Time::FromInternalValue( | 145 file_info->creation_time = base::Time::FromInternalValue( |
141 entry.file_info().creation_time()); | 146 entry.file_info().creation_time()); |
142 } | 147 } |
143 | 148 |
149 bool ConvertTeamDriveChangeResourceToResourceEntry( | |
hashimoto
2017/04/10 11:01:24
For FileResource, we have ConvertFileResourceToRes
yamaguchi
2017/04/11 07:08:07
Splitted ConvertTeamDriveResourceToResourceEntry,
| |
150 const google_apis::ChangeResource& input, | |
151 ResourceEntry* out_entry, | |
152 std::string* out_parent_resource_id) { | |
153 DCHECK(out_entry); | |
154 DCHECK(out_parent_resource_id); | |
155 DCHECK_EQ(google_apis::ChangeResource::TEAM_DRIVE, input.type()); | |
156 ResourceEntry converted; | |
157 converted.mutable_file_info()->set_is_directory(true); | |
158 converted.set_parent_local_id(util::kDriveTeamDrivesDirLocalId); | |
159 *out_parent_resource_id = util::kDriveTeamDrivesDirVirtualResourceId; | |
160 if (input.team_drive()) { | |
161 converted.set_title(input.team_drive()->name()); | |
162 converted.set_base_name(input.team_drive()->name()); | |
163 } | |
164 converted.set_resource_id(input.team_drive_id()); | |
165 out_entry->Swap(&converted); | |
166 return true; | |
167 } | |
168 | |
144 } // namespace drive | 169 } // namespace drive |
OLD | NEW |