Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: content/child/quota_dispatcher.h

Issue 20015002: Make Platform::queryStorageUsageAndQuota work from worker threads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_CHILD_QUOTA_DISPATCHER_H_ 5 #ifndef CONTENT_CHILD_QUOTA_DISPATCHER_H_
6 #define CONTENT_CHILD_QUOTA_DISPATCHER_H_ 6 #define CONTENT_CHILD_QUOTA_DISPATCHER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/id_map.h" 12 #include "base/id_map.h"
13 #include "ipc/ipc_listener.h" 13 #include "base/memory/ref_counted.h"
14 #include "webkit/child/worker_task_runner.h"
14 #include "webkit/common/quota/quota_types.h" 15 #include "webkit/common/quota/quota_types.h"
15 16
16 class GURL; 17 class GURL;
17 18
18 namespace IPC { 19 namespace IPC {
19 class Message; 20 class Message;
20 } 21 }
21 22
22 namespace WebKit { 23 namespace WebKit {
23 class WebStorageQuotaCallbacks; 24 class WebStorageQuotaCallbacks;
24 } 25 }
25 26
26 namespace content { 27 namespace content {
27 28
29 class ThreadSafeSender;
30
28 // Dispatches and sends quota related messages sent to/from a child 31 // Dispatches and sends quota related messages sent to/from a child
29 // process from/to the main browser process. There is one instance 32 // process from/to the main browser process. There is one instance
30 // per child process. Messages are dispatched on the main child thread. 33 // per each thread. Thread-specific instance can be obtained by
31 class QuotaDispatcher : public IPC::Listener { 34 // ThreadSpecificInstance().
35 class QuotaDispatcher : public webkit_glue::WorkerTaskRunner::Observer {
32 public: 36 public:
33 class Callback { 37 class Callback {
34 public: 38 public:
35 virtual ~Callback() {} 39 virtual ~Callback() {}
36 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) = 0; 40 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) = 0;
37 virtual void DidGrantStorageQuota(int64 granted_quota) = 0; 41 virtual void DidGrantStorageQuota(int64 granted_quota) = 0;
38 virtual void DidFail(quota::QuotaStatusCode status) = 0; 42 virtual void DidFail(quota::QuotaStatusCode status) = 0;
39 }; 43 };
40 44
41 QuotaDispatcher(); 45 explicit QuotaDispatcher(ThreadSafeSender* thread_safe_sender);
42 virtual ~QuotaDispatcher(); 46 virtual ~QuotaDispatcher();
43 47
44 // IPC::Listener implementation. 48 // |thread_safe_sender| is used if calling this leads to construction.
45 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; 49 static QuotaDispatcher* ThreadSpecificInstance(
50 ThreadSafeSender* thread_safe_sender);
51
52 // webkit_glue::WorkerTaskRunner::Observer implementation.
53 virtual void OnWorkerRunLoopStopped() OVERRIDE;
54
55 void OnMessageReceived(const IPC::Message& msg);
46 56
47 void QueryStorageUsageAndQuota(const GURL& gurl, 57 void QueryStorageUsageAndQuota(const GURL& gurl,
48 quota::StorageType type, 58 quota::StorageType type,
49 Callback* callback); 59 Callback* callback);
50 void RequestStorageQuota(int render_view_id, 60 void RequestStorageQuota(int render_view_id,
51 const GURL& gurl, 61 const GURL& gurl,
52 quota::StorageType type, 62 quota::StorageType type,
53 int64 requested_size, 63 int64 requested_size,
54 Callback* callback); 64 Callback* callback);
55 65
56 // Creates a new Callback instance for WebStorageQuotaCallbacks. 66 // Creates a new Callback instance for WebStorageQuotaCallbacks.
57 static Callback* CreateWebStorageQuotaCallbacksWrapper( 67 static Callback* CreateWebStorageQuotaCallbacksWrapper(
58 WebKit::WebStorageQuotaCallbacks* callbacks); 68 WebKit::WebStorageQuotaCallbacks* callbacks);
59 69
60 private: 70 private:
61 // Message handlers. 71 // Message handlers.
62 void DidQueryStorageUsageAndQuota(int request_id, 72 void DidQueryStorageUsageAndQuota(int ipc_thread_id,
73 int request_id,
63 int64 current_usage, 74 int64 current_usage,
64 int64 current_quota); 75 int64 current_quota);
65 void DidGrantStorageQuota(int request_id, 76 void DidGrantStorageQuota(int ipc_thread_id,
77 int request_id,
66 int64 granted_quota); 78 int64 granted_quota);
67 void DidFail(int request_id, quota::QuotaStatusCode error); 79 void DidFail(int ipc_thread_id,
80 int request_id,
81 quota::QuotaStatusCode error);
68 82
69 IDMap<Callback, IDMapOwnPointer> pending_quota_callbacks_; 83 IDMap<Callback, IDMapOwnPointer> pending_quota_callbacks_;
70 84
85 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
86
71 DISALLOW_COPY_AND_ASSIGN(QuotaDispatcher); 87 DISALLOW_COPY_AND_ASSIGN(QuotaDispatcher);
72 }; 88 };
73 89
74 } // namespace content 90 } // namespace content
75 91
76 #endif // CONTENT_CHILD_QUOTA_DISPATCHER_H_ 92 #endif // CONTENT_CHILD_QUOTA_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698