OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/media_galleries/win/mtp_device_operations_util.h" | 5 #include "chrome/browser/media_galleries/win/mtp_device_operations_util.h" |
6 | 6 |
7 #include <portabledevice.h> | 7 #include <portabledevice.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // TODO(kmadhusu): |content_type| can be an image or audio or video or mixed | 95 // TODO(kmadhusu): |content_type| can be an image or audio or video or mixed |
96 // album. It is not clear whether an album is a collection of physical objects | 96 // album. It is not clear whether an album is a collection of physical objects |
97 // or virtual objects. Investigate this in detail. | 97 // or virtual objects. Investigate this in detail. |
98 | 98 |
99 // The root storage object describes its content type as | 99 // The root storage object describes its content type as |
100 // WPD_CONTENT_FUNCTIONAL_OBJECT. | 100 // WPD_CONTENT_FUNCTIONAL_OBJECT. |
101 return (content_type == WPD_CONTENT_TYPE_FOLDER || | 101 return (content_type == WPD_CONTENT_TYPE_FOLDER || |
102 content_type == WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT); | 102 content_type == WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT); |
103 } | 103 } |
104 | 104 |
105 // Returns the friendly name of the object from the property key values | 105 // Returns the name of the object from |properties_values|. If the object has |
106 // specified by the |properties_values|. | 106 // no filename, try to use a friendly name instead. e.g. with MTP storage roots. |
107 base::string16 GetObjectName(IPortableDeviceValues* properties_values, | 107 base::string16 GetObjectName(IPortableDeviceValues* properties_values) { |
108 bool is_directory) { | |
109 DCHECK(properties_values); | 108 DCHECK(properties_values); |
| 109 base::string16 result; |
110 base::win::ScopedCoMem<base::char16> buffer; | 110 base::win::ScopedCoMem<base::char16> buffer; |
111 REFPROPERTYKEY key = | 111 HRESULT hr = properties_values->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, |
112 is_directory ? WPD_OBJECT_NAME : WPD_OBJECT_ORIGINAL_FILE_NAME; | 112 &buffer); |
113 HRESULT hr = properties_values->GetStringValue(key, &buffer); | 113 if (FAILED(hr)) |
114 base::string16 result; | 114 hr = properties_values->GetStringValue(WPD_OBJECT_NAME, &buffer); |
115 if (SUCCEEDED(hr)) | 115 if (SUCCEEDED(hr)) |
116 result.assign(buffer); | 116 result.assign(buffer); |
117 return result; | 117 return result; |
118 } | 118 } |
119 | 119 |
120 // Gets the last modified time of the object from the property key values | 120 // Gets the last modified time of the object from the property key values |
121 // specified by the |properties_values|. On success, returns true and fills in | 121 // specified by the |properties_values|. On success, returns true and fills in |
122 // |last_modified_time|. | 122 // |last_modified_time|. |
123 bool GetLastModifiedTime(IPortableDeviceValues* properties_values, | 123 bool GetLastModifiedTime(IPortableDeviceValues* properties_values, |
124 base::Time* last_modified_time) { | 124 base::Time* last_modified_time) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 return false; | 201 return false; |
202 | 202 |
203 base::win::ScopedComPtr<IPortableDeviceValues> properties_values; | 203 base::win::ScopedComPtr<IPortableDeviceValues> properties_values; |
204 hr = properties->GetValues(object_id.c_str(), | 204 hr = properties->GetValues(object_id.c_str(), |
205 properties_to_read.get(), | 205 properties_to_read.get(), |
206 properties_values.Receive()); | 206 properties_values.Receive()); |
207 if (FAILED(hr)) | 207 if (FAILED(hr)) |
208 return false; | 208 return false; |
209 | 209 |
210 *is_directory = IsDirectory(properties_values.get()); | 210 *is_directory = IsDirectory(properties_values.get()); |
211 *name = GetObjectName(properties_values.get(), *is_directory); | 211 *name = GetObjectName(properties_values.get()); |
212 if (name->empty()) | 212 if (name->empty()) |
213 return false; | 213 return false; |
214 | 214 |
215 if (*is_directory) { | 215 if (*is_directory) { |
216 // Directory entry does not have size and last modified date property key | 216 // Directory entry does not have size and last modified date property key |
217 // values. | 217 // values. |
218 *size = 0; | 218 *size = 0; |
219 *last_modified_time = base::Time(); | 219 *last_modified_time = base::Time(); |
220 return true; | 220 return true; |
221 } | 221 } |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 object_entries.empty()) | 399 object_entries.empty()) |
400 return base::string16(); | 400 return base::string16(); |
401 // TODO(thestig): This DCHECK can fail. Multiple MTP objects can have | 401 // TODO(thestig): This DCHECK can fail. Multiple MTP objects can have |
402 // the same name. Handle the situation gracefully. Refer to crbug.com/169930 | 402 // the same name. Handle the situation gracefully. Refer to crbug.com/169930 |
403 // for more details. | 403 // for more details. |
404 DCHECK_EQ(1U, object_entries.size()); | 404 DCHECK_EQ(1U, object_entries.size()); |
405 return object_entries[0].object_id; | 405 return object_entries[0].object_id; |
406 } | 406 } |
407 | 407 |
408 } // namespace media_transfer_protocol | 408 } // namespace media_transfer_protocol |
OLD | NEW |