1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_QUOTA_INTERNALS_QUOTA_INTERNALS_PROXY_H_
6 #define CHROME_BROWSER_UI_WEBUI_QUOTA_INTERNALS_QUOTA_INTERNALS_PROXY_H_
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/sequenced_task_runner_helpers.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "storage/browser/quota/quota_manager.h"
18 #include "storage/common/quota/quota_types.h"
20 namespace quota_internals
{
22 class QuotaInternalsHandler
;
23 class GlobalStorageInfo
;
24 class PerHostStorageInfo
;
25 class PerOriginStorageInfo
;
26 typedef std::map
<std::string
, std::string
> Statistics
;
28 // This class is the bridge between QuotaInternalsHandler and QuotaManager.
29 // Each QuotaInternalsHandler instances creates and owns a instance of this
31 class QuotaInternalsProxy
32 : public base::RefCountedThreadSafe
<
34 content::BrowserThread::DeleteOnIOThread
> {
36 explicit QuotaInternalsProxy(QuotaInternalsHandler
* handler
);
38 void RequestInfo(scoped_refptr
<storage::QuotaManager
> quota_manager
);
41 friend class base::DeleteHelper
<QuotaInternalsProxy
>;
42 friend struct content::BrowserThread::DeleteOnThread
<
43 content::BrowserThread::IO
>;
44 friend class QuotaInternalsHandler
;
46 typedef storage::QuotaManager::QuotaTableEntries QuotaTableEntries
;
47 typedef storage::QuotaManager::OriginInfoTableEntries OriginInfoTableEntries
;
49 virtual ~QuotaInternalsProxy();
51 void ReportAvailableSpace(int64 available_space
);
52 void ReportGlobalInfo(const GlobalStorageInfo
& data
);
53 void ReportPerHostInfo(const std::vector
<PerHostStorageInfo
>& hosts
);
54 void ReportPerOriginInfo(const std::vector
<PerOriginStorageInfo
>& origins
);
55 void ReportStatistics(const Statistics
& stats
);
57 // Called on IO Thread by QuotaManager as callback.
58 void DidGetAvailableSpace(storage::QuotaStatusCode status
, int64 space
);
59 void DidGetGlobalQuota(storage::StorageType type
,
60 storage::QuotaStatusCode status
,
62 void DidGetGlobalUsage(storage::StorageType type
,
64 int64 unlimited_usage
);
65 void DidDumpQuotaTable(const QuotaTableEntries
& entries
);
66 void DidDumpOriginInfoTable(const OriginInfoTableEntries
& entries
);
67 void DidGetHostUsage(const std::string
& host
,
68 storage::StorageType type
,
71 // Helper. Called on IO Thread.
72 void RequestPerOriginInfo(storage::StorageType type
);
73 void VisitHost(const std::string
& host
, storage::StorageType type
);
74 void GetHostUsage(const std::string
& host
, storage::StorageType type
);
77 QuotaInternalsHandler
* handler_
;
80 scoped_refptr
<storage::QuotaManager
> quota_manager_
;
81 std::set
<std::pair
<std::string
, storage::StorageType
> > hosts_visited_
,
83 std::vector
<PerHostStorageInfo
> report_pending_
;
84 base::WeakPtrFactory
<QuotaInternalsProxy
> weak_factory_
;
86 DISALLOW_COPY_AND_ASSIGN(QuotaInternalsProxy
);
88 } // namespace quota_internals
90 #endif // CHROME_BROWSER_UI_WEBUI_QUOTA_INTERNALS_QUOTA_INTERNALS_PROXY_H_