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_WIN_H_
      6 #define THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_WIN_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "third_party/leveldatabase/env_chromium.h"
     12 
     13 namespace leveldb_env {
     14 
     15 leveldb::Status MakeIOErrorWin(leveldb::Slice filename,
     16                                  const std::string& message,
     17                                  MethodID method,
     18                                  DWORD err);
     19 
     20 class ChromiumWritableFileWin : public leveldb::WritableFile {
     21  public:
     22   ChromiumWritableFileWin(const std::string& fname,
     23                             HANDLE f,
     24                             const UMALogger* uma_logger,
     25                             WriteTracker* tracker,
     26                             bool make_backup);
     27   virtual ~ChromiumWritableFileWin();
     28   virtual leveldb::Status Append(const leveldb::Slice& data);
     29   virtual leveldb::Status Close();
     30   virtual leveldb::Status Flush();
     31   virtual leveldb::Status Sync();
     32 
     33  private:
     34   enum Type {
     35     kManifest,
     36     kTable,
     37     kOther
     38   };
     39   leveldb::Status SyncParent();
     40 
     41   std::string filename_;
     42   HANDLE file_;
     43   const UMALogger* uma_logger_;
     44   WriteTracker* tracker_;
     45   Type file_type_;
     46   std::string parent_dir_;
     47   bool make_backup_;
     48 };
     49 
     50 class ChromiumEnvWin : public ChromiumEnv {
     51  public:
     52   ChromiumEnvWin();
     53   virtual ~ChromiumEnvWin();
     54 
     55   virtual leveldb::Status NewSequentialFile(const std::string& fname,
     56                                             leveldb::SequentialFile** result);
     57   virtual leveldb::Status NewRandomAccessFile(
     58       const std::string& fname,
     59       leveldb::RandomAccessFile** result);
     60   virtual leveldb::Status NewWritableFile(const std::string& fname,
     61                                           leveldb::WritableFile** result);
     62   virtual leveldb::Status NewLogger(const std::string& fname,
     63                                     leveldb::Logger** result);
     64 
     65  protected:
     66   virtual base::File::Error GetDirectoryEntries(
     67       const base::FilePath& dir_param,
     68       std::vector<base::FilePath>* result) const;
     69 
     70  private:
     71   // BGThread() is the body of the background thread
     72   void BGThread();
     73   static void BGThreadWrapper(void* arg) {
     74     reinterpret_cast<ChromiumEnvWin*>(arg)->BGThread();
     75   }
     76   void RecordOpenFilesLimit(const std::string& type);
     77   virtual void RecordOSError(MethodID method, DWORD err) const;
     78 };
     79 
     80 }  // namespace leveldb_env
     81 
     82 #endif  // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_WIN_H_
     83