blob: 109a97a8b47f2f07454f6a15d2207297b8dbd905 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]1683aedf2009-09-29 23:06:132// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]1683aedf2009-09-29 23:06:134
[email protected]993da5e2013-03-23 21:25:165#ifndef EXTENSIONS_BROWSER_FILE_READER_H_
6#define EXTENSIONS_BROWSER_FILE_READER_H_
[email protected]1683aedf2009-09-29 23:06:137
8#include <string>
9
[email protected]1ec27eb52011-11-03 21:59:0910#include "base/callback.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/ref_counted.h"
[email protected]993da5e2013-03-23 21:25:1612#include "extensions/common/extension_resource.h"
[email protected]1683aedf2009-09-29 23:06:1313
[email protected]5e9e96a2013-03-31 02:29:2014namespace base {
[email protected]1683aedf2009-09-29 23:06:1315class MessageLoop;
[email protected]5e9e96a2013-03-31 02:29:2016}
[email protected]1683aedf2009-09-29 23:06:1317
[email protected]ecabe6ee2009-10-07 22:49:1018// This file defines an interface for reading a file asynchronously on a
19// background thread.
20// Consider abstracting out a FilePathProvider (ExtensionResource) and moving
21// back to chrome/browser/net if other subsystems want to use it.
[email protected]1683aedf2009-09-29 23:06:1322class FileReader : public base::RefCountedThreadSafe<FileReader> {
23 public:
24 // Reports success or failure and the data of the file upon success.
[email protected]1ec27eb52011-11-03 21:59:0925 typedef base::Callback<void(bool, const std::string&)> Callback;
[email protected]1683aedf2009-09-29 23:06:1326
[email protected]993da5e2013-03-23 21:25:1627 FileReader(const extensions::ExtensionResource& resource,
28 const Callback& callback);
[email protected]1683aedf2009-09-29 23:06:1329
30 // Called to start reading the file on a background thread. Upon completion,
31 // the callback will be notified of the results.
32 void Start();
33
34 private:
[email protected]8de85a62009-11-06 08:32:1735 friend class base::RefCountedThreadSafe<FileReader>;
36
[email protected]8e383412010-10-19 16:57:0337 virtual ~FileReader();
[email protected]8de85a62009-11-06 08:32:1738
[email protected]1683aedf2009-09-29 23:06:1339 void ReadFileOnBackgroundThread();
[email protected]1683aedf2009-09-29 23:06:1340
[email protected]993da5e2013-03-23 21:25:1641 extensions::ExtensionResource resource_;
[email protected]1ec27eb52011-11-03 21:59:0942 Callback callback_;
[email protected]5e9e96a2013-03-31 02:29:2043 base::MessageLoop* origin_loop_;
[email protected]1683aedf2009-09-29 23:06:1344};
45
[email protected]993da5e2013-03-23 21:25:1646#endif // EXTENSIONS_BROWSER_FILE_READER_H_