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/local_discovery/storage/privet_filesystem_operations.h" | 5 #include "chrome/browser/local_discovery/storage/privet_filesystem_operations.h" |
6 | 6 |
7 #include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" | 7 #include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" |
8 | 8 |
9 namespace local_discovery { | 9 namespace local_discovery { |
10 | 10 |
11 PrivetFileSystemOperationFactory::PrivetFileSystemOperationFactory( | 11 PrivetFileSystemOperationFactory::PrivetFileSystemOperationFactory( |
12 content::BrowserContext* browser_context) | 12 content::BrowserContext* browser_context) |
13 : browser_context_(browser_context), weak_factory_(this) {} | 13 : browser_context_(browser_context), weak_factory_(this) {} |
14 | 14 |
15 PrivetFileSystemOperationFactory::~PrivetFileSystemOperationFactory() { | 15 PrivetFileSystemOperationFactory::~PrivetFileSystemOperationFactory() { |
16 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 16 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
17 RemoveAllOperations(); | 17 RemoveAllOperations(); |
18 } | 18 } |
19 | 19 |
20 void PrivetFileSystemOperationFactory::GetFileInfo( | 20 void PrivetFileSystemOperationFactory::GetFileInfo( |
21 const fileapi::FileSystemURL& url, | 21 const storage::FileSystemURL& url, |
22 const fileapi::AsyncFileUtil::GetFileInfoCallback& callback) { | 22 const storage::AsyncFileUtil::GetFileInfoCallback& callback) { |
23 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 23 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
24 PrivetFileSystemAsyncOperation* operation = | 24 PrivetFileSystemAsyncOperation* operation = |
25 new PrivetFileSystemDetailsOperation( | 25 new PrivetFileSystemDetailsOperation( |
26 url.path(), browser_context_, this, &attribute_cache_, callback); | 26 url.path(), browser_context_, this, &attribute_cache_, callback); |
27 async_operations_.insert(operation); | 27 async_operations_.insert(operation); |
28 operation->Start(); | 28 operation->Start(); |
29 } | 29 } |
30 | 30 |
31 void PrivetFileSystemOperationFactory::ReadDirectory( | 31 void PrivetFileSystemOperationFactory::ReadDirectory( |
32 const fileapi::FileSystemURL& url, | 32 const storage::FileSystemURL& url, |
33 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) { | 33 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) { |
34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
35 PrivetFileSystemAsyncOperation* operation = new PrivetFileSystemListOperation( | 35 PrivetFileSystemAsyncOperation* operation = new PrivetFileSystemListOperation( |
36 url.path(), browser_context_, this, &attribute_cache_, callback); | 36 url.path(), browser_context_, this, &attribute_cache_, callback); |
37 async_operations_.insert(operation); | 37 async_operations_.insert(operation); |
38 operation->Start(); | 38 operation->Start(); |
39 } | 39 } |
40 | 40 |
41 void PrivetFileSystemOperationFactory::RemoveOperation( | 41 void PrivetFileSystemOperationFactory::RemoveOperation( |
42 PrivetFileSystemAsyncOperation* operation) { | 42 PrivetFileSystemAsyncOperation* operation) { |
43 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 43 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 privet_client_ = PrivetV1HTTPClient::CreateDefault(privet_http_client.Pass()); | 102 privet_client_ = PrivetV1HTTPClient::CreateDefault(privet_http_client.Pass()); |
103 delegate_->PrivetFileSystemResolved(privet_client_.get(), | 103 delegate_->PrivetFileSystemResolved(privet_client_.get(), |
104 parsed_path_.path); | 104 parsed_path_.path); |
105 } | 105 } |
106 | 106 |
107 PrivetFileSystemListOperation::PrivetFileSystemListOperation( | 107 PrivetFileSystemListOperation::PrivetFileSystemListOperation( |
108 const base::FilePath& full_path, | 108 const base::FilePath& full_path, |
109 content::BrowserContext* browser_context, | 109 content::BrowserContext* browser_context, |
110 PrivetFileSystemAsyncOperationContainer* container, | 110 PrivetFileSystemAsyncOperationContainer* container, |
111 PrivetFileSystemAttributeCache* attribute_cache, | 111 PrivetFileSystemAttributeCache* attribute_cache, |
112 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) | 112 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) |
113 : core_(full_path, browser_context, this), | 113 : core_(full_path, browser_context, this), |
114 full_path_(full_path), | 114 full_path_(full_path), |
115 container_(container), | 115 container_(container), |
116 attribute_cache_(attribute_cache), | 116 attribute_cache_(attribute_cache), |
117 callback_(callback) { | 117 callback_(callback) { |
118 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 118 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
119 } | 119 } |
120 | 120 |
121 PrivetFileSystemListOperation::~PrivetFileSystemListOperation() { | 121 PrivetFileSystemListOperation::~PrivetFileSystemListOperation() { |
122 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 122 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
(...skipping 25 matching lines...) Expand all Loading... |
148 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 148 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
149 list_operation_.reset(); | 149 list_operation_.reset(); |
150 | 150 |
151 if (!value) { | 151 if (!value) { |
152 SignalError(); | 152 SignalError(); |
153 return; | 153 return; |
154 } | 154 } |
155 | 155 |
156 attribute_cache_->AddFileInfoFromJSON(full_path_, value); | 156 attribute_cache_->AddFileInfoFromJSON(full_path_, value); |
157 | 157 |
158 fileapi::AsyncFileUtil::EntryList entry_list; | 158 storage::AsyncFileUtil::EntryList entry_list; |
159 | 159 |
160 const base::ListValue* entries; | 160 const base::ListValue* entries; |
161 if (!value->GetList(kPrivetListEntries, &entries)) { | 161 if (!value->GetList(kPrivetListEntries, &entries)) { |
162 SignalError(); | 162 SignalError(); |
163 return; | 163 return; |
164 } | 164 } |
165 | 165 |
166 for (size_t i = 0; i < entries->GetSize(); i++) { | 166 for (size_t i = 0; i < entries->GetSize(); i++) { |
167 const base::DictionaryValue* entry_value; | 167 const base::DictionaryValue* entry_value; |
168 if (!entries->GetDictionary(i, &entry_value)) { | 168 if (!entries->GetDictionary(i, &entry_value)) { |
169 SignalError(); | 169 SignalError(); |
170 return; | 170 return; |
171 } | 171 } |
172 | 172 |
173 std::string name; | 173 std::string name; |
174 std::string type; | 174 std::string type; |
175 int size = 0; | 175 int size = 0; |
176 | 176 |
177 entry_value->GetString(kPrivetListKeyName, &name); | 177 entry_value->GetString(kPrivetListKeyName, &name); |
178 entry_value->GetString(kPrivetListKeyType, &type); | 178 entry_value->GetString(kPrivetListKeyType, &type); |
179 entry_value->GetInteger(kPrivetListKeySize, &size); | 179 entry_value->GetInteger(kPrivetListKeySize, &size); |
180 | 180 |
181 fileapi::DirectoryEntry entry( | 181 storage::DirectoryEntry entry(name, |
182 name, | 182 (type == kPrivetListTypeDir) |
183 (type == kPrivetListTypeDir) ? | 183 ? storage::DirectoryEntry::DIRECTORY |
184 fileapi::DirectoryEntry::DIRECTORY : fileapi::DirectoryEntry::FILE, | 184 : storage::DirectoryEntry::FILE, |
185 size, | 185 size, |
186 base::Time() /* TODO(noamsml) */); | 186 base::Time() /* TODO(noamsml) */); |
187 | 187 |
188 entry_list.push_back(entry); | 188 entry_list.push_back(entry); |
189 } | 189 } |
190 | 190 |
191 TriggerCallbackAndDestroy(base::File::FILE_OK, entry_list, false); | 191 TriggerCallbackAndDestroy(base::File::FILE_OK, entry_list, false); |
192 } | 192 } |
193 | 193 |
194 void PrivetFileSystemListOperation::SignalError() { | 194 void PrivetFileSystemListOperation::SignalError() { |
195 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 195 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
196 TriggerCallbackAndDestroy(base::File::FILE_ERROR_FAILED, | 196 TriggerCallbackAndDestroy(base::File::FILE_ERROR_FAILED, |
197 fileapi::AsyncFileUtil::EntryList(), | 197 storage::AsyncFileUtil::EntryList(), |
198 false); | 198 false); |
199 } | 199 } |
200 | 200 |
201 void PrivetFileSystemListOperation::TriggerCallbackAndDestroy( | 201 void PrivetFileSystemListOperation::TriggerCallbackAndDestroy( |
202 base::File::Error result, | 202 base::File::Error result, |
203 const fileapi::AsyncFileUtil::EntryList& file_list, | 203 const storage::AsyncFileUtil::EntryList& file_list, |
204 bool has_more) { | 204 bool has_more) { |
205 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 205 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
206 content::BrowserThread::PostTask( | 206 content::BrowserThread::PostTask( |
207 content::BrowserThread::IO, | 207 content::BrowserThread::IO, |
208 FROM_HERE, | 208 FROM_HERE, |
209 base::Bind(callback_, result, file_list, has_more)); | 209 base::Bind(callback_, result, file_list, has_more)); |
210 container_->RemoveOperation(this); | 210 container_->RemoveOperation(this); |
211 } | 211 } |
212 | 212 |
213 PrivetFileSystemDetailsOperation::PrivetFileSystemDetailsOperation( | 213 PrivetFileSystemDetailsOperation::PrivetFileSystemDetailsOperation( |
214 const base::FilePath& full_path, | 214 const base::FilePath& full_path, |
215 content::BrowserContext* browser_context, | 215 content::BrowserContext* browser_context, |
216 PrivetFileSystemAsyncOperationContainer* container, | 216 PrivetFileSystemAsyncOperationContainer* container, |
217 PrivetFileSystemAttributeCache* attribute_cache, | 217 PrivetFileSystemAttributeCache* attribute_cache, |
218 const fileapi::AsyncFileUtil::GetFileInfoCallback& callback) | 218 const storage::AsyncFileUtil::GetFileInfoCallback& callback) |
219 : core_(full_path, browser_context, this), | 219 : core_(full_path, browser_context, this), |
220 full_path_(full_path), | 220 full_path_(full_path), |
221 container_(container), | 221 container_(container), |
222 attribute_cache_(attribute_cache), | 222 attribute_cache_(attribute_cache), |
223 callback_(callback) { | 223 callback_(callback) { |
224 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 224 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
225 } | 225 } |
226 | 226 |
227 PrivetFileSystemDetailsOperation::~PrivetFileSystemDetailsOperation() { | 227 PrivetFileSystemDetailsOperation::~PrivetFileSystemDetailsOperation() { |
228 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 228 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 base::File::Error result, | 279 base::File::Error result, |
280 const base::File::Info& info) { | 280 const base::File::Info& info) { |
281 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 281 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
282 content::BrowserThread::PostTask(content::BrowserThread::IO, | 282 content::BrowserThread::PostTask(content::BrowserThread::IO, |
283 FROM_HERE, | 283 FROM_HERE, |
284 base::Bind(callback_, result, info)); | 284 base::Bind(callback_, result, info)); |
285 container_->RemoveOperation(this); | 285 container_->RemoveOperation(this); |
286 } | 286 } |
287 | 287 |
288 } // namespace local_discovery | 288 } // namespace local_discovery |
OLD | NEW |