Home | History | Annotate | Download | only in leveldatabase
      1 // Copyright (c) 2013 The LevelDB Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
      4 
      5 #ifndef THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_STDIO_H_
      6 #define THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_STDIO_H_
      7 
      8 #include "env_chromium.h"
      9 
     10 namespace leveldb_env {
     11 
     12 class ChromiumWritableFile : public leveldb::WritableFile {
     13  public:
     14   ChromiumWritableFile(const std::string& fname,
     15                        FILE* f,
     16                        const UMALogger* uma_logger,
     17                        WriteTracker* tracker,
     18                        bool make_backup);
     19   virtual ~ChromiumWritableFile();
     20   virtual leveldb::Status Append(const leveldb::Slice& data);
     21   virtual leveldb::Status Close();
     22   virtual leveldb::Status Flush();
     23   virtual leveldb::Status Sync();
     24 
     25  private:
     26   enum Type {
     27     kManifest,
     28     kTable,
     29     kOther
     30   };
     31   leveldb::Status SyncParent();
     32 
     33   std::string filename_;
     34   FILE* file_;
     35   const UMALogger* uma_logger_;
     36   WriteTracker* tracker_;
     37   Type file_type_;
     38   std::string parent_dir_;
     39   bool make_backup_;
     40 };
     41 
     42 class ChromiumEnvStdio : public ChromiumEnv {
     43  public:
     44   ChromiumEnvStdio();
     45   virtual ~ChromiumEnvStdio();
     46 
     47   virtual leveldb::Status NewSequentialFile(const std::string& fname,
     48                                             leveldb::SequentialFile** result);
     49   virtual leveldb::Status NewRandomAccessFile(
     50       const std::string& fname,
     51       leveldb::RandomAccessFile** result);
     52   virtual leveldb::Status NewWritableFile(const std::string& fname,
     53                                           leveldb::WritableFile** result);
     54   virtual leveldb::Status NewLogger(const std::string& fname,
     55                                     leveldb::Logger** result);
     56 
     57  protected:
     58   virtual base::File::Error GetDirectoryEntries(
     59       const base::FilePath& dir_param,
     60       std::vector<base::FilePath>* result) const;
     61 
     62  private:
     63   // BGThread() is the body of the background thread
     64   void BGThread();
     65   static void BGThreadWrapper(void* arg) {
     66     reinterpret_cast<ChromiumEnvStdio*>(arg)->BGThread();
     67   }
     68   void RecordOpenFilesLimit(const std::string& type);
     69 };
     70 
     71 }  // namespace leveldb_env
     72 
     73 #endif
     74