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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.h" 6 7 #include "chrome/browser/local_discovery/storage/path_util.h" 8 #include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" 9 10 namespace local_discovery { 11 12 PrivetFileSystemAttributeCache::PrivetFileSystemAttributeCache() {} 13 14 PrivetFileSystemAttributeCache::~PrivetFileSystemAttributeCache() {} 15 16 const base::File::Info* PrivetFileSystemAttributeCache::GetFileInfo( 17 const base::FilePath& full_path) { 18 FileInfoMap::iterator found = 19 file_info_map_.find(NormalizeFilePath(full_path)); 20 21 if (found != file_info_map_.end()) { 22 return &found->second; 23 } 24 25 return NULL; 26 } 27 28 void PrivetFileSystemAttributeCache::AddFileInfoFromJSON( 29 const base::FilePath& full_path, 30 const base::DictionaryValue* json) { 31 AddEntryInfoFromJSON(full_path, json); 32 33 const base::ListValue* entry_list; 34 if (!json->GetList(kPrivetListEntries, &entry_list)) 35 return; 36 37 for (size_t i = 0; i < entry_list->GetSize(); i++) { 38 const base::DictionaryValue* entry_value; 39 if (!entry_list->GetDictionary(i, &entry_value)) 40 break; 41 42 std::string name; 43 if (!entry_value->GetString(kPrivetListKeyName, &name)) 44 break; 45 46 AddEntryInfoFromJSON(full_path.AppendASCII(name), entry_value); 47 } 48 } 49 50 void PrivetFileSystemAttributeCache::AddEntryInfoFromJSON( 51 const base::FilePath& full_path, 52 const base::DictionaryValue* json) { 53 base::File::Info file_info; 54 55 std::string type; 56 int size = 0; 57 58 json->GetString(kPrivetListKeyType, &type); 59 json->GetInteger(kPrivetListKeySize, &size); 60 61 file_info.size = size; 62 file_info.is_directory = (type == kPrivetListTypeDir); 63 file_info.is_symbolic_link = false; 64 65 file_info_map_[NormalizeFilePath(full_path)] = file_info; 66 } 67 68 } // namespace local_discovery 69