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 CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_MESSAGE_FILTER_H_
6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_MESSAGE_FILTER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/browser/dom_storage/dom_storage_context_impl.h"
11 #include "content/common/dom_storage/dom_storage_types.h"
12 #include "content/public/browser/browser_message_filter.h"
17 class NullableString16;
23 class DOMStorageContextImpl;
24 class DOMStorageContextWrapper;
27 // This class handles the logistics of DOM Storage within the browser process.
28 // It mostly ferries information between IPCs and the dom_storage classes.
29 class DOMStorageMessageFilter
30 : public BrowserMessageFilter,
31 public DOMStorageContextImpl::EventObserver {
33 explicit DOMStorageMessageFilter(int render_process_id,
34 DOMStorageContextWrapper* context);
37 virtual ~DOMStorageMessageFilter();
39 void InitializeInSequence();
40 void UninitializeInSequence();
42 // BrowserMessageFilter implementation
43 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
44 virtual void OnFilterRemoved() OVERRIDE;
45 virtual base::TaskRunner* OverrideTaskRunnerForMessage(
46 const IPC::Message& message) OVERRIDE;
47 virtual bool OnMessageReceived(const IPC::Message& message,
48 bool* message_was_ok) OVERRIDE;
51 void OnOpenStorageArea(int connection_id, int64 namespace_id,
53 void OnCloseStorageArea(int connection_id);
54 void OnLoadStorageArea(int connection_id, DOMStorageValuesMap* map,
55 bool* send_log_get_messages);
56 void OnSetItem(int connection_id, const base::string16& key,
57 const base::string16& value, const GURL& page_url);
58 void OnLogGetItem(int connection_id, const base::string16& key,
59 const base::NullableString16& value);
60 void OnRemoveItem(int connection_id, const base::string16& key,
61 const GURL& page_url);
62 void OnClear(int connection_id, const GURL& page_url);
63 void OnFlushMessages();
65 // DOMStorageContextImpl::EventObserver implementation which
66 // sends events back to our renderer process.
67 virtual void OnDOMStorageItemSet(
68 const DOMStorageArea* area,
69 const base::string16& key,
70 const base::string16& new_value,
71 const base::NullableString16& old_value,
72 const GURL& page_url) OVERRIDE;
73 virtual void OnDOMStorageItemRemoved(
74 const DOMStorageArea* area,
75 const base::string16& key,
76 const base::string16& old_value,
77 const GURL& page_url) OVERRIDE;
78 virtual void OnDOMStorageAreaCleared(
79 const DOMStorageArea* area,
80 const GURL& page_url) OVERRIDE;
81 virtual void OnDOMSessionStorageReset(int64 namespace_id) OVERRIDE;
83 void SendDOMStorageEvent(
84 const DOMStorageArea* area,
86 const base::NullableString16& key,
87 const base::NullableString16& new_value,
88 const base::NullableString16& old_value);
90 int render_process_id_;
91 scoped_refptr<DOMStorageContextImpl> context_;
92 scoped_ptr<DOMStorageHost> host_;
93 int connection_dispatching_message_for_;
95 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageMessageFilter);
98 } // namespace content
100 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_MESSAGE_FILTER_H_