Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / chrome / browser / local_discovery / storage / privet_filesystem_attribute_cache.cc
blobd85c92a8553725477650d5774e5fc6b88ee97a5f
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.
5 #include "chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.h"
7 #include "chrome/browser/local_discovery/storage/path_util.h"
8 #include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h"
10 namespace local_discovery {
12 PrivetFileSystemAttributeCache::PrivetFileSystemAttributeCache() {}
14 PrivetFileSystemAttributeCache::~PrivetFileSystemAttributeCache() {}
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));
21 if (found != file_info_map_.end()) {
22 return &found->second;
25 return NULL;
28 void PrivetFileSystemAttributeCache::AddFileInfoFromJSON(
29 const base::FilePath& full_path,
30 const base::DictionaryValue* json) {
31 AddEntryInfoFromJSON(full_path, json);
33 const base::ListValue* entry_list;
34 if (!json->GetList(kPrivetListEntries, &entry_list))
35 return;
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;
42 std::string name;
43 if (!entry_value->GetString(kPrivetListKeyName, &name))
44 break;
46 AddEntryInfoFromJSON(full_path.AppendASCII(name), entry_value);
50 void PrivetFileSystemAttributeCache::AddEntryInfoFromJSON(
51 const base::FilePath& full_path,
52 const base::DictionaryValue* json) {
53 base::File::Info file_info;
55 std::string type;
56 int size = 0;
58 json->GetString(kPrivetListKeyType, &type);
59 json->GetInteger(kPrivetListKeySize, &size);
61 file_info.size = size;
62 file_info.is_directory = (type == kPrivetListTypeDir);
63 file_info.is_symbolic_link = false;
65 file_info_map_[NormalizeFilePath(full_path)] = file_info;
68 } // namespace local_discovery