summaryrefslogtreecommitdiffstats
path: root/webkit/support/test_webidbfactory.cc
blob: 42dfc21561292ae69fff2d37ef607914e4002758 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/support/test_webidbfactory.h"

#include "base/logging.h"
#include "webkit/base/file_path_string_conversions.h"
#include "webkit/support/webkit_support.h"

TestWebIDBFactory::TestWebIDBFactory() {
  // Create a new temp directory for Indexed DB storage, specific to this
  // factory. If this fails, WebKit uses in-memory storage.
  if (!indexed_db_dir_.CreateUniqueTempDir()) {
    LOG(WARNING) << "Failed to create a temp dir for Indexed DB, "
        "using in-memory storage.";
    DCHECK(indexed_db_dir_.path().empty());
  }
}

TestWebIDBFactory::~TestWebIDBFactory() {
}

void TestWebIDBFactory::getDatabaseNames(
    WebKit::WebIDBCallbacks* callbacks,
    const WebKit::WebString& database_identifier,
    const WebKit::WebString& data_dir) {
  GetFactory()->getDatabaseNames(callbacks, database_identifier,
                                 data_dir.isEmpty() ? GetDataDir() : data_dir);
}

void TestWebIDBFactory::open(
    const WebKit::WebString& name,
    long long version,
    long long transaction_id,
    WebKit::WebIDBCallbacks* callbacks,
    WebKit::WebIDBDatabaseCallbacks* database_callbacks,
    const WebKit::WebString& database_identifier,
    const WebKit::WebString& data_dir) {
  GetFactory()->open(name, version, transaction_id, callbacks,
                     database_callbacks, database_identifier,
                     data_dir.isEmpty() ? GetDataDir() : data_dir);
}

void TestWebIDBFactory::deleteDatabase(
    const WebKit::WebString& name,
    WebKit::WebIDBCallbacks* callbacks,
    const WebKit::WebString& database_identifier,
    const WebKit::WebString& data_dir) {
  GetFactory()->deleteDatabase(name, callbacks, database_identifier,
                               data_dir.isEmpty() ? GetDataDir() : data_dir);
}

WebKit::WebIDBFactory* TestWebIDBFactory::GetFactory() {
  WebKit::WebIDBFactory* factory = factories_.Get();
  if (!factory) {
    factory = WebKit::WebIDBFactory::create();
    factories_.Set(factory);
  }
  return factory;
}

WebKit::WebString TestWebIDBFactory::GetDataDir() const {
  return webkit_base::FilePathToWebString(indexed_db_dir_.path());
}