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/drive/drive_api_util.h" | 5 #include "chrome/browser/drive/drive_api_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/scoped_platform_file_closer.h" | 10 #include "base/files/scoped_platform_file_closer.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 const char kGoogleDocumentMimeType[] = "application/vnd.google-apps.document"; | 32 const char kGoogleDocumentMimeType[] = "application/vnd.google-apps.document"; |
33 const char kGoogleDrawingMimeType[] = "application/vnd.google-apps.drawing"; | 33 const char kGoogleDrawingMimeType[] = "application/vnd.google-apps.drawing"; |
34 const char kGooglePresentationMimeType[] = | 34 const char kGooglePresentationMimeType[] = |
35 "application/vnd.google-apps.presentation"; | 35 "application/vnd.google-apps.presentation"; |
36 const char kGoogleSpreadsheetMimeType[] = | 36 const char kGoogleSpreadsheetMimeType[] = |
37 "application/vnd.google-apps.spreadsheet"; | 37 "application/vnd.google-apps.spreadsheet"; |
38 const char kGoogleTableMimeType[] = "application/vnd.google-apps.table"; | 38 const char kGoogleTableMimeType[] = "application/vnd.google-apps.table"; |
39 const char kGoogleFormMimeType[] = "application/vnd.google-apps.form"; | 39 const char kGoogleFormMimeType[] = "application/vnd.google-apps.form"; |
40 const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder"; | 40 const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder"; |
41 | 41 |
| 42 std::string GetMimeTypeFromEntryKind(google_apis::DriveEntryKind kind) { |
| 43 switch (kind) { |
| 44 case google_apis::ENTRY_KIND_DOCUMENT: |
| 45 return kGoogleDocumentMimeType; |
| 46 case google_apis::ENTRY_KIND_SPREADSHEET: |
| 47 return kGoogleSpreadsheetMimeType; |
| 48 case google_apis::ENTRY_KIND_PRESENTATION: |
| 49 return kGooglePresentationMimeType; |
| 50 case google_apis::ENTRY_KIND_DRAWING: |
| 51 return kGoogleDrawingMimeType; |
| 52 case google_apis::ENTRY_KIND_TABLE: |
| 53 return kGoogleTableMimeType; |
| 54 case google_apis::ENTRY_KIND_FORM: |
| 55 return kGoogleFormMimeType; |
| 56 default: |
| 57 return std::string(); |
| 58 } |
| 59 } |
| 60 |
42 ScopedVector<std::string> CopyScopedVectorString( | 61 ScopedVector<std::string> CopyScopedVectorString( |
43 const ScopedVector<std::string>& source) { | 62 const ScopedVector<std::string>& source) { |
44 ScopedVector<std::string> result; | 63 ScopedVector<std::string> result; |
45 result.reserve(source.size()); | 64 result.reserve(source.size()); |
46 for (size_t i = 0; i < source.size(); ++i) | 65 for (size_t i = 0; i < source.size(); ++i) |
47 result.push_back(new std::string(*source[i])); | 66 result.push_back(new std::string(*source[i])); |
48 | 67 |
49 return result.Pass(); | 68 return result.Pass(); |
50 } | 69 } |
51 | 70 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 "shared-with-me") != entry.labels().end()) { | 335 "shared-with-me") != entry.labels().end()) { |
317 // Set current time to mark the file is shared_with_me, since ResourceEntry | 336 // Set current time to mark the file is shared_with_me, since ResourceEntry |
318 // doesn't have |shared_with_me_date| equivalent. | 337 // doesn't have |shared_with_me_date| equivalent. |
319 file->set_shared_with_me_date(base::Time::Now()); | 338 file->set_shared_with_me_date(base::Time::Now()); |
320 } | 339 } |
321 | 340 |
322 file->set_shared(std::find(entry.labels().begin(), entry.labels().end(), | 341 file->set_shared(std::find(entry.labels().begin(), entry.labels().end(), |
323 "shared") != entry.labels().end()); | 342 "shared") != entry.labels().end()); |
324 | 343 |
325 file->set_download_url(entry.download_url()); | 344 file->set_download_url(entry.download_url()); |
326 if (entry.is_folder()) | 345 if (entry.is_folder()) { |
327 file->set_mime_type(kDriveFolderMimeType); | 346 file->set_mime_type(kDriveFolderMimeType); |
328 else | 347 } else { |
329 file->set_mime_type(entry.content_mime_type()); | 348 std::string mime_type = GetMimeTypeFromEntryKind(entry.kind()); |
| 349 if (mime_type.empty()) |
| 350 mime_type = entry.content_mime_type(); |
| 351 file->set_mime_type(mime_type); |
| 352 } |
330 | 353 |
331 file->set_md5_checksum(entry.file_md5()); | 354 file->set_md5_checksum(entry.file_md5()); |
332 file->set_file_size(entry.file_size()); | 355 file->set_file_size(entry.file_size()); |
333 | 356 |
334 file->mutable_labels()->set_trashed(entry.deleted()); | 357 file->mutable_labels()->set_trashed(entry.deleted()); |
335 file->set_etag(entry.etag()); | 358 file->set_etag(entry.etag()); |
336 | 359 |
337 google_apis::ImageMediaMetadata* image_media_metadata = | 360 google_apis::ImageMediaMetadata* image_media_metadata = |
338 file->mutable_image_media_metadata(); | 361 file->mutable_image_media_metadata(); |
339 image_media_metadata->set_width(entry.image_width()); | 362 image_media_metadata->set_width(entry.image_width()); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 | 618 |
596 base::MD5Digest digest; | 619 base::MD5Digest digest; |
597 base::MD5Final(&digest, &context); | 620 base::MD5Final(&digest, &context); |
598 return MD5DigestToBase16(digest); | 621 return MD5DigestToBase16(digest); |
599 } | 622 } |
600 | 623 |
601 const char kWapiRootDirectoryResourceId[] = "folder:root"; | 624 const char kWapiRootDirectoryResourceId[] = "folder:root"; |
602 | 625 |
603 } // namespace util | 626 } // namespace util |
604 } // namespace drive | 627 } // namespace drive |
OLD | NEW |