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/browser/chromeos/file_system_provider/operations/get_metadata.h
" | 10 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h
" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } | 48 } |
49 | 49 |
50 output->push_back(output_entry); | 50 output->push_back(output_entry); |
51 } | 51 } |
52 | 52 |
53 return true; | 53 return true; |
54 } | 54 } |
55 | 55 |
56 } // namespace | 56 } // namespace |
57 | 57 |
58 ReadDirectory::ReadDirectory( | 58 template <int source> |
59 extensions::EventRouter* event_router, | 59 ReadDirectory<source>::ReadDirectory( |
| 60 typename Operation<source>::EventRouterType* event_router, |
60 const ProvidedFileSystemInfo& file_system_info, | 61 const ProvidedFileSystemInfo& file_system_info, |
61 const base::FilePath& directory_path, | 62 const base::FilePath& directory_path, |
62 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) | 63 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) |
63 : Operation(event_router, file_system_info), | 64 : Operation<source>(event_router, file_system_info), |
64 directory_path_(directory_path), | 65 directory_path_(directory_path), |
65 callback_(callback) { | 66 callback_(callback) { |
66 } | 67 } |
67 | 68 |
68 ReadDirectory::~ReadDirectory() { | 69 template <int source> |
| 70 ReadDirectory<source>::~ReadDirectory() { |
69 } | 71 } |
70 | 72 |
71 bool ReadDirectory::Execute(int request_id) { | 73 template <int source> |
| 74 bool ReadDirectory<source>::Execute(int request_id) { |
72 using extensions::api::file_system_provider::ReadDirectoryRequestedOptions; | 75 using extensions::api::file_system_provider::ReadDirectoryRequestedOptions; |
73 | 76 |
74 ReadDirectoryRequestedOptions options; | 77 ReadDirectoryRequestedOptions options; |
75 options.file_system_id = file_system_info_.file_system_id(); | 78 options.file_system_id = this->file_system_info_.file_system_id(); |
76 options.request_id = request_id; | 79 options.request_id = request_id; |
77 options.directory_path = directory_path_.AsUTF8Unsafe(); | 80 options.directory_path = directory_path_.AsUTF8Unsafe(); |
78 | 81 |
79 return SendEvent( | 82 return this->SendEvent( |
80 request_id, | 83 request_id, extensions::api::file_system_provider:: |
81 extensions::api::file_system_provider::OnReadDirectoryRequested:: | 84 OnReadDirectoryRequested::kEventName, |
82 kEventName, | |
83 extensions::api::file_system_provider::OnReadDirectoryRequested::Create( | 85 extensions::api::file_system_provider::OnReadDirectoryRequested::Create( |
84 options)); | 86 options)); |
85 } | 87 } |
86 | 88 |
87 void ReadDirectory::OnSuccess(int /* request_id */, | 89 template <int source> |
88 scoped_ptr<RequestValue> result, | 90 void ReadDirectory<source>::OnSuccess(int /* request_id */, |
89 bool has_more) { | 91 scoped_ptr<RequestValue> result, |
| 92 bool has_more) { |
90 storage::AsyncFileUtil::EntryList entry_list; | 93 storage::AsyncFileUtil::EntryList entry_list; |
91 const bool convert_result = | 94 const bool convert_result = |
92 ConvertRequestValueToEntryList(result.Pass(), &entry_list); | 95 ConvertRequestValueToEntryList(result.Pass(), &entry_list); |
93 | 96 |
94 if (!convert_result) { | 97 if (!convert_result) { |
95 LOG(ERROR) | 98 LOG(ERROR) |
96 << "Failed to parse a response for the read directory operation."; | 99 << "Failed to parse a response for the read directory operation."; |
97 callback_.Run(base::File::FILE_ERROR_IO, | 100 callback_.Run(base::File::FILE_ERROR_IO, |
98 storage::AsyncFileUtil::EntryList(), | 101 storage::AsyncFileUtil::EntryList(), |
99 false /* has_more */); | 102 false /* has_more */); |
100 return; | 103 return; |
101 } | 104 } |
102 | 105 |
103 callback_.Run(base::File::FILE_OK, entry_list, has_more); | 106 callback_.Run(base::File::FILE_OK, entry_list, has_more); |
104 } | 107 } |
105 | 108 |
106 void ReadDirectory::OnError(int /* request_id */, | 109 template <int source> |
107 scoped_ptr<RequestValue> /* result */, | 110 void ReadDirectory<source>::OnError(int /* request_id */, |
108 base::File::Error error) { | 111 scoped_ptr<RequestValue> /* result */, |
109 callback_.Run( | 112 base::File::Error error) { |
110 error, storage::AsyncFileUtil::EntryList(), false /* has_more */); | 113 callback_.Run(error, storage::AsyncFileUtil::EntryList(), |
| 114 false /* has_more */); |
111 } | 115 } |
112 | 116 |
| 117 template class ReadDirectory<Source_Type::extension>; |
| 118 template class ReadDirectory<Source_Type::plugin>; |
| 119 |
113 } // namespace operations | 120 } // namespace operations |
114 } // namespace file_system_provider | 121 } // namespace file_system_provider |
115 } // namespace chromeos | 122 } // namespace chromeos |
OLD | NEW |