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/resource_entry_conversion.h" | 5 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "chrome/browser/chromeos/drive/drive.pb.h" | 11 #include "chrome/browser/chromeos/drive/drive.pb.h" |
12 #include "chrome/browser/chromeos/drive/file_system_util.h" | 12 #include "chrome/browser/chromeos/drive/file_system_util.h" |
13 #include "chrome/browser/drive/drive_api_util.h" | 13 #include "chrome/browser/drive/drive_api_util.h" |
14 #include "google_apis/drive/drive_api_parser.h" | 14 #include "google_apis/drive/drive_api_parser.h" |
15 #include "google_apis/drive/gdata_wapi_parser.h" | |
16 | 15 |
17 namespace drive { | 16 namespace drive { |
18 | 17 |
19 bool ConvertChangeResourceToResourceEntry( | 18 bool ConvertChangeResourceToResourceEntry( |
20 const google_apis::ChangeResource& input, | 19 const google_apis::ChangeResource& input, |
21 ResourceEntry* out_entry, | 20 ResourceEntry* out_entry, |
22 std::string* out_parent_resource_id) { | 21 std::string* out_parent_resource_id) { |
23 DCHECK(out_entry); | 22 DCHECK(out_entry); |
24 DCHECK(out_parent_resource_id); | 23 DCHECK(out_parent_resource_id); |
25 | 24 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 PlatformFileInfoProto* file_info = converted.mutable_file_info(); | 69 PlatformFileInfoProto* file_info = converted.mutable_file_info(); |
71 | 70 |
72 file_info->set_last_modified(input.modified_date().ToInternalValue()); | 71 file_info->set_last_modified(input.modified_date().ToInternalValue()); |
73 // If the file has never been viewed (last_viewed_by_me_date().is_null() == | 72 // If the file has never been viewed (last_viewed_by_me_date().is_null() == |
74 // true), then we will set the last_accessed field in the protocol buffer to | 73 // true), then we will set the last_accessed field in the protocol buffer to |
75 // 0. | 74 // 0. |
76 file_info->set_last_accessed( | 75 file_info->set_last_accessed( |
77 input.last_viewed_by_me_date().ToInternalValue()); | 76 input.last_viewed_by_me_date().ToInternalValue()); |
78 file_info->set_creation_time(input.created_date().ToInternalValue()); | 77 file_info->set_creation_time(input.created_date().ToInternalValue()); |
79 | 78 |
80 // TODO(hashimoto): Get rid of WAPI stuff. crbug.com/357038 | 79 if (input.IsDirectory()) { |
81 const google_apis::DriveEntryKind entry_kind = util::GetKind(input); | 80 file_info->set_is_directory(true); |
82 const int entry_kind_class = | 81 } else { |
83 google_apis::ResourceEntry::ClassifyEntryKind(entry_kind); | |
84 const bool is_file = entry_kind_class & | |
85 google_apis::ResourceEntry::KIND_OF_FILE; | |
86 const bool is_hosted_document = entry_kind_class & | |
87 google_apis::ResourceEntry::KIND_OF_HOSTED_DOCUMENT; | |
88 const bool is_folder = entry_kind_class & | |
89 google_apis::ResourceEntry::KIND_OF_FOLDER; | |
90 | |
91 if (is_file || is_hosted_document) { | |
92 FileSpecificInfo* file_specific_info = | 82 FileSpecificInfo* file_specific_info = |
93 converted.mutable_file_specific_info(); | 83 converted.mutable_file_specific_info(); |
94 if (is_file) { | 84 if (!drive::util::IsHostedDocument(input.mime_type())) { |
95 file_info->set_size(input.file_size()); | 85 file_info->set_size(input.file_size()); |
96 file_specific_info->set_md5(input.md5_checksum()); | 86 file_specific_info->set_md5(input.md5_checksum()); |
97 } else if (is_hosted_document) { | 87 file_specific_info->set_is_hosted_document(false); |
| 88 } else { |
98 // Attach .g<something> extension to hosted documents so we can special | 89 // Attach .g<something> extension to hosted documents so we can special |
99 // case their handling in UI. | 90 // case their handling in UI. |
100 // TODO(satorux): Figure out better way how to pass input info like kind | 91 // TODO(satorux): Figure out better way how to pass input info like kind |
101 // to UI through the File API stack. | 92 // to UI through the File API stack. |
102 const std::string document_extension = | 93 const std::string document_extension = |
103 google_apis::ResourceEntry::GetHostedDocumentExtension(entry_kind); | 94 drive::util::GetHostedDocumentExtension(input.mime_type()); |
104 file_specific_info->set_document_extension(document_extension); | 95 file_specific_info->set_document_extension(document_extension); |
105 converted.set_base_name( | 96 converted.set_base_name( |
106 util::NormalizeFileName(converted.title() + document_extension)); | 97 util::NormalizeFileName(converted.title() + document_extension)); |
107 | 98 |
108 // We don't know the size of hosted docs and it does not matter since | 99 // We don't know the size of hosted docs and it does not matter since |
109 // it has no effect on the quota. | 100 // it has no effect on the quota. |
110 file_info->set_size(0); | 101 file_info->set_size(0); |
| 102 file_specific_info->set_is_hosted_document(true); |
111 } | 103 } |
112 file_info->set_is_directory(false); | 104 file_info->set_is_directory(false); |
113 file_specific_info->set_content_mime_type(input.mime_type()); | 105 file_specific_info->set_content_mime_type(input.mime_type()); |
114 file_specific_info->set_is_hosted_document(is_hosted_document); | |
115 | 106 |
116 if (!input.alternate_link().is_empty()) | 107 if (!input.alternate_link().is_empty()) |
117 file_specific_info->set_alternate_url(input.alternate_link().spec()); | 108 file_specific_info->set_alternate_url(input.alternate_link().spec()); |
118 | 109 |
119 const int64 image_width = input.image_media_metadata().width(); | 110 const int64 image_width = input.image_media_metadata().width(); |
120 if (image_width != -1) | 111 if (image_width != -1) |
121 file_specific_info->set_image_width(image_width); | 112 file_specific_info->set_image_width(image_width); |
122 | 113 |
123 const int64 image_height = input.image_media_metadata().height(); | 114 const int64 image_height = input.image_media_metadata().height(); |
124 if (image_height != -1) | 115 if (image_height != -1) |
125 file_specific_info->set_image_height(image_height); | 116 file_specific_info->set_image_height(image_height); |
126 | 117 |
127 const int64 image_rotation = input.image_media_metadata().rotation(); | 118 const int64 image_rotation = input.image_media_metadata().rotation(); |
128 if (image_rotation != -1) | 119 if (image_rotation != -1) |
129 file_specific_info->set_image_rotation(image_rotation); | 120 file_specific_info->set_image_rotation(image_rotation); |
130 } else if (is_folder) { | |
131 file_info->set_is_directory(true); | |
132 } else { | |
133 // The entry is something that doesn't map into files (i.e. sites). | |
134 // We don't handle these kind of entries hence return false. | |
135 return false; | |
136 } | 121 } |
137 | 122 |
138 out_entry->Swap(&converted); | 123 out_entry->Swap(&converted); |
139 swap(*out_parent_resource_id, parent_resource_id); | 124 swap(*out_parent_resource_id, parent_resource_id); |
140 return true; | 125 return true; |
141 } | 126 } |
142 | 127 |
143 void ConvertResourceEntryToFileInfo(const ResourceEntry& entry, | 128 void ConvertResourceEntryToFileInfo(const ResourceEntry& entry, |
144 base::File::Info* file_info) { | 129 base::File::Info* file_info) { |
145 file_info->size = entry.file_info().size(); | 130 file_info->size = entry.file_info().size(); |
146 file_info->is_directory = entry.file_info().is_directory(); | 131 file_info->is_directory = entry.file_info().is_directory(); |
147 file_info->is_symbolic_link = entry.file_info().is_symbolic_link(); | 132 file_info->is_symbolic_link = entry.file_info().is_symbolic_link(); |
148 file_info->last_modified = base::Time::FromInternalValue( | 133 file_info->last_modified = base::Time::FromInternalValue( |
149 entry.file_info().last_modified()); | 134 entry.file_info().last_modified()); |
150 file_info->last_accessed = base::Time::FromInternalValue( | 135 file_info->last_accessed = base::Time::FromInternalValue( |
151 entry.file_info().last_accessed()); | 136 entry.file_info().last_accessed()); |
152 file_info->creation_time = base::Time::FromInternalValue( | 137 file_info->creation_time = base::Time::FromInternalValue( |
153 entry.file_info().creation_time()); | 138 entry.file_info().creation_time()); |
154 } | 139 } |
155 | 140 |
156 } // namespace drive | 141 } // namespace drive |
OLD | NEW |