Chromium Code Reviews| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 base::Time* last_modified_time) { | 124 base::Time* last_modified_time) { |
| 125 DCHECK(properties_values); | 125 DCHECK(properties_values); |
| 126 DCHECK(last_modified_time); | 126 DCHECK(last_modified_time); |
| 127 base::win::ScopedPropVariant last_modified_date; | 127 base::win::ScopedPropVariant last_modified_date; |
| 128 HRESULT hr = properties_values->GetValue(WPD_OBJECT_DATE_MODIFIED, | 128 HRESULT hr = properties_values->GetValue(WPD_OBJECT_DATE_MODIFIED, |
| 129 last_modified_date.Receive()); | 129 last_modified_date.Receive()); |
| 130 if (FAILED(hr)) | 130 if (FAILED(hr)) |
| 131 return false; | 131 return false; |
| 132 | 132 |
| 133 bool last_modified_time_set = (last_modified_date.get().vt == VT_DATE); | 133 bool last_modified_time_set = (last_modified_date.get().vt == VT_DATE); |
| 134 | |
| 135 // Some PTP devices don't provide an mtime. Try using the ctime instead. | |
|
Lei Zhang
2014/06/18 00:54:26
s/an mtime/a mtime/
tommycli
2014/06/18 16:28:50
I think "an" for vowel sounds?
| |
| 136 if (!last_modified_time_set) { | |
| 137 last_modified_date.Reset(); | |
| 138 HRESULT hr = properties_values->GetValue(WPD_OBJECT_DATE_CREATED, | |
| 139 last_modified_date.Receive()); | |
| 140 if (FAILED(hr)) | |
| 141 return false; | |
| 142 | |
| 143 last_modified_time_set = (last_modified_date.get().vt == VT_DATE); | |
| 144 } | |
| 145 | |
| 134 if (last_modified_time_set) { | 146 if (last_modified_time_set) { |
| 135 SYSTEMTIME system_time; | 147 SYSTEMTIME system_time; |
| 136 FILETIME file_time; | 148 FILETIME file_time; |
| 137 if (VariantTimeToSystemTime(last_modified_date.get().date, &system_time) && | 149 if (VariantTimeToSystemTime(last_modified_date.get().date, &system_time) && |
| 138 SystemTimeToFileTime(&system_time, &file_time)) { | 150 SystemTimeToFileTime(&system_time, &file_time)) { |
| 139 *last_modified_time = base::Time::FromFileTime(file_time); | 151 *last_modified_time = base::Time::FromFileTime(file_time); |
| 140 } else { | 152 } else { |
| 141 last_modified_time_set = false; | 153 last_modified_time_set = false; |
| 142 } | 154 } |
| 143 } | 155 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 154 HRESULT hr = properties_values->GetUnsignedLargeIntegerValue(WPD_OBJECT_SIZE, | 166 HRESULT hr = properties_values->GetUnsignedLargeIntegerValue(WPD_OBJECT_SIZE, |
| 155 &actual_size); | 167 &actual_size); |
| 156 bool success = SUCCEEDED(hr) && (actual_size <= kint64max); | 168 bool success = SUCCEEDED(hr) && (actual_size <= kint64max); |
| 157 if (success) | 169 if (success) |
| 158 *size = static_cast<int64>(actual_size); | 170 *size = static_cast<int64>(actual_size); |
| 159 return success; | 171 return success; |
| 160 } | 172 } |
| 161 | 173 |
| 162 // Gets the details of the object specified by the |object_id| given the media | 174 // Gets the details of the object specified by the |object_id| given the media |
| 163 // transfer protocol |device|. On success, returns true and fills in |name|, | 175 // transfer protocol |device|. On success, returns true and fills in |name|, |
| 164 // |is_directory|, |size| and |last_modified_time|. | 176 // |is_directory|, |size|. |last_modified_time| will be filled in if possible, |
| 177 // but failure to get it doesn't prevent success. | |
| 165 bool GetObjectDetails(IPortableDevice* device, | 178 bool GetObjectDetails(IPortableDevice* device, |
| 166 const base::string16 object_id, | 179 const base::string16 object_id, |
| 167 base::string16* name, | 180 base::string16* name, |
| 168 bool* is_directory, | 181 bool* is_directory, |
| 169 int64* size, | 182 int64* size, |
| 170 base::Time* last_modified_time) { | 183 base::Time* last_modified_time) { |
| 171 base::ThreadRestrictions::AssertIOAllowed(); | 184 base::ThreadRestrictions::AssertIOAllowed(); |
| 172 DCHECK(device); | 185 DCHECK(device); |
| 173 DCHECK(!object_id.empty()); | 186 DCHECK(!object_id.empty()); |
| 174 DCHECK(name); | 187 DCHECK(name); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 190 NULL, | 203 NULL, |
| 191 CLSCTX_INPROC_SERVER); | 204 CLSCTX_INPROC_SERVER); |
| 192 if (FAILED(hr)) | 205 if (FAILED(hr)) |
| 193 return false; | 206 return false; |
| 194 | 207 |
| 195 if (FAILED(properties_to_read->Add(WPD_OBJECT_CONTENT_TYPE)) || | 208 if (FAILED(properties_to_read->Add(WPD_OBJECT_CONTENT_TYPE)) || |
| 196 FAILED(properties_to_read->Add(WPD_OBJECT_FORMAT)) || | 209 FAILED(properties_to_read->Add(WPD_OBJECT_FORMAT)) || |
| 197 FAILED(properties_to_read->Add(WPD_OBJECT_ORIGINAL_FILE_NAME)) || | 210 FAILED(properties_to_read->Add(WPD_OBJECT_ORIGINAL_FILE_NAME)) || |
| 198 FAILED(properties_to_read->Add(WPD_OBJECT_NAME)) || | 211 FAILED(properties_to_read->Add(WPD_OBJECT_NAME)) || |
| 199 FAILED(properties_to_read->Add(WPD_OBJECT_DATE_MODIFIED)) || | 212 FAILED(properties_to_read->Add(WPD_OBJECT_DATE_MODIFIED)) || |
| 213 FAILED(properties_to_read->Add(WPD_OBJECT_DATE_CREATED)) || | |
| 200 FAILED(properties_to_read->Add(WPD_OBJECT_SIZE))) | 214 FAILED(properties_to_read->Add(WPD_OBJECT_SIZE))) |
| 201 return false; | 215 return false; |
| 202 | 216 |
| 203 base::win::ScopedComPtr<IPortableDeviceValues> properties_values; | 217 base::win::ScopedComPtr<IPortableDeviceValues> properties_values; |
| 204 hr = properties->GetValues(object_id.c_str(), | 218 hr = properties->GetValues(object_id.c_str(), |
| 205 properties_to_read.get(), | 219 properties_to_read.get(), |
| 206 properties_values.Receive()); | 220 properties_values.Receive()); |
| 207 if (FAILED(hr)) | 221 if (FAILED(hr)) |
| 208 return false; | 222 return false; |
| 209 | 223 |
| 210 *is_directory = IsDirectory(properties_values.get()); | 224 *is_directory = IsDirectory(properties_values.get()); |
| 211 *name = GetObjectName(properties_values.get()); | 225 *name = GetObjectName(properties_values.get()); |
| 212 if (name->empty()) | 226 if (name->empty()) |
| 213 return false; | 227 return false; |
| 214 | 228 |
| 215 if (*is_directory) { | 229 if (*is_directory) { |
| 216 // Directory entry does not have size and last modified date property key | 230 // Directory entry does not have size and last modified date property key |
| 217 // values. | 231 // values. |
| 218 *size = 0; | 232 *size = 0; |
| 219 *last_modified_time = base::Time(); | 233 *last_modified_time = base::Time(); |
| 220 return true; | 234 return true; |
| 221 } | 235 } |
| 222 return (GetObjectSize(properties_values.get(), size) && | 236 |
| 223 GetLastModifiedTime(properties_values.get(), last_modified_time)); | 237 // Try to get the last modified time, but don't fail if we can't. |
| 238 GetLastModifiedTime(properties_values.get(), last_modified_time); | |
|
Lei Zhang
2014/06/18 00:54:26
This is the only caller. Just change the return ty
tommycli
2014/06/18 16:28:50
Done. I also changed the method's flow a bit since
| |
| 239 | |
| 240 return GetObjectSize(properties_values.get(), size); | |
| 224 } | 241 } |
| 225 | 242 |
| 226 // Creates an MTP device object entry for the given |device| and |object_id|. | 243 // Creates an MTP device object entry for the given |device| and |object_id|. |
| 227 // On success, returns true and fills in |entry|. | 244 // On success, returns true and fills in |entry|. |
| 228 bool GetMTPDeviceObjectEntry(IPortableDevice* device, | 245 bool GetMTPDeviceObjectEntry(IPortableDevice* device, |
| 229 const base::string16& object_id, | 246 const base::string16& object_id, |
| 230 MTPDeviceObjectEntry* entry) { | 247 MTPDeviceObjectEntry* entry) { |
| 231 base::ThreadRestrictions::AssertIOAllowed(); | 248 base::ThreadRestrictions::AssertIOAllowed(); |
| 232 DCHECK(device); | 249 DCHECK(device); |
| 233 DCHECK(!object_id.empty()); | 250 DCHECK(!object_id.empty()); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 object_entries.empty()) | 416 object_entries.empty()) |
| 400 return base::string16(); | 417 return base::string16(); |
| 401 // TODO(thestig): This DCHECK can fail. Multiple MTP objects can have | 418 // TODO(thestig): This DCHECK can fail. Multiple MTP objects can have |
| 402 // the same name. Handle the situation gracefully. Refer to crbug.com/169930 | 419 // the same name. Handle the situation gracefully. Refer to crbug.com/169930 |
| 403 // for more details. | 420 // for more details. |
| 404 DCHECK_EQ(1U, object_entries.size()); | 421 DCHECK_EQ(1U, object_entries.size()); |
| 405 return object_entries[0].object_id; | 422 return object_entries[0].object_id; |
| 406 } | 423 } |
| 407 | 424 |
| 408 } // namespace media_transfer_protocol | 425 } // namespace media_transfer_protocol |
| OLD | NEW |