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::Sender* sender) 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) OVERRIDE;
50 void OnOpenStorageArea(int connection_id, int64 namespace_id,
52 void OnCloseStorageArea(int connection_id);
53 void OnLoadStorageArea(int connection_id, DOMStorageValuesMap* map,
54 bool* send_log_get_messages);
55 void OnSetItem(int connection_id, const base::string16& key,
56 const base::string16& value, const GURL& page_url);
57 void OnLogGetItem(int connection_id, const base::string16& key,
58 const base::NullableString16& value);
59 void OnRemoveItem(int connection_id, const base::string16& key,
60 const GURL& page_url);
61 void OnClear(int connection_id, const GURL& page_url);
62 void OnFlushMessages();
64 // DOMStorageContextImpl::EventObserver implementation which
65 // sends events back to our renderer process.
66 virtual void OnDOMStorageItemSet(
67 const DOMStorageArea* area,
68 const base::string16& key,
69 const base::string16& new_value,
70 const base::NullableString16& old_value,
71 const GURL& page_url) OVERRIDE;
72 virtual void OnDOMStorageItemRemoved(
73 const DOMStorageArea* area,
74 const base::string16& key,
75 const base::string16& old_value,
76 const GURL& page_url) OVERRIDE;
77 virtual void OnDOMStorageAreaCleared(
78 const DOMStorageArea* area,
79 const GURL& page_url) OVERRIDE;
80 virtual void OnDOMSessionStorageReset(int64 namespace_id) OVERRIDE;
82 void SendDOMStorageEvent(
83 const DOMStorageArea* area,
85 const base::NullableString16& key,
86 const base::NullableString16& new_value,
87 const base::NullableString16& old_value);
89 int render_process_id_;
90 scoped_refptr<DOMStorageContextImpl> context_;
91 scoped_ptr<DOMStorageHost> host_;
92 int connection_dispatching_message_for_;
94 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageMessageFilter);
97 } // namespace content
99 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_MESSAGE_FILTER_H_