summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/file_system_quota_util.cc
blob: 3d0fab40caf84e566b83873a4b28df4930b6ef01 (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) 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 "webkit/fileapi/file_system_quota_util.h"

#include "base/compiler_specific.h"
#include "base/message_loop_proxy.h"

namespace fileapi {

void FileSystemQuotaUtil::Proxy::UpdateOriginUsage(
    quota::QuotaManagerProxy* proxy, const GURL& origin_url,
    fileapi::FileSystemType type, int64 delta) {
  if (!file_thread_->BelongsToCurrentThread()) {
    file_thread_->PostTask(FROM_HERE, NewRunnableMethod(
        this, &Proxy::UpdateOriginUsage, proxy, origin_url, type, delta));
    return;
  }
  if (quota_util_)
    quota_util_->UpdateOriginUsageOnFileThread(proxy, origin_url, type, delta);
}

void FileSystemQuotaUtil::Proxy::StartUpdateOrigin(
    const GURL& origin_url, fileapi::FileSystemType type) {
  if (!file_thread_->BelongsToCurrentThread()) {
    file_thread_->PostTask(FROM_HERE, NewRunnableMethod(
        this, &Proxy::StartUpdateOrigin, origin_url, type));
    return;
  }
  if (quota_util_)
    quota_util_->StartUpdateOriginOnFileThread(origin_url, type);
}

void FileSystemQuotaUtil::Proxy::EndUpdateOrigin(
    const GURL& origin_url, fileapi::FileSystemType type) {
  if (!file_thread_->BelongsToCurrentThread()) {
    file_thread_->PostTask(FROM_HERE, NewRunnableMethod(
        this, &Proxy::EndUpdateOrigin, origin_url, type));
    return;
  }
  if (quota_util_)
    quota_util_->EndUpdateOriginOnFileThread(origin_url, type);
}

FileSystemQuotaUtil::Proxy::Proxy(
    FileSystemQuotaUtil* quota_util,
    base::MessageLoopProxy* file_thread)
    : quota_util_(quota_util),
      file_thread_(file_thread) {
  DCHECK(quota_util);
}

FileSystemQuotaUtil::Proxy::~Proxy() {
}

FileSystemQuotaUtil::FileSystemQuotaUtil(base::MessageLoopProxy* file_thread)
    : proxy_(new Proxy(ALLOW_THIS_IN_INITIALIZER_LIST(this), file_thread)) {
}

FileSystemQuotaUtil::~FileSystemQuotaUtil() {
  proxy_->quota_util_ = NULL;
}

}  // namespace fileapi