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