diff options
author | cira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-07 22:49:10 +0000 |
---|---|---|
committer | cira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-07 22:49:10 +0000 |
commit | ecabe6eed156a36238888bfd2fdb96ec4906f0a4 (patch) | |
tree | 9419d9a349fc940d45fa450b3a75169fdf48b39f /chrome/browser/net | |
parent | 7050861ff094fd74d155264b6da3ca3795543870 (diff) | |
download | chromium_src-ecabe6eed156a36238888bfd2fdb96ec4906f0a4.zip chromium_src-ecabe6eed156a36238888bfd2fdb96ec4906f0a4.tar.gz chromium_src-ecabe6eed156a36238888bfd2fdb96ec4906f0a4.tar.bz2 |
Loads local resources from current locale subtree if available, if not it falls back to extension subtree.
We look for ext_root/foo/bar.js under ext_root/_locales/fr/foo/bar.js if current locale is fr. If there is no fr specific resource we load ext_root/foo/bar.js instead.
Lots of small refactoring to replace FilePath with ExtensionResource.
BUG=12131
TEST=See unittest for sample tree.
Review URL: http://codereview.chromium.org/256022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28333 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net')
-rw-r--r-- | chrome/browser/net/file_reader.cc | 32 | ||||
-rw-r--r-- | chrome/browser/net/file_reader.h | 39 | ||||
-rw-r--r-- | chrome/browser/net/file_reader_unittest.cc | 92 |
3 files changed, 0 insertions, 163 deletions
diff --git a/chrome/browser/net/file_reader.cc b/chrome/browser/net/file_reader.cc deleted file mode 100644 index 9e3041e..0000000 --- a/chrome/browser/net/file_reader.cc +++ /dev/null @@ -1,32 +0,0 @@ -// 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/net/file_reader.h" - -#include "base/file_util.h" -#include "chrome/browser/chrome_thread.h" - -FileReader::FileReader(const FilePath& path, Callback* callback) - : path_(path), - callback_(callback), - origin_loop_(MessageLoop::current()) { - DCHECK(callback_); -} - -void FileReader::Start() { - ChromeThread::GetMessageLoop(ChromeThread::FILE)->PostTask(FROM_HERE, - NewRunnableMethod(this, &FileReader::ReadFileOnBackgroundThread)); -} - -void FileReader::ReadFileOnBackgroundThread() { - std::string data; - bool success = file_util::ReadFileToString(path_, &data); - origin_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &FileReader::RunCallback, success, data)); -} - -void FileReader::RunCallback(bool success, const std::string& data) { - callback_->Run(success, data); - delete callback_; -} diff --git a/chrome/browser/net/file_reader.h b/chrome/browser/net/file_reader.h deleted file mode 100644 index 7aa52f1..0000000 --- a/chrome/browser/net/file_reader.h +++ /dev/null @@ -1,39 +0,0 @@ -// 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. -// -// This file defines an interface for reading a file asynchronously on a -// background thread. - -#ifndef CHROME_BROWSER_NET_FILE_READER_H_ -#define CHROME_BROWSER_NET_FILE_READER_H_ - -#include <string> - -#include "base/file_path.h" -#include "base/ref_counted.h" -#include "base/task.h" - -class MessageLoop; - -class FileReader : public base::RefCountedThreadSafe<FileReader> { - public: - // Reports success or failure and the data of the file upon success. - typedef Callback2<bool, const std::string&>::Type Callback; - - FileReader(const FilePath& path, Callback* callback); - - // Called to start reading the file on a background thread. Upon completion, - // the callback will be notified of the results. - void Start(); - - private: - void ReadFileOnBackgroundThread(); - void RunCallback(bool success, const std::string& data); - - FilePath path_; - Callback* callback_; - MessageLoop* origin_loop_; -}; - -#endif // CHROME_BROWSER_NET_FILE_READER_H_ diff --git a/chrome/browser/net/file_reader_unittest.cc b/chrome/browser/net/file_reader_unittest.cc deleted file mode 100644 index 72c3f42..0000000 --- a/chrome/browser/net/file_reader_unittest.cc +++ /dev/null @@ -1,92 +0,0 @@ -// 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 "base/file_util.h" -#include "base/message_loop.h" -#include "base/path_service.h" -#include "chrome/browser/chrome_thread.h" -#include "chrome/browser/net/file_reader.h" -#include "chrome/common/chrome_paths.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -class FileReaderTest : public testing::Test { - public: - FileReaderTest() : file_thread_(ChromeThread::FILE) { - file_thread_.Start(); - } - private: - MessageLoop message_loop_; - ChromeThread file_thread_; -}; - -class Receiver { - public: - Receiver() : succeeded_(false) { - } - - FileReader::Callback* NewCallback() { - return ::NewCallback(this, &Receiver::DidReadFile); - } - - bool succeeded() const { return succeeded_; } - const std::string& data() const { return data_; } - - private: - void DidReadFile(bool success, const std::string& data) { - succeeded_ = success; - data_ = data; - MessageLoop::current()->Quit(); - } - - bool succeeded_; - std::string data_; -}; - -void RunBasicTest(const char* filename) { - FilePath path; - PathService::Get(chrome::DIR_TEST_DATA, &path); - path = path.AppendASCII(filename); - - std::string file_contents; - bool file_exists = file_util::ReadFileToString(path, &file_contents); - - Receiver receiver; - - scoped_refptr<FileReader> file_reader( - new FileReader(path, receiver.NewCallback())); - file_reader->Start(); - - MessageLoop::current()->Run(); - - EXPECT_EQ(file_exists, receiver.succeeded()); - EXPECT_EQ(file_contents, receiver.data()); -} - -TEST_F(FileReaderTest, SmallFile) { - RunBasicTest("title1.html"); -} - -TEST_F(FileReaderTest, BiggerFile) { - RunBasicTest("download-test1.lib"); -} - -TEST_F(FileReaderTest, NonExistantFile) { - FilePath path; - PathService::Get(chrome::DIR_TEST_DATA, &path); - path = path.AppendASCII("file_that_does_not_exist"); - - Receiver receiver; - - scoped_refptr<FileReader> file_reader( - new FileReader(path, receiver.NewCallback())); - file_reader->Start(); - - MessageLoop::current()->Run(); - - EXPECT_FALSE(receiver.succeeded()); -} - -} // namespace |