summaryrefslogtreecommitdiffstats
path: root/content/browser/in_process_webkit/webkit_context.cc
blob: f1cb1da7072e0272c9412fc56db3520d16b0afd4 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2011 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 "content/browser/in_process_webkit/webkit_context.h"

#include "base/bind.h"
#include "base/command_line.h"
#include "content/public/browser/browser_thread.h"

using content::BrowserThread;

WebKitContext::WebKitContext(
    bool is_incognito, const FilePath& data_path,
    quota::SpecialStoragePolicy* special_storage_policy,
    bool clear_local_state_on_exit,
    quota::QuotaManagerProxy* quota_manager_proxy,
    base::MessageLoopProxy* webkit_thread_loop)
    : data_path_(is_incognito ? FilePath() : data_path),
      is_incognito_(is_incognito),
      clear_local_state_on_exit_(clear_local_state_on_exit),
      ALLOW_THIS_IN_INITIALIZER_LIST(
          dom_storage_context_(new DOMStorageContext(
              this, special_storage_policy))),
      ALLOW_THIS_IN_INITIALIZER_LIST(
          indexed_db_context_(new IndexedDBContext(
              this, special_storage_policy, quota_manager_proxy,
              webkit_thread_loop))) {
}

WebKitContext::~WebKitContext() {
  // If the WebKit thread was ever spun up, delete the object there.  The task
  // will just get deleted if the WebKit thread isn't created (which only
  // happens during testing).
  dom_storage_context_->set_clear_local_state_on_exit_(
      clear_local_state_on_exit_);
  DOMStorageContext* dom_storage_context = dom_storage_context_.release();
  if (!BrowserThread::DeleteSoon(
          BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, dom_storage_context)) {
    // The WebKit thread wasn't created, and the task got deleted without
    // freeing the DOMStorageContext, so delete it manually.
    delete dom_storage_context;
  }

  indexed_db_context_->set_clear_local_state_on_exit(
      clear_local_state_on_exit_);
}

void WebKitContext::PurgeMemory() {
  if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)) {
    BrowserThread::PostTask(
        BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
        base::Bind(&WebKitContext::PurgeMemory, this));
    return;
  }

  dom_storage_context_->PurgeMemory();
}

void WebKitContext::DeleteDataModifiedSince(const base::Time& cutoff) {
  if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)) {
    BrowserThread::PostTask(
        BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
        base::Bind(&WebKitContext::DeleteDataModifiedSince, this, cutoff));
    return;
  }

  dom_storage_context_->DeleteDataModifiedSince(cutoff);
}

void WebKitContext::DeleteSessionStorageNamespace(
    int64 session_storage_namespace_id) {
  if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)) {
    BrowserThread::PostTask(
        BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
        base::Bind(&WebKitContext::DeleteSessionStorageNamespace, this,
                   session_storage_namespace_id));
    return;
  }

  dom_storage_context_->DeleteSessionStorageNamespace(
      session_storage_namespace_id);
}

void WebKitContext::SaveSessionState() {
  if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)) {
    BrowserThread::PostTask(
        BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
        base::Bind(&WebKitContext::SaveSessionState, this));
    return;
  }
  dom_storage_context_->SaveSessionState();
  indexed_db_context_->SaveSessionState();
}