summaryrefslogtreecommitdiffstats
path: root/extensions/browser/file_reader.cc
blob: f1a560016f4130af94e7bf39a0f4af60cc4db2a3 (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
// Copyright (c) 2011 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 "extensions/browser/file_reader.h"

#include "base/bind.h"
#include "base/file_util.h"
#include "base/message_loop/message_loop.h"
#include "content/public/browser/browser_thread.h"

using content::BrowserThread;

FileReader::FileReader(const extensions::ExtensionResource& resource,
                       const Callback& callback)
    : resource_(resource),
      callback_(callback),
      origin_loop_(base::MessageLoop::current()) {}

void FileReader::Start() {
  BrowserThread::PostTask(
      BrowserThread::FILE, FROM_HERE,
      base::Bind(&FileReader::ReadFileOnBackgroundThread, this));
}

FileReader::~FileReader() {}

void FileReader::ReadFileOnBackgroundThread() {
  std::string data;
  bool success = file_util::ReadFileToString(resource_.GetFilePath(), &data);
  origin_loop_->PostTask(FROM_HERE, base::Bind(callback_, success, data));
}