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/document_entry_conversion.h" | 5 #include "chrome/browser/chromeos/drive/document_entry_conversion.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/chromeos/drive/drive.pb.h" | 10 #include "chrome/browser/chromeos/drive/drive.pb.h" |
11 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 11 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
12 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 12 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
14 #include "net/base/escape.h" | 14 #include "net/base/escape.h" |
15 | 15 |
16 namespace gdata { | 16 namespace drive { |
17 | 17 |
18 DriveEntryProto ConvertDocumentEntryToDriveEntryProto( | 18 DriveEntryProto ConvertDocumentEntryToDriveEntryProto( |
19 const DocumentEntry& doc) { | 19 const gdata::DocumentEntry& doc) { |
20 DriveEntryProto entry_proto; | 20 DriveEntryProto entry_proto; |
21 | 21 |
22 // For regular files, the 'filename' and 'title' attribute in the metadata | 22 // For regular files, the 'filename' and 'title' attribute in the metadata |
23 // may be different (e.g. due to rename). To be consistent with the web | 23 // may be different (e.g. due to rename). To be consistent with the web |
24 // interface and other client to use the 'title' attribute, instead of | 24 // interface and other client to use the 'title' attribute, instead of |
25 // 'filename', as the file name in the local snapshot. | 25 // 'filename', as the file name in the local snapshot. |
26 entry_proto.set_title(UTF16ToUTF8(doc.title())); | 26 entry_proto.set_title(UTF16ToUTF8(doc.title())); |
27 entry_proto.set_base_name(util::EscapeUtf8FileName(entry_proto.title())); | 27 entry_proto.set_base_name(util::EscapeUtf8FileName(entry_proto.title())); |
28 | 28 |
29 entry_proto.set_resource_id(doc.resource_id()); | 29 entry_proto.set_resource_id(doc.resource_id()); |
30 entry_proto.set_content_url(doc.content_url().spec()); | 30 entry_proto.set_content_url(doc.content_url().spec()); |
31 | 31 |
32 const Link* edit_link = doc.GetLinkByType(Link::LINK_EDIT); | 32 const gdata::Link* edit_link = doc.GetLinkByType(gdata::Link::LINK_EDIT); |
33 if (edit_link) | 33 if (edit_link) |
34 entry_proto.set_edit_url(edit_link->href().spec()); | 34 entry_proto.set_edit_url(edit_link->href().spec()); |
35 | 35 |
36 const Link* parent_link = doc.GetLinkByType(Link::LINK_PARENT); | 36 const gdata::Link* parent_link = doc.GetLinkByType(gdata::Link::LINK_PARENT); |
37 if (parent_link) { | 37 if (parent_link) { |
38 entry_proto.set_parent_resource_id( | 38 entry_proto.set_parent_resource_id( |
39 util::ExtractResourceIdFromUrl(parent_link->href())); | 39 util::ExtractResourceIdFromUrl(parent_link->href())); |
40 } | 40 } |
41 | 41 |
42 entry_proto.set_deleted(doc.deleted()); | 42 entry_proto.set_deleted(doc.deleted()); |
43 entry_proto.set_kind(doc.kind()); | 43 entry_proto.set_kind(doc.kind()); |
44 | 44 |
45 PlatformFileInfoProto* file_info = entry_proto.mutable_file_info(); | 45 PlatformFileInfoProto* file_info = entry_proto.mutable_file_info(); |
46 | 46 |
47 file_info->set_last_modified(doc.updated_time().ToInternalValue()); | 47 file_info->set_last_modified(doc.updated_time().ToInternalValue()); |
48 // If the file has never been viewed (last_viewed_time().is_null() == true), | 48 // If the file has never been viewed (last_viewed_time().is_null() == true), |
49 // then we will set the last_accessed field in the protocol buffer to 0. | 49 // then we will set the last_accessed field in the protocol buffer to 0. |
50 file_info->set_last_accessed(doc.last_viewed_time().ToInternalValue()); | 50 file_info->set_last_accessed(doc.last_viewed_time().ToInternalValue()); |
51 file_info->set_creation_time(doc.published_time().ToInternalValue()); | 51 file_info->set_creation_time(doc.published_time().ToInternalValue()); |
52 | 52 |
53 if (doc.is_file() || doc.is_hosted_document()) { | 53 if (doc.is_file() || doc.is_hosted_document()) { |
54 DriveFileSpecificInfo* file_specific_info = | 54 DriveFileSpecificInfo* file_specific_info = |
55 entry_proto.mutable_file_specific_info(); | 55 entry_proto.mutable_file_specific_info(); |
56 if (doc.is_file()) { | 56 if (doc.is_file()) { |
57 file_info->set_size(doc.file_size()); | 57 file_info->set_size(doc.file_size()); |
58 file_specific_info->set_file_md5(doc.file_md5()); | 58 file_specific_info->set_file_md5(doc.file_md5()); |
59 | 59 |
60 // The resumable-edit-media link should only be present for regular | 60 // The resumable-edit-media link should only be present for regular |
61 // files as hosted documents are not uploadable. | 61 // files as hosted documents are not uploadable. |
62 const Link* upload_link = doc.GetLinkByType( | 62 const gdata::Link* upload_link = doc.GetLinkByType( |
63 Link::LINK_RESUMABLE_EDIT_MEDIA); | 63 gdata::Link::LINK_RESUMABLE_EDIT_MEDIA); |
64 if (upload_link) | 64 if (upload_link) |
65 entry_proto.set_upload_url(upload_link->href().spec()); | 65 entry_proto.set_upload_url(upload_link->href().spec()); |
66 } else if (doc.is_hosted_document()) { | 66 } else if (doc.is_hosted_document()) { |
67 // Attach .g<something> extension to hosted documents so we can special | 67 // Attach .g<something> extension to hosted documents so we can special |
68 // case their handling in UI. | 68 // case their handling in UI. |
69 // TODO(zelidrag): Figure out better way how to pass entry info like kind | 69 // TODO(zelidrag): Figure out better way how to pass entry info like kind |
70 // to UI through the File API stack. | 70 // to UI through the File API stack. |
71 const std::string document_extension = doc.GetHostedDocumentExtension(); | 71 const std::string document_extension = doc.GetHostedDocumentExtension(); |
72 entry_proto.set_base_name( | 72 entry_proto.set_base_name( |
73 util::EscapeUtf8FileName(entry_proto.title() + document_extension)); | 73 util::EscapeUtf8FileName(entry_proto.title() + document_extension)); |
74 | 74 |
75 // We don't know the size of hosted docs and it does not matter since | 75 // We don't know the size of hosted docs and it does not matter since |
76 // is has no effect on the quota. | 76 // is has no effect on the quota. |
77 file_info->set_size(0); | 77 file_info->set_size(0); |
78 } | 78 } |
79 file_specific_info->set_content_mime_type(doc.content_mime_type()); | 79 file_specific_info->set_content_mime_type(doc.content_mime_type()); |
80 file_specific_info->set_is_hosted_document(doc.is_hosted_document()); | 80 file_specific_info->set_is_hosted_document(doc.is_hosted_document()); |
81 | 81 |
82 const Link* thumbnail_link = doc.GetLinkByType(Link::LINK_THUMBNAIL); | 82 const gdata::Link* thumbnail_link = doc.GetLinkByType( |
| 83 gdata::Link::LINK_THUMBNAIL); |
83 if (thumbnail_link) | 84 if (thumbnail_link) |
84 file_specific_info->set_thumbnail_url(thumbnail_link->href().spec()); | 85 file_specific_info->set_thumbnail_url(thumbnail_link->href().spec()); |
85 | 86 |
86 const Link* alternate_link = doc.GetLinkByType(Link::LINK_ALTERNATE); | 87 const gdata::Link* alternate_link = doc.GetLinkByType( |
| 88 gdata::Link::LINK_ALTERNATE); |
87 if (alternate_link) | 89 if (alternate_link) |
88 file_specific_info->set_alternate_url(alternate_link->href().spec()); | 90 file_specific_info->set_alternate_url(alternate_link->href().spec()); |
89 } else if (doc.is_folder()) { | 91 } else if (doc.is_folder()) { |
90 const Link* upload_link = doc.GetLinkByType( | 92 const gdata::Link* upload_link = doc.GetLinkByType( |
91 Link::LINK_RESUMABLE_CREATE_MEDIA); | 93 gdata::Link::LINK_RESUMABLE_CREATE_MEDIA); |
92 if (upload_link) | 94 if (upload_link) |
93 entry_proto.set_upload_url(upload_link->href().spec()); | 95 entry_proto.set_upload_url(upload_link->href().spec()); |
94 } else { | 96 } else { |
95 NOTREACHED() << "Unknown DocumentEntry type"; | 97 NOTREACHED() << "Unknown gdata::DocumentEntry type"; |
96 } | 98 } |
97 | 99 |
98 return entry_proto; | 100 return entry_proto; |
99 } | 101 } |
100 | 102 |
101 } // namespace gdata | 103 } // namespace drive |
OLD | NEW |