Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / parsers / metadata_parser_filebase.cc
blob38a0b36884a95a1002b47734805df790c6c732dd
1 // Copyright (c) 2010 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/parsers/metadata_parser_filebase.h"
7 #include "base/file_util.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/utf_string_conversions.h"
11 FileMetadataParser::FileMetadataParser(const base::FilePath& path)
12 : MetadataParser(path),
13 path_(path) {
16 FileMetadataParser::~FileMetadataParser() {}
18 bool FileMetadataParser::Parse() {
19 std::string value;
20 int64 size;
21 if (base::GetFileSize(path_, &size)) {
22 properties_[MetadataParser::kPropertyFilesize] = base::Int64ToString(size);
24 #if defined(OS_WIN)
25 value = base::WideToUTF8(path_.BaseName().value());
26 properties_[MetadataParser::kPropertyTitle] = value;
27 #elif defined(OS_POSIX)
28 properties_[MetadataParser::kPropertyTitle] = path_.BaseName().value();
29 #endif
30 return true;
33 bool FileMetadataParser::GetProperty(const std::string& key,
34 std::string* value) {
35 PropertyMap::iterator it = properties_.find(key.c_str());
36 if (it == properties_.end()) {
37 return false;
40 *value = properties_[key.c_str()];
41 return true;
44 MetadataPropertyIterator* FileMetadataParser::GetPropertyIterator() {
45 return new FileMetadataPropertyIterator(properties_);
48 FileMetadataPropertyIterator::FileMetadataPropertyIterator(
49 PropertyMap& properties) : properties_(properties) {
50 it = properties_.begin();
53 FileMetadataPropertyIterator::~FileMetadataPropertyIterator() {}
55 bool FileMetadataPropertyIterator::GetNext(std::string* key,
56 std::string* value) {
57 if (it == properties_.end()) {
58 return false;
60 *key = it->first;
61 *value = it->second;
62 it++;
63 return true;
66 int FileMetadataPropertyIterator::Length() {
67 return properties_.size();
70 bool FileMetadataPropertyIterator::IsEnd() {
71 if (it == properties_.end()) {
72 return true;
73 } else {
74 return false;