Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1212)

Unified Diff: chrome/browser/file_system_proxy.cc

Issue 3131026: Moving file_system_proxy to base/ and changing it to work with MessageLoopPro... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/file_system_proxy.cc
===================================================================
--- chrome/browser/file_system_proxy.cc (revision 56780)
+++ chrome/browser/file_system_proxy.cc (working copy)
@@ -1,180 +0,0 @@
-// Copyright (c) 2010 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/file_system_proxy.h"
-
-#include "base/file_util.h"
-#include "chrome/browser/chrome_thread_relay.h"
-
-namespace {
-
-class RelayCreateOrOpen : public ChromeThreadRelay {
- public:
- RelayCreateOrOpen(
- const FilePath& file_path,
- int file_flags,
- FileSystemProxy::CreateOrOpenCallback* callback)
- : file_path_(file_path),
- file_flags_(file_flags),
- callback_(callback),
- file_handle_(base::kInvalidPlatformFileValue),
- created_(false) {
- DCHECK(callback);
- }
-
- protected:
- virtual ~RelayCreateOrOpen() {
- if (file_handle_ != base::kInvalidPlatformFileValue)
- FileSystemProxy::Close(file_handle_, NULL);
- }
-
- virtual void RunWork() {
- file_handle_ = base::CreatePlatformFile(file_path_, file_flags_, &created_);
- }
-
- virtual void RunCallback() {
- callback_->Run(base::PassPlatformFile(&file_handle_), created_);
- delete callback_;
- }
-
- private:
- FilePath file_path_;
- int file_flags_;
- FileSystemProxy::CreateOrOpenCallback* callback_;
- base::PlatformFile file_handle_;
- bool created_;
-};
-
-class RelayCreateTemporary : public ChromeThreadRelay {
- public:
- explicit RelayCreateTemporary(
- FileSystemProxy::CreateTemporaryCallback* callback)
- : callback_(callback),
- file_handle_(base::kInvalidPlatformFileValue) {
- DCHECK(callback);
- }
-
- protected:
- virtual ~RelayCreateTemporary() {
- if (file_handle_ != base::kInvalidPlatformFileValue)
- FileSystemProxy::Close(file_handle_, NULL);
- }
-
- virtual void RunWork() {
- // TODO(darin): file_util should have a variant of CreateTemporaryFile
- // that returns a FilePath and a PlatformFile.
- file_util::CreateTemporaryFile(&file_path_);
-
- // Use a fixed set of flags that are appropriate for writing to a temporary
- // file from the IO thread using a net::FileStream.
- int file_flags =
- base::PLATFORM_FILE_CREATE_ALWAYS |
- base::PLATFORM_FILE_WRITE |
- base::PLATFORM_FILE_ASYNC |
- base::PLATFORM_FILE_TEMPORARY;
- file_handle_ = base::CreatePlatformFile(file_path_, file_flags, NULL);
- }
-
- virtual void RunCallback() {
- callback_->Run(base::PassPlatformFile(&file_handle_), file_path_);
- delete callback_;
- }
-
- private:
- FileSystemProxy::CreateTemporaryCallback* callback_;
- base::PlatformFile file_handle_;
- FilePath file_path_;
-};
-
-class RelayWithStatusCallback : public ChromeThreadRelay {
- public:
- explicit RelayWithStatusCallback(FileSystemProxy::StatusCallback* callback)
- : callback_(callback),
- succeeded_(false) {
- // It is OK for callback to be NULL.
- }
-
- protected:
- virtual void RunCallback() {
- // The caller may not have been interested in the result.
- if (callback_) {
- callback_->Run(succeeded_);
- delete callback_;
- }
- }
-
- void SetStatus(bool succeeded) { succeeded_ = succeeded; }
-
- private:
- FileSystemProxy::StatusCallback* callback_;
- bool succeeded_;
-};
-
-class RelayClose : public RelayWithStatusCallback {
- public:
- RelayClose(base::PlatformFile file_handle,
- FileSystemProxy::StatusCallback* callback)
- : RelayWithStatusCallback(callback),
- file_handle_(file_handle) {
- }
-
- protected:
- virtual void RunWork() {
- SetStatus(base::ClosePlatformFile(file_handle_));
- }
-
- private:
- base::PlatformFile file_handle_;
-};
-
-class RelayDelete : public RelayWithStatusCallback {
- public:
- RelayDelete(const FilePath& file_path,
- bool recursive,
- FileSystemProxy::StatusCallback* callback)
- : RelayWithStatusCallback(callback),
- file_path_(file_path),
- recursive_(recursive) {
- }
-
- protected:
- virtual void RunWork() {
- SetStatus(file_util::Delete(file_path_, recursive_));
- }
-
- private:
- FilePath file_path_;
- bool recursive_;
-};
-
-void Start(const tracked_objects::Location& from_here,
- scoped_refptr<ChromeThreadRelay> relay) {
- relay->Start(ChromeThread::FILE, from_here);
-}
-
-} // namespace
-
-void FileSystemProxy::CreateOrOpen(const FilePath& file_path, int file_flags,
- CreateOrOpenCallback* callback) {
- Start(FROM_HERE, new RelayCreateOrOpen(file_path, file_flags, callback));
-}
-
-void FileSystemProxy::CreateTemporary(CreateTemporaryCallback* callback) {
- Start(FROM_HERE, new RelayCreateTemporary(callback));
-}
-
-void FileSystemProxy::Close(base::PlatformFile file_handle,
- StatusCallback* callback) {
- Start(FROM_HERE, new RelayClose(file_handle, callback));
-}
-
-void FileSystemProxy::Delete(const FilePath& file_path,
- StatusCallback* callback) {
- Start(FROM_HERE, new RelayDelete(file_path, false, callback));
-}
-
-void FileSystemProxy::RecursiveDelete(const FilePath& file_path,
- StatusCallback* callback) {
- Start(FROM_HERE, new RelayDelete(file_path, true, callback));
-}
« no previous file with comments | « chrome/browser/file_system_proxy.h ('k') | chrome/browser/renderer_host/redirect_to_file_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698