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 ~DOMStorageMessageFilter() override;
39 void InitializeInSequence();
40 void UninitializeInSequence();
42 // BrowserMessageFilter implementation
43 void OnFilterAdded(IPC::Sender* sender) override;
44 void OnFilterRemoved() override;
45 base::TaskRunner* OverrideTaskRunnerForMessage(
46 const IPC::Message& message) override;
47 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 void OnDOMStorageItemSet(const DOMStorageArea* area,
67 const base::string16& key,
68 const base::string16& new_value,
69 const base::NullableString16& old_value,
70 const GURL& page_url) override;
71 void OnDOMStorageItemRemoved(const DOMStorageArea* area,
72 const base::string16& key,
73 const base::string16& old_value,
74 const GURL& page_url) override;
75 void OnDOMStorageAreaCleared(const DOMStorageArea* area,
76 const GURL& page_url) override;
77 void OnDOMSessionStorageReset(int64 namespace_id) override;
79 void SendDOMStorageEvent(
80 const DOMStorageArea* area,
82 const base::NullableString16& key,
83 const base::NullableString16& new_value,
84 const base::NullableString16& old_value);
86 int render_process_id_;
87 scoped_refptr<DOMStorageContextImpl> context_;
88 scoped_ptr<DOMStorageHost> host_;
89 int connection_dispatching_message_for_;
91 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageMessageFilter);
94 } // namespace content
96 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_MESSAGE_FILTER_H_