Home | History | Annotate | Download | only in fake_ppapi
      1 // Copyright 2014 The Chromium 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.
      4 
      5 #ifndef TESTS_NACL_IO_TEST_FAKE_VAR_MANAGER_H_
      6 #define TESTS_NACL_IO_TEST_FAKE_VAR_MANAGER_H_
      7 
      8 #include <map>
      9 #include <ppapi/c/pp_var.h>
     10 #include <string>
     11 #include <vector>
     12 
     13 #include "sdk_util/macros.h"
     14 
     15 typedef std::vector<PP_Var> FakeArrayType;
     16 typedef std::map<std::string, PP_Var> FakeDictType;
     17 
     18 struct FakeVarData {
     19   uint64_t id;
     20   uint64_t type;
     21   int32_t ref_count;
     22   std::string string_value;
     23   FakeArrayType array_value;
     24   FakeDictType dict_value;
     25   struct {
     26     void* ptr;
     27     uint32_t length;
     28   } buffer_value;
     29 };
     30 
     31 class FakeVarManager {
     32  public:
     33   FakeVarManager();
     34   ~FakeVarManager();
     35 
     36   void AddRef(PP_Var var);
     37   void Release(PP_Var var);
     38   FakeVarData* CreateVarData();
     39   FakeVarData* GetVarData(PP_Var var);
     40   std::string Describe(const FakeVarData& resource);
     41 
     42   bool debug;
     43  private:
     44   void DestroyVarData(FakeVarData* var);
     45 
     46   typedef uint64_t Id;
     47   typedef std::map<Id, FakeVarData> VarMap;
     48 
     49   Id next_id_;
     50   VarMap var_map_;
     51 
     52   DISALLOW_COPY_AND_ASSIGN(FakeVarManager);
     53 };
     54 
     55 #endif  // TESTS_NACL_IO_TEST_FAKE_VAR_MANAGER_H_
     56