| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/file_system_provider/operations/get_metadata.h
" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h
" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "chrome/common/extensions/api/file_system_provider.h" | 10 #include "chrome/common/extensions/api/file_system_provider.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 const Params* params = value->get_metadata_success_params(); | 26 const Params* params = value->get_metadata_success_params(); |
| 27 if (!params) | 27 if (!params) |
| 28 return false; | 28 return false; |
| 29 | 29 |
| 30 if (!ValidateIDLEntryMetadata(params->metadata, root_entry)) | 30 if (!ValidateIDLEntryMetadata(params->metadata, root_entry)) |
| 31 return false; | 31 return false; |
| 32 | 32 |
| 33 output->name = params->metadata.name; | 33 output->name = params->metadata.name; |
| 34 output->is_directory = params->metadata.is_directory; | 34 output->is_directory = params->metadata.is_directory; |
| 35 output->size = static_cast<int64>(params->metadata.size); | 35 output->size = static_cast<int64>(*params->metadata.size); |
| 36 | 36 |
| 37 std::string input_modification_time; | 37 std::string input_modification_time; |
| 38 if (!params->metadata.modification_time.additional_properties.GetString( | 38 if (!params->metadata.modification_time->additional_properties.GetString( |
| 39 "value", &input_modification_time)) { | 39 "value", &input_modification_time)) { |
| 40 NOTREACHED(); | 40 NOTREACHED(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // Allow to pass invalid modification time, since there is no way to verify | 43 // Allow to pass invalid modification time, since there is no way to verify |
| 44 // it easily on any earlier stage. | 44 // it easily on any earlier stage. |
| 45 base::Time::FromString(input_modification_time.c_str(), | 45 base::Time::FromString(input_modification_time.c_str(), |
| 46 &output->modification_time); | 46 &output->modification_time); |
| 47 | 47 |
| 48 if (params->metadata.mime_type.get()) | 48 if (params->metadata.mime_type.get()) |
| 49 output->mime_type = *params->metadata.mime_type.get(); | 49 output->mime_type = *params->metadata.mime_type.get(); |
| 50 | 50 |
| 51 if (params->metadata.thumbnail.get()) | 51 if (params->metadata.thumbnail.get()) |
| 52 output->thumbnail = *params->metadata.thumbnail.get(); | 52 output->thumbnail = *params->metadata.thumbnail.get(); |
| 53 | 53 |
| 54 return true; | 54 return true; |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 bool ValidateIDLEntryMetadata( | 59 bool ValidateIDLEntryMetadata( |
| 60 const extensions::api::file_system_provider::EntryMetadata& metadata, | 60 const extensions::api::file_system_provider::EntryMetadata& metadata, |
| 61 bool root_entry) { | 61 bool root_entry) { |
| 62 using extensions::api::file_system_provider::EntryMetadata; | 62 using extensions::api::file_system_provider::EntryMetadata; |
| 63 | 63 |
| 64 if (!ValidateName(metadata.name, root_entry)) | 64 if (!ValidateName(metadata.name, root_entry)) |
| 65 return false; | 65 return false; |
| 66 | 66 |
| 67 std::string input_modification_time; | 67 std::string input_modification_time; |
| 68 if (!metadata.modification_time.additional_properties.GetString( | 68 if (metadata.modification_time.get() && |
| 69 !metadata.modification_time->additional_properties.GetString( |
| 69 "value", &input_modification_time)) { | 70 "value", &input_modification_time)) { |
| 70 return false; | 71 return false; |
| 71 } | 72 } |
| 72 | 73 |
| 73 if (metadata.thumbnail.get()) { | 74 if (metadata.thumbnail.get()) { |
| 74 // Sanity check for the thumbnail format. Note, that another, more granural | 75 // Sanity check for the thumbnail format. Note, that another, more granural |
| 75 // check is done in custom bindings. Note, this is an extra check only for | 76 // check is done in custom bindings. Note, this is an extra check only for |
| 76 // the security reasons. | 77 // the security reasons. |
| 77 const std::string expected_prefix = "data:"; | 78 const std::string expected_prefix = "data:"; |
| 78 std::string thumbnail_prefix = | 79 std::string thumbnail_prefix = |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 148 } |
| 148 | 149 |
| 149 void GetMetadata::OnError(int /* request_id */, | 150 void GetMetadata::OnError(int /* request_id */, |
| 150 scoped_ptr<RequestValue> /* result */, | 151 scoped_ptr<RequestValue> /* result */, |
| 151 base::File::Error error) { | 152 base::File::Error error) { |
| 152 callback_.Run(make_scoped_ptr<EntryMetadata>(NULL), error); | 153 callback_.Run(make_scoped_ptr<EntryMetadata>(NULL), error); |
| 153 } | 154 } |
| 154 } // namespace operations | 155 } // namespace operations |
| 155 } // namespace file_system_provider | 156 } // namespace file_system_provider |
| 156 } // namespace chromeos | 157 } // namespace chromeos |
| OLD | NEW |