blob: f428fa3ee3c4c8f034ffd0d636e4580fac464334 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/parsers/metadata_parser_manager.h"
#include "base/logging.h"
#include "base/file_util.h"
#include "base/singleton.h"
#include "base/stl_util-inl.h"
#include "build/build_config.h"
#include "chrome/browser/parsers/metadata_parser_factory.h"
#include "chrome/browser/parsers/metadata_parser_jpeg_factory.h"
static const int kAmountToRead = 256;
// Gets the singleton
MetadataParserManager* MetadataParserManager::Get() {
// Uses the LeakySingletonTrait because cleanup is optional.
return
Singleton<MetadataParserManager,
LeakySingletonTraits<MetadataParserManager> >::get();
}
bool MetadataParserManager::RegisterParserFactory(
MetadataParserFactory* parser) {
factories_.push_back(parser);
return true;
}
MetadataParserManager::MetadataParserManager() {
MetadataParserJpegFactory *factory = new MetadataParserJpegFactory();
RegisterParserFactory(factory);
}
MetadataParserManager::~MetadataParserManager() {}
MetadataParser* MetadataParserManager::GetParserForFile(const FilePath& path) {
char buffer[kAmountToRead];
int amount_read = 0;
DLOG(ERROR) << path.value();
amount_read = file_util::ReadFile(path, buffer, sizeof(buffer));
if (amount_read <= 0) {
DLOG(ERROR) << "Unable to read file";
return NULL;
}
for (size_t x = 0; x < factories_.size(); ++x) {
if (factories_[x]->CanParse(path, buffer, amount_read)) {
return factories_[x]->CreateParser(path);
}
}
return NULL;
}
|