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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 87 } |
88 | 88 |
89 return true; | 89 return true; |
90 } | 90 } |
91 | 91 |
92 bool ValidateName(const std::string& name, bool root_entry) { | 92 bool ValidateName(const std::string& name, bool root_entry) { |
93 if (root_entry) | 93 if (root_entry) |
94 return name.empty(); | 94 return name.empty(); |
95 return !name.empty() && name.find('/') == std::string::npos; | 95 return !name.empty() && name.find('/') == std::string::npos; |
96 } | 96 } |
97 | 97 template <int source> |
98 GetMetadata::GetMetadata( | 98 GetMetadata<source>::GetMetadata( |
99 extensions::EventRouter* event_router, | 99 typename Operation<source>::EventRouterType* event_router, |
100 const ProvidedFileSystemInfo& file_system_info, | 100 const ProvidedFileSystemInfo& file_system_info, |
101 const base::FilePath& entry_path, | 101 const base::FilePath& entry_path, |
102 ProvidedFileSystemInterface::MetadataFieldMask fields, | 102 ProvidedFileSystemInterface::MetadataFieldMask fields, |
103 const ProvidedFileSystemInterface::GetMetadataCallback& callback) | 103 const ProvidedFileSystemInterface::GetMetadataCallback& callback) |
104 : Operation(event_router, file_system_info), | 104 : Operation<source>(event_router, file_system_info), |
105 entry_path_(entry_path), | 105 entry_path_(entry_path), |
106 fields_(fields), | 106 fields_(fields), |
107 callback_(callback) { | 107 callback_(callback) { |
108 } | 108 } |
109 | 109 |
110 GetMetadata::~GetMetadata() { | 110 template <int source> |
| 111 GetMetadata<source>::~GetMetadata() { |
111 } | 112 } |
112 | 113 |
113 bool GetMetadata::Execute(int request_id) { | 114 template <int source> |
| 115 bool GetMetadata<source>::Execute(int request_id) { |
114 using extensions::api::file_system_provider::GetMetadataRequestedOptions; | 116 using extensions::api::file_system_provider::GetMetadataRequestedOptions; |
115 | 117 |
116 GetMetadataRequestedOptions options; | 118 GetMetadataRequestedOptions options; |
117 options.file_system_id = file_system_info_.file_system_id(); | 119 options.file_system_id = this->file_system_info_.file_system_id(); |
118 options.request_id = request_id; | 120 options.request_id = request_id; |
119 options.entry_path = entry_path_.AsUTF8Unsafe(); | 121 options.entry_path = entry_path_.AsUTF8Unsafe(); |
120 options.thumbnail = | 122 options.thumbnail = |
121 fields_ & ProvidedFileSystemInterface::METADATA_FIELD_THUMBNAIL; | 123 fields_ & ProvidedFileSystemInterface::METADATA_FIELD_THUMBNAIL; |
122 | 124 |
123 return SendEvent( | 125 return this->SendEvent( |
124 request_id, | 126 request_id, |
125 extensions::api::file_system_provider::OnGetMetadataRequested::kEventName, | 127 extensions::api::file_system_provider::OnGetMetadataRequested::kEventName, |
126 extensions::api::file_system_provider::OnGetMetadataRequested::Create( | 128 extensions::api::file_system_provider::OnGetMetadataRequested::Create( |
127 options)); | 129 options)); |
128 } | 130 } |
129 | 131 |
130 void GetMetadata::OnSuccess(int /* request_id */, | 132 template <int source> |
131 scoped_ptr<RequestValue> result, | 133 void GetMetadata<source>::OnSuccess(int /* request_id */, |
132 bool has_more) { | 134 scoped_ptr<RequestValue> result, |
| 135 bool has_more) { |
133 scoped_ptr<EntryMetadata> metadata(new EntryMetadata); | 136 scoped_ptr<EntryMetadata> metadata(new EntryMetadata); |
134 const bool convert_result = ConvertRequestValueToFileInfo( | 137 const bool convert_result = ConvertRequestValueToFileInfo( |
135 result.Pass(), entry_path_.AsUTF8Unsafe() == FILE_PATH_LITERAL("/"), | 138 result.Pass(), entry_path_.AsUTF8Unsafe() == FILE_PATH_LITERAL("/"), |
136 metadata.get()); | 139 metadata.get()); |
137 | 140 |
138 if (!convert_result) { | 141 if (!convert_result) { |
139 LOG(ERROR) << "Failed to parse a response for the get metadata operation."; | 142 LOG(ERROR) << "Failed to parse a response for the get metadata operation."; |
140 callback_.Run(make_scoped_ptr<EntryMetadata>(NULL), | 143 callback_.Run(make_scoped_ptr<EntryMetadata>(NULL), |
141 base::File::FILE_ERROR_IO); | 144 base::File::FILE_ERROR_IO); |
142 return; | 145 return; |
143 } | 146 } |
144 | 147 |
145 callback_.Run(metadata.Pass(), base::File::FILE_OK); | 148 callback_.Run(metadata.Pass(), base::File::FILE_OK); |
146 } | 149 } |
147 | 150 |
148 void GetMetadata::OnError(int /* request_id */, | 151 template <int source> |
149 scoped_ptr<RequestValue> /* result */, | 152 void GetMetadata<source>::OnError(int /* request_id */, |
150 base::File::Error error) { | 153 scoped_ptr<RequestValue> /* result */, |
| 154 base::File::Error error) { |
151 callback_.Run(make_scoped_ptr<EntryMetadata>(NULL), error); | 155 callback_.Run(make_scoped_ptr<EntryMetadata>(NULL), error); |
152 } | 156 } |
| 157 |
| 158 template class GetMetadata<Source_Type::extension>; |
| 159 template class GetMetadata<Source_Type::plugin>; |
| 160 |
153 } // namespace operations | 161 } // namespace operations |
154 } // namespace file_system_provider | 162 } // namespace file_system_provider |
155 } // namespace chromeos | 163 } // namespace chromeos |
OLD | NEW |