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" | 15 #include "google_apis/drive/drive_entry_kinds.h" |
16 | 16 |
17 namespace drive { | 17 namespace drive { |
18 | 18 |
19 bool ConvertChangeResourceToResourceEntry( | 19 bool ConvertChangeResourceToResourceEntry( |
20 const google_apis::ChangeResource& input, | 20 const google_apis::ChangeResource& input, |
21 ResourceEntry* out_entry, | 21 ResourceEntry* out_entry, |
22 std::string* out_parent_resource_id) { | 22 std::string* out_parent_resource_id) { |
23 DCHECK(out_entry); | 23 DCHECK(out_entry); |
24 DCHECK(out_parent_resource_id); | 24 DCHECK(out_parent_resource_id); |
25 | 25 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 file_info->set_last_modified(input.modified_date().ToInternalValue()); | 72 file_info->set_last_modified(input.modified_date().ToInternalValue()); |
73 // If the file has never been viewed (last_viewed_by_me_date().is_null() == | 73 // 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 | 74 // true), then we will set the last_accessed field in the protocol buffer to |
75 // 0. | 75 // 0. |
76 file_info->set_last_accessed( | 76 file_info->set_last_accessed( |
77 input.last_viewed_by_me_date().ToInternalValue()); | 77 input.last_viewed_by_me_date().ToInternalValue()); |
78 file_info->set_creation_time(input.created_date().ToInternalValue()); | 78 file_info->set_creation_time(input.created_date().ToInternalValue()); |
79 | 79 |
80 // TODO(hashimoto): Get rid of WAPI stuff. crbug.com/357038 | 80 // TODO(hashimoto): Get rid of WAPI stuff. crbug.com/357038 |
81 const google_apis::DriveEntryKind entry_kind = util::GetKind(input); | 81 const google_apis::DriveEntryKind entry_kind = util::GetKind(input); |
82 const int entry_kind_class = | 82 const int entry_kind_class = google_apis::ClassifyEntryKind(entry_kind); |
83 google_apis::ResourceEntry::ClassifyEntryKind(entry_kind); | 83 const bool is_file = entry_kind_class & google_apis::KIND_OF_FILE; |
84 const bool is_file = entry_kind_class & | 84 const bool is_hosted_document = |
85 google_apis::ResourceEntry::KIND_OF_FILE; | 85 entry_kind_class & google_apis::KIND_OF_HOSTED_DOCUMENT; |
86 const bool is_hosted_document = entry_kind_class & | 86 const bool is_folder = entry_kind_class & google_apis::KIND_OF_FOLDER; |
87 google_apis::ResourceEntry::KIND_OF_HOSTED_DOCUMENT; | |
88 const bool is_folder = entry_kind_class & | |
89 google_apis::ResourceEntry::KIND_OF_FOLDER; | |
90 | 87 |
91 if (is_file || is_hosted_document) { | 88 if (is_file || is_hosted_document) { |
92 FileSpecificInfo* file_specific_info = | 89 FileSpecificInfo* file_specific_info = |
93 converted.mutable_file_specific_info(); | 90 converted.mutable_file_specific_info(); |
94 if (is_file) { | 91 if (is_file) { |
95 file_info->set_size(input.file_size()); | 92 file_info->set_size(input.file_size()); |
96 file_specific_info->set_md5(input.md5_checksum()); | 93 file_specific_info->set_md5(input.md5_checksum()); |
97 } else if (is_hosted_document) { | 94 } else if (is_hosted_document) { |
98 // Attach .g<something> extension to hosted documents so we can special | 95 // Attach .g<something> extension to hosted documents so we can special |
99 // case their handling in UI. | 96 // case their handling in UI. |
100 // TODO(satorux): Figure out better way how to pass input info like kind | 97 // TODO(satorux): Figure out better way how to pass input info like kind |
101 // to UI through the File API stack. | 98 // to UI through the File API stack. |
102 const std::string document_extension = | 99 const std::string document_extension = |
103 google_apis::ResourceEntry::GetHostedDocumentExtension(entry_kind); | 100 google_apis::GetHostedDocumentExtension(entry_kind); |
104 file_specific_info->set_document_extension(document_extension); | 101 file_specific_info->set_document_extension(document_extension); |
105 converted.set_base_name( | 102 converted.set_base_name( |
106 util::NormalizeFileName(converted.title() + document_extension)); | 103 util::NormalizeFileName(converted.title() + document_extension)); |
107 | 104 |
108 // We don't know the size of hosted docs and it does not matter since | 105 // We don't know the size of hosted docs and it does not matter since |
109 // it has no effect on the quota. | 106 // it has no effect on the quota. |
110 file_info->set_size(0); | 107 file_info->set_size(0); |
111 } | 108 } |
112 file_info->set_is_directory(false); | 109 file_info->set_is_directory(false); |
113 file_specific_info->set_content_mime_type(input.mime_type()); | 110 file_specific_info->set_content_mime_type(input.mime_type()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 file_info->is_symbolic_link = entry.file_info().is_symbolic_link(); | 144 file_info->is_symbolic_link = entry.file_info().is_symbolic_link(); |
148 file_info->last_modified = base::Time::FromInternalValue( | 145 file_info->last_modified = base::Time::FromInternalValue( |
149 entry.file_info().last_modified()); | 146 entry.file_info().last_modified()); |
150 file_info->last_accessed = base::Time::FromInternalValue( | 147 file_info->last_accessed = base::Time::FromInternalValue( |
151 entry.file_info().last_accessed()); | 148 entry.file_info().last_accessed()); |
152 file_info->creation_time = base::Time::FromInternalValue( | 149 file_info->creation_time = base::Time::FromInternalValue( |
153 entry.file_info().creation_time()); | 150 entry.file_info().creation_time()); |
154 } | 151 } |
155 | 152 |
156 } // namespace drive | 153 } // namespace drive |
OLD | NEW |