Shaka Player Embedded
idb_factory.cc
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/js/idb/idb_factory.h"
16 
17 #include <utility>
18 
21 #include "src/js/idb/idb_utils.h"
23 #include "src/js/idb/request.h"
24 #include "src/memory/heap_tracer.h"
25 
26 namespace shaka {
27 namespace js {
28 namespace idb {
29 
30 namespace {
31 
32 constexpr const char* kDbFileName = "shaka_indexeddb.db";
33 
34 } // namespace
35 
37 // \cond Doxygen_Skip
38 IDBFactory::~IDBFactory() {}
39 // \endcond Doxygen_Skip
40 
42  optional<uint64_t> version) {
43  RefPtr<IDBOpenDBRequest> request(new IDBOpenDBRequest(name, version));
44  const std::string db_path =
47  TaskPriority::Internal, "IndexedDb::open",
48  [=]() { request->DoOperation(db_path); });
49  return request;
50 }
51 
53  RefPtr<IDBOpenDBRequest> request(new IDBOpenDBRequest("test", 1));
54  // Use a temporary database name. This will be cleaned up by sqlite.
56  TaskPriority::Internal, "IndexedDb::openTestDb",
57  [=]() { request->DoOperation(""); });
58  return request;
59 }
60 
63  const std::string db_path =
66  TaskPriority::Internal, "IndexedDb::deleteDatabase",
67  [=]() { request->DoOperation(db_path); });
68  return request;
69 }
70 
72  proto::Value temp;
73  RETURN_IF_ERROR(StoreInProto(value, &temp));
74  return LoadFromProto(temp);
75 }
76 
77 
79  AddMemberFunction("cloneForTesting", &IDBFactory::CloneForTesting);
80  AddMemberFunction("open", &IDBFactory::Open);
81  AddMemberFunction("openTestDb", &IDBFactory::OpenTestDb);
82  AddMemberFunction("deleteDatabase", &IDBFactory::DeleteDatabase);
83 
84  NotImplemented("cmp");
85 }
86 
87 } // namespace idb
88 } // namespace js
89 } // namespace shaka
ExceptionOr< Any > CloneForTesting(Any value)
Definition: idb_factory.cc:71
Any LoadFromProto(const proto::Value &value)
Definition: idb_utils.cc:238
std::string GetPathForDynamicFile(const std::string &file) const
Definition: any.h:31
ExceptionOr< void > StoreInProto(Any input, proto::Value *result)
Definition: idb_utils.cc:233
RefPtr< IDBOpenDBRequest > Open(const std::string &name, optional< uint64_t > version)
Definition: idb_factory.cc:41
RefPtr< IDBRequest > DeleteDatabase(const std::string &name)
Definition: idb_factory.cc:61
RefPtr< IDBOpenDBRequest > OpenTestDb()
Definition: idb_factory.cc:52
#define RETURN_IF_ERROR(code)
Definition: sqlite.cc:31
std::shared_ptr< ThreadEvent< impl::RetOf< Func > > > AddInternalTask(TaskPriority priority, const std::string &name, Func &&callback)
Definition: task_runner.h:219
std::string name() const
TaskRunner * MainThread()