| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 entry_proto.set_base_name(util::EscapeUtf8FileName(entry_proto.title())); | 45 entry_proto.set_base_name(util::EscapeUtf8FileName(entry_proto.title())); |
| 46 | 46 |
| 47 entry_proto.set_resource_id(entry.resource_id()); | 47 entry_proto.set_resource_id(entry.resource_id()); |
| 48 entry_proto.set_download_url(entry.download_url().spec()); | 48 entry_proto.set_download_url(entry.download_url().spec()); |
| 49 | 49 |
| 50 const google_apis::Link* edit_link = | 50 const google_apis::Link* edit_link = |
| 51 entry.GetLinkByType(google_apis::Link::LINK_EDIT); | 51 entry.GetLinkByType(google_apis::Link::LINK_EDIT); |
| 52 if (edit_link) | 52 if (edit_link) |
| 53 entry_proto.set_edit_url(edit_link->href().spec()); | 53 entry_proto.set_edit_url(edit_link->href().spec()); |
| 54 | 54 |
| 55 // Sets parent Resource ID. On drive.google.com, a file can have multiple |
| 56 // parents or no parent, but we are forcing a tree-shaped structure (i.e. no |
| 57 // multi-parent or zero-parent entries). Therefore the first found "parent" is |
| 58 // used for the entry and if the entry has no parent, we assign a special ID |
| 59 // which represents no-parent entries. Tracked in http://crbug.com/158904. |
| 55 const google_apis::Link* parent_link = | 60 const google_apis::Link* parent_link = |
| 56 entry.GetLinkByType(google_apis::Link::LINK_PARENT); | 61 entry.GetLinkByType(google_apis::Link::LINK_PARENT); |
| 57 if (parent_link) { | 62 if (parent_link) { |
| 58 // TODO(haruki): Apply mapping from an empty parent to special dummy | |
| 59 // directory. See http://crbug.com/174233. Until we implement it, | |
| 60 // ChangeListProcessor ignores such "no parent" entries. | |
| 61 entry_proto.set_parent_resource_id( | 63 entry_proto.set_parent_resource_id( |
| 62 util::ExtractResourceIdFromUrl(parent_link->href())); | 64 util::ExtractResourceIdFromUrl(parent_link->href())); |
| 63 } | 65 } |
| 66 // Apply mapping from an empty parent to the special dummy directory. |
| 67 if (entry_proto.parent_resource_id().empty()) |
| 68 entry_proto.set_parent_resource_id(util::kDriveOtherDirSpecialResourceId); |
| 64 | 69 |
| 65 entry_proto.set_deleted(entry.deleted()); | 70 entry_proto.set_deleted(entry.deleted()); |
| 66 entry_proto.set_shared_with_me(HasSharedWithMeLabel(entry)); | 71 entry_proto.set_shared_with_me(HasSharedWithMeLabel(entry)); |
| 67 | 72 |
| 68 PlatformFileInfoProto* file_info = entry_proto.mutable_file_info(); | 73 PlatformFileInfoProto* file_info = entry_proto.mutable_file_info(); |
| 69 | 74 |
| 70 file_info->set_last_modified(entry.updated_time().ToInternalValue()); | 75 file_info->set_last_modified(entry.updated_time().ToInternalValue()); |
| 71 // If the file has never been viewed (last_viewed_time().is_null() == true), | 76 // If the file has never been viewed (last_viewed_time().is_null() == true), |
| 72 // then we will set the last_accessed field in the protocol buffer to 0. | 77 // then we will set the last_accessed field in the protocol buffer to 0. |
| 73 file_info->set_last_accessed(entry.last_viewed_time().ToInternalValue()); | 78 file_info->set_last_accessed(entry.last_viewed_time().ToInternalValue()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 entry_proto.set_upload_url(upload_link->href().spec()); | 131 entry_proto.set_upload_url(upload_link->href().spec()); |
| 127 } else { | 132 } else { |
| 128 // Some resource entries don't map into files (i.e. sites). | 133 // Some resource entries don't map into files (i.e. sites). |
| 129 return DriveEntryProto(); | 134 return DriveEntryProto(); |
| 130 } | 135 } |
| 131 | 136 |
| 132 return entry_proto; | 137 return entry_proto; |
| 133 } | 138 } |
| 134 | 139 |
| 135 } // namespace drive | 140 } // namespace drive |
| OLD | NEW |