summaryrefslogtreecommitdiffstats
path: root/chrome/browser/parsers/metadata_parser_manager.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-23 23:18:12 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-23 23:18:12 +0000
commitfa89702052f10d610859e2d724a7262743fe7418 (patch)
tree8a3671e7dd6924bb181cdfbeec96a6f51232a38b /chrome/browser/parsers/metadata_parser_manager.cc
parent0b0f60d96020eb44648869a7199520fd5b9f75e0 (diff)
downloadchromium_src-fa89702052f10d610859e2d724a7262743fe7418.zip
chromium_src-fa89702052f10d610859e2d724a7262743fe7418.tar.gz
chromium_src-fa89702052f10d610859e2d724a7262743fe7418.tar.bz2
Adding a new parsing system to the metadata url request.
BUG=none TEST=none Original review: http://codereview.chromium.org/155803 Patch by: dhg@google.com Review URL: http://codereview.chromium.org/160059 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21469 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/parsers/metadata_parser_manager.cc')
-rw-r--r--chrome/browser/parsers/metadata_parser_manager.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/chrome/browser/parsers/metadata_parser_manager.cc b/chrome/browser/parsers/metadata_parser_manager.cc
new file mode 100644
index 0000000..3efce7d
--- /dev/null
+++ b/chrome/browser/parsers/metadata_parser_manager.cc
@@ -0,0 +1,56 @@
+// 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() {
+ STLDeleteContainerPointers(factories_.begin(), factories_.end());
+}
+
+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;
+}