OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/gdata/gdata_directory_service.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_directory_service.h" |
6 | 6 |
7 #include <leveldb/db.h> | 7 #include <leveldb/db.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 GDataEntry* GDataDirectoryService::FindEntryByPathSync( | 293 GDataEntry* GDataDirectoryService::FindEntryByPathSync( |
294 const FilePath& file_path) { | 294 const FilePath& file_path) { |
295 if (file_path == root_->GetFilePath()) | 295 if (file_path == root_->GetFilePath()) |
296 return root_.get(); | 296 return root_.get(); |
297 | 297 |
298 std::vector<FilePath::StringType> components; | 298 std::vector<FilePath::StringType> components; |
299 file_path.GetComponents(&components); | 299 file_path.GetComponents(&components); |
300 GDataDirectory* current_dir = root_.get(); | 300 GDataDirectory* current_dir = root_.get(); |
301 | 301 |
302 for (size_t i = 1; i < components.size() && current_dir; ++i) { | 302 for (size_t i = 1; i < components.size() && current_dir; ++i) { |
303 GDataEntry* entry = current_dir->FindChild(components[i]); | 303 std::string resource_id = current_dir->FindChild(components[i]); |
304 if (!entry) | 304 if (resource_id.empty()) |
305 return NULL; | 305 return NULL; |
306 | 306 |
| 307 GDataEntry* entry = GetEntryByResourceId(resource_id); |
| 308 DCHECK(entry); |
| 309 |
307 if (i == components.size() - 1) // Last component. | 310 if (i == components.size() - 1) // Last component. |
308 return entry; | 311 return entry; |
309 else | 312 else |
310 current_dir = entry->AsGDataDirectory(); | 313 current_dir = entry->AsGDataDirectory(); |
311 } | 314 } |
312 return NULL; | 315 return NULL; |
313 } | 316 } |
314 | 317 |
315 GDataEntry* GDataDirectoryService::GetEntryByResourceId( | 318 GDataEntry* GDataDirectoryService::GetEntryByResourceId( |
316 const std::string& resource) { | 319 const std::string& resource_id) { |
317 // GDataFileSystem has already locked. | 320 DCHECK(!resource_id.empty()); |
318 ResourceMap::const_iterator iter = resource_map_.find(resource); | 321 ResourceMap::const_iterator iter = resource_map_.find(resource_id); |
319 return iter == resource_map_.end() ? NULL : iter->second; | 322 return iter == resource_map_.end() ? NULL : iter->second; |
320 } | 323 } |
321 | 324 |
322 void GDataDirectoryService::GetEntryByResourceIdAsync( | 325 void GDataDirectoryService::GetEntryByResourceIdAsync( |
323 const std::string& resource_id, | 326 const std::string& resource_id, |
324 const GetEntryByResourceIdCallback& callback) { | 327 const GetEntryByResourceIdCallback& callback) { |
325 GDataEntry* entry = GetEntryByResourceId(resource_id); | 328 GDataEntry* entry = GetEntryByResourceId(resource_id); |
326 callback.Run(entry); | 329 callback.Run(entry); |
327 } | 330 } |
328 | 331 |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 DCHECK(result.get()); | 723 DCHECK(result.get()); |
721 | 724 |
722 result->second.path = second_path; | 725 result->second.path = second_path; |
723 result->second.error = error; | 726 result->second.error = error; |
724 result->second.proto = entry_proto.Pass(); | 727 result->second.proto = entry_proto.Pass(); |
725 | 728 |
726 callback.Run(result.Pass()); | 729 callback.Run(result.Pass()); |
727 } | 730 } |
728 | 731 |
729 } // namespace gdata | 732 } // namespace gdata |
OLD | NEW |