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 const bool is_folder = input.IsDirectory(); |
81 const google_apis::DriveEntryKind entry_kind = util::GetKind(input); | 80 const bool is_hosted_document = |
82 const int entry_kind_class = | 81 drive::util::IsHostedDocument(input.mime_type()); |
83 google_apis::ResourceEntry::ClassifyEntryKind(entry_kind); | 82 const bool is_file = !is_folder && !is_hosted_document; |
hashimoto
2014/07/14 08:23:26
nit: No need to have this bool now?
fukino
2014/07/14 09:10:53
Done. Removed these temporary bool variables.
| |
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 | 83 |
91 if (is_file || is_hosted_document) { | 84 if (is_file || is_hosted_document) { |
92 FileSpecificInfo* file_specific_info = | 85 FileSpecificInfo* file_specific_info = |
93 converted.mutable_file_specific_info(); | 86 converted.mutable_file_specific_info(); |
94 if (is_file) { | 87 if (is_file) { |
95 file_info->set_size(input.file_size()); | 88 file_info->set_size(input.file_size()); |
96 file_specific_info->set_md5(input.md5_checksum()); | 89 file_specific_info->set_md5(input.md5_checksum()); |
97 } else if (is_hosted_document) { | 90 } else if (is_hosted_document) { |
98 // Attach .g<something> extension to hosted documents so we can special | 91 // Attach .g<something> extension to hosted documents so we can special |
99 // case their handling in UI. | 92 // case their handling in UI. |
100 // TODO(satorux): Figure out better way how to pass input info like kind | 93 // TODO(satorux): Figure out better way how to pass input info like kind |
101 // to UI through the File API stack. | 94 // to UI through the File API stack. |
102 const std::string document_extension = | 95 const std::string document_extension = |
103 google_apis::ResourceEntry::GetHostedDocumentExtension(entry_kind); | 96 drive::util::GetHostedDocumentExtension(input.mime_type()); |
104 file_specific_info->set_document_extension(document_extension); | 97 file_specific_info->set_document_extension(document_extension); |
105 converted.set_base_name( | 98 converted.set_base_name( |
106 util::NormalizeFileName(converted.title() + document_extension)); | 99 util::NormalizeFileName(converted.title() + document_extension)); |
107 | 100 |
108 // We don't know the size of hosted docs and it does not matter since | 101 // We don't know the size of hosted docs and it does not matter since |
109 // it has no effect on the quota. | 102 // it has no effect on the quota. |
110 file_info->set_size(0); | 103 file_info->set_size(0); |
111 } | 104 } |
112 file_info->set_is_directory(false); | 105 file_info->set_is_directory(false); |
113 file_specific_info->set_content_mime_type(input.mime_type()); | 106 file_specific_info->set_content_mime_type(input.mime_type()); |
114 file_specific_info->set_is_hosted_document(is_hosted_document); | 107 file_specific_info->set_is_hosted_document(is_hosted_document); |
115 | 108 |
116 if (!input.alternate_link().is_empty()) | 109 if (!input.alternate_link().is_empty()) |
117 file_specific_info->set_alternate_url(input.alternate_link().spec()); | 110 file_specific_info->set_alternate_url(input.alternate_link().spec()); |
118 | 111 |
119 const int64 image_width = input.image_media_metadata().width(); | 112 const int64 image_width = input.image_media_metadata().width(); |
120 if (image_width != -1) | 113 if (image_width != -1) |
121 file_specific_info->set_image_width(image_width); | 114 file_specific_info->set_image_width(image_width); |
122 | 115 |
123 const int64 image_height = input.image_media_metadata().height(); | 116 const int64 image_height = input.image_media_metadata().height(); |
124 if (image_height != -1) | 117 if (image_height != -1) |
125 file_specific_info->set_image_height(image_height); | 118 file_specific_info->set_image_height(image_height); |
126 | 119 |
127 const int64 image_rotation = input.image_media_metadata().rotation(); | 120 const int64 image_rotation = input.image_media_metadata().rotation(); |
128 if (image_rotation != -1) | 121 if (image_rotation != -1) |
129 file_specific_info->set_image_rotation(image_rotation); | 122 file_specific_info->set_image_rotation(image_rotation); |
130 } else if (is_folder) { | 123 } else if (is_folder) { |
131 file_info->set_is_directory(true); | 124 file_info->set_is_directory(true); |
132 } else { | 125 } else { |
133 // The entry is something that doesn't map into files (i.e. sites). | 126 // The entry is something that doesn't map into files (i.e. sites). |
hashimoto
2014/07/14 08:23:26
This branch is never reached.
fukino
2014/07/14 09:10:53
Done.
| |
134 // We don't handle these kind of entries hence return false. | 127 // We don't handle these kind of entries hence return false. |
135 return false; | 128 return false; |
136 } | 129 } |
137 | 130 |
138 out_entry->Swap(&converted); | 131 out_entry->Swap(&converted); |
139 swap(*out_parent_resource_id, parent_resource_id); | 132 swap(*out_parent_resource_id, parent_resource_id); |
140 return true; | 133 return true; |
141 } | 134 } |
142 | 135 |
143 void ConvertResourceEntryToFileInfo(const ResourceEntry& entry, | 136 void ConvertResourceEntryToFileInfo(const ResourceEntry& entry, |
144 base::File::Info* file_info) { | 137 base::File::Info* file_info) { |
145 file_info->size = entry.file_info().size(); | 138 file_info->size = entry.file_info().size(); |
146 file_info->is_directory = entry.file_info().is_directory(); | 139 file_info->is_directory = entry.file_info().is_directory(); |
147 file_info->is_symbolic_link = entry.file_info().is_symbolic_link(); | 140 file_info->is_symbolic_link = entry.file_info().is_symbolic_link(); |
148 file_info->last_modified = base::Time::FromInternalValue( | 141 file_info->last_modified = base::Time::FromInternalValue( |
149 entry.file_info().last_modified()); | 142 entry.file_info().last_modified()); |
150 file_info->last_accessed = base::Time::FromInternalValue( | 143 file_info->last_accessed = base::Time::FromInternalValue( |
151 entry.file_info().last_accessed()); | 144 entry.file_info().last_accessed()); |
152 file_info->creation_time = base::Time::FromInternalValue( | 145 file_info->creation_time = base::Time::FromInternalValue( |
153 entry.file_info().creation_time()); | 146 entry.file_info().creation_time()); |
154 } | 147 } |
155 | 148 |
156 } // namespace drive | 149 } // namespace drive |
OLD | NEW |