// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // This file defines FileStream::Context class. // The general design of FileStream is as follows: file_stream.h defines // FileStream class which basically is just an "wrapper" not containing any // specific implementation details. It re-routes all its method calls to // the instance of FileStream::Context (FileStream holds a scoped_ptr to // FileStream::Context instance). Context was extracted into a different class // to be able to do and finish all async operations even when FileStream // instance is deleted. So FileStream's destructor can schedule file // closing to be done by Context in WorkerPool (or the TaskRunner passed to // constructor) and then just return (releasing Context pointer from // scoped_ptr) without waiting for actual closing to complete. // Implementation of FileStream::Context is divided in two parts: some methods // and members are platform-independent and some depend on the platform. This // header file contains the complete definition of Context class including all // platform-dependent parts (because of that it has a lot of #if-#else // branching). Implementations of all platform-independent methods are // located in file_stream_context.cc, and all platform-dependent methods are // in file_stream_context_{win,posix}.cc. This separation provides better // readability of Context's code. And we tried to make as much Context code // platform-independent as possible. So file_stream_context_{win,posix}.cc are // much smaller than file_stream_context.cc now. #ifndef NET_BASE_FILE_STREAM_CONTEXT_H_ #define NET_BASE_FILE_STREAM_CONTEXT_H_ #include <stdint.h> #include "base/files/file.h" #include "base/logging.h" #include "base/memory/weak_ptr.h" #include "base/message_loop/message_pump_for_io.h" #include "base/task/single_thread_task_runner.h" #include "base/task/task_runner.h" #include "build/build_config.h" #include "net/base/completion_once_callback.h" #include "net/base/file_stream.h" #if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) #include <errno.h> #endif namespace base { class FilePath; } namespace net { class IOBuffer; // Implementation for a FileStream. See file_stream.h for documentation. #if BUILDFLAG(IS_WIN) class FileStream::Context : public base::MessagePumpForIO::IOHandler { #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) class FileStream::Context { … }; } // namespace net #endif // NET_BASE_FILE_STREAM_CONTEXT_H_