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/read_directory
.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/read_directory
.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "chrome/common/extensions/api/file_system_provider.h" | 10 #include "chrome/common/extensions/api/file_system_provider.h" |
11 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 11 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
12 | 12 |
13 namespace chromeos { | 13 namespace chromeos { |
14 namespace file_system_provider { | 14 namespace file_system_provider { |
15 namespace operations { | 15 namespace operations { |
16 namespace { | 16 namespace { |
17 | 17 |
18 // Convert |input| into |output|. If parsing fails, then returns false. | 18 // Convert |input| into |output|. If parsing fails, then returns false. |
19 bool ConvertRequestValueToEntryList(scoped_ptr<RequestValue> value, | 19 bool ConvertRequestValueToEntryList(scoped_ptr<RequestValue> value, |
20 fileapi::AsyncFileUtil::EntryList* output) { | 20 storage::AsyncFileUtil::EntryList* output) { |
21 using extensions::api::file_system_provider::EntryMetadata; | 21 using extensions::api::file_system_provider::EntryMetadata; |
22 using extensions::api::file_system_provider_internal:: | 22 using extensions::api::file_system_provider_internal:: |
23 ReadDirectoryRequestedSuccess::Params; | 23 ReadDirectoryRequestedSuccess::Params; |
24 | 24 |
25 const Params* params = value->read_directory_success_params(); | 25 const Params* params = value->read_directory_success_params(); |
26 if (!params) | 26 if (!params) |
27 return false; | 27 return false; |
28 | 28 |
29 for (size_t i = 0; i < params->entries.size(); ++i) { | 29 for (size_t i = 0; i < params->entries.size(); ++i) { |
30 const linked_ptr<EntryMetadata> entry_metadata = params->entries[i]; | 30 const linked_ptr<EntryMetadata> entry_metadata = params->entries[i]; |
31 | 31 |
32 fileapi::DirectoryEntry output_entry; | 32 storage::DirectoryEntry output_entry; |
33 output_entry.is_directory = entry_metadata->is_directory; | 33 output_entry.is_directory = entry_metadata->is_directory; |
34 output_entry.name = entry_metadata->name; | 34 output_entry.name = entry_metadata->name; |
35 output_entry.size = static_cast<int64>(entry_metadata->size); | 35 output_entry.size = static_cast<int64>(entry_metadata->size); |
36 | 36 |
37 std::string input_modification_time; | 37 std::string input_modification_time; |
38 if (!entry_metadata->modification_time.additional_properties.GetString( | 38 if (!entry_metadata->modification_time.additional_properties.GetString( |
39 "value", &input_modification_time)) { | 39 "value", &input_modification_time)) { |
40 return false; | 40 return false; |
41 } | 41 } |
42 if (!base::Time::FromString(input_modification_time.c_str(), | 42 if (!base::Time::FromString(input_modification_time.c_str(), |
43 &output_entry.last_modified_time)) { | 43 &output_entry.last_modified_time)) { |
44 return false; | 44 return false; |
45 } | 45 } |
46 | 46 |
47 output->push_back(output_entry); | 47 output->push_back(output_entry); |
48 } | 48 } |
49 | 49 |
50 return true; | 50 return true; |
51 } | 51 } |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 ReadDirectory::ReadDirectory( | 55 ReadDirectory::ReadDirectory( |
56 extensions::EventRouter* event_router, | 56 extensions::EventRouter* event_router, |
57 const ProvidedFileSystemInfo& file_system_info, | 57 const ProvidedFileSystemInfo& file_system_info, |
58 const base::FilePath& directory_path, | 58 const base::FilePath& directory_path, |
59 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) | 59 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) |
60 : Operation(event_router, file_system_info), | 60 : Operation(event_router, file_system_info), |
61 directory_path_(directory_path), | 61 directory_path_(directory_path), |
62 callback_(callback) { | 62 callback_(callback) { |
63 } | 63 } |
64 | 64 |
65 ReadDirectory::~ReadDirectory() { | 65 ReadDirectory::~ReadDirectory() { |
66 } | 66 } |
67 | 67 |
68 bool ReadDirectory::Execute(int request_id) { | 68 bool ReadDirectory::Execute(int request_id) { |
69 scoped_ptr<base::DictionaryValue> values(new base::DictionaryValue); | 69 scoped_ptr<base::DictionaryValue> values(new base::DictionaryValue); |
70 values->SetString("directoryPath", directory_path_.AsUTF8Unsafe()); | 70 values->SetString("directoryPath", directory_path_.AsUTF8Unsafe()); |
71 return SendEvent(request_id, | 71 return SendEvent(request_id, |
72 extensions::api::file_system_provider:: | 72 extensions::api::file_system_provider:: |
73 OnReadDirectoryRequested::kEventName, | 73 OnReadDirectoryRequested::kEventName, |
74 values.Pass()); | 74 values.Pass()); |
75 } | 75 } |
76 | 76 |
77 void ReadDirectory::OnSuccess(int /* request_id */, | 77 void ReadDirectory::OnSuccess(int /* request_id */, |
78 scoped_ptr<RequestValue> result, | 78 scoped_ptr<RequestValue> result, |
79 bool has_more) { | 79 bool has_more) { |
80 fileapi::AsyncFileUtil::EntryList entry_list; | 80 storage::AsyncFileUtil::EntryList entry_list; |
81 const bool convert_result = | 81 const bool convert_result = |
82 ConvertRequestValueToEntryList(result.Pass(), &entry_list); | 82 ConvertRequestValueToEntryList(result.Pass(), &entry_list); |
83 | 83 |
84 if (!convert_result) { | 84 if (!convert_result) { |
85 LOG(ERROR) | 85 LOG(ERROR) |
86 << "Failed to parse a response for the read directory operation."; | 86 << "Failed to parse a response for the read directory operation."; |
87 callback_.Run(base::File::FILE_ERROR_IO, | 87 callback_.Run(base::File::FILE_ERROR_IO, |
88 fileapi::AsyncFileUtil::EntryList(), | 88 storage::AsyncFileUtil::EntryList(), |
89 false /* has_more */); | 89 false /* has_more */); |
90 return; | 90 return; |
91 } | 91 } |
92 | 92 |
93 callback_.Run(base::File::FILE_OK, entry_list, has_more); | 93 callback_.Run(base::File::FILE_OK, entry_list, has_more); |
94 } | 94 } |
95 | 95 |
96 void ReadDirectory::OnError(int /* request_id */, | 96 void ReadDirectory::OnError(int /* request_id */, |
97 scoped_ptr<RequestValue> /* result */, | 97 scoped_ptr<RequestValue> /* result */, |
98 base::File::Error error) { | 98 base::File::Error error) { |
99 callback_.Run( | 99 callback_.Run( |
100 error, fileapi::AsyncFileUtil::EntryList(), false /* has_more */); | 100 error, storage::AsyncFileUtil::EntryList(), false /* has_more */); |
101 } | 101 } |
102 | 102 |
103 } // namespace operations | 103 } // namespace operations |
104 } // namespace file_system_provider | 104 } // namespace file_system_provider |
105 } // namespace chromeos | 105 } // namespace chromeos |
OLD | NEW |