Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h " | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/memory/linked_ptr.h" | |
|
kinaba
2014/04/30 07:55:03
is this used?
mtomasz
2014/04/30 09:18:24
Nope. Done.
| |
| 10 #include "chrome/common/extensions/api/file_system_provider.h" | |
| 11 #include "chrome/common/extensions/api/file_system_provider_internal.h" | |
| 12 | |
| 13 namespace chromeos { | |
| 14 namespace file_system_provider { | |
| 15 namespace operations { | |
| 16 namespace { | |
| 17 | |
| 18 // Convert |value| into |output|. If parsing fails, then returns false. | |
| 19 bool ConvertRequestValueToFileInfo(scoped_ptr<RequestValue> value, | |
| 20 base::File::Info* output) { | |
| 21 using extensions::api::file_system_provider::EntryMetadata; | |
| 22 using extensions::api::file_system_provider_internal:: | |
| 23 GetMetadataRequestedSuccess::Params; | |
| 24 | |
| 25 const Params* params = value->get_metadata_success_params(); | |
| 26 if (!params) | |
| 27 return false; | |
| 28 | |
| 29 output->is_directory = params->metadata.is_directory; | |
| 30 output->size = static_cast<int64>(params->metadata.size); | |
| 31 output->is_symbolic_link = false; // Not supported. | |
| 32 | |
| 33 std::string input_modification_time; | |
| 34 if (!params->metadata.modification_time.additional_properties.GetString( | |
| 35 "value", &input_modification_time)) { | |
| 36 return false; | |
| 37 } | |
| 38 if (!base::Time::FromString(input_modification_time.c_str(), | |
| 39 &output->last_modified)) { | |
| 40 return false; | |
| 41 } | |
| 42 | |
| 43 return true; | |
| 44 } | |
| 45 | |
| 46 } // namespace | |
| 47 | |
| 48 GetMetadata::GetMetadata( | |
| 49 extensions::EventRouter* event_router, | |
| 50 const ProvidedFileSystemInfo& file_system_info, | |
| 51 const base::FilePath& directory_path, | |
| 52 const fileapi::AsyncFileUtil::GetFileInfoCallback& callback) | |
| 53 : Operation(event_router, file_system_info), | |
| 54 directory_path_(directory_path), | |
| 55 callback_(callback) { | |
| 56 } | |
| 57 | |
| 58 GetMetadata::~GetMetadata() { | |
| 59 } | |
| 60 | |
| 61 bool GetMetadata::Execute(int request_id) { | |
| 62 scoped_ptr<base::ListValue> values(new base::ListValue); | |
| 63 values->AppendString(directory_path_.AsUTF8Unsafe()); | |
| 64 return SendEvent( | |
| 65 request_id, | |
| 66 extensions::api::file_system_provider::OnGetMetadataRequested::kEventName, | |
| 67 values.Pass()); | |
| 68 } | |
| 69 | |
| 70 void GetMetadata::OnSuccess(int /* request_id */, | |
| 71 scoped_ptr<RequestValue> result, | |
| 72 bool has_next) { | |
| 73 base::File::Info file_info; | |
| 74 const bool convert_result = | |
| 75 ConvertRequestValueToFileInfo(result.Pass(), &file_info); | |
| 76 DCHECK(convert_result); | |
| 77 callback_.Run(base::File::FILE_OK, file_info); | |
| 78 } | |
| 79 | |
| 80 void GetMetadata::OnError(int /* request_id */, base::File::Error error) { | |
| 81 callback_.Run(error, base::File::Info()); | |
| 82 } | |
| 83 | |
| 84 } // namespace operations | |
| 85 } // namespace file_system_provider | |
| 86 } // namespace chromeos | |
| OLD | NEW |