Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / parsers / metadata_parser_manager.cc
blobb60a0ddcd05a92002853bd51e7fab3d22d7428ea
1 // Copyright (c) 2011 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_manager.h"
7 #include "base/logging.h"
8 #include "base/file_util.h"
9 #include "base/memory/singleton.h"
10 #include "base/stl_util.h"
11 #include "build/build_config.h"
12 #include "chrome/browser/parsers/metadata_parser_factory.h"
13 #include "chrome/browser/parsers/metadata_parser_jpeg_factory.h"
15 static const int kAmountToRead = 256;
17 // Gets the singleton
18 MetadataParserManager* MetadataParserManager::GetInstance() {
19 // Uses the LeakySingletonTrait because cleanup is optional.
20 return Singleton<MetadataParserManager,
21 LeakySingletonTraits<MetadataParserManager> >::get();
24 bool MetadataParserManager::RegisterParserFactory(
25 MetadataParserFactory* parser) {
26 factories_.push_back(parser);
27 return true;
30 MetadataParserManager::MetadataParserManager() {
31 MetadataParserJpegFactory *factory = new MetadataParserJpegFactory();
32 RegisterParserFactory(factory);
35 MetadataParserManager::~MetadataParserManager() {}
37 MetadataParser* MetadataParserManager::GetParserForFile(
38 const base::FilePath& path) {
39 char buffer[kAmountToRead];
40 int amount_read = 0;
41 DLOG(ERROR) << path.value();
42 amount_read = base::ReadFile(path, buffer, sizeof(buffer));
43 if (amount_read <= 0) {
44 DLOG(ERROR) << "Unable to read file";
45 return NULL;
47 for (size_t x = 0; x < factories_.size(); ++x) {
48 if (factories_[x]->CanParse(path, buffer, amount_read)) {
49 return factories_[x]->CreateParser(path);
52 return NULL;