Home | History | Annotate | Download | only in dom_storage
      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.
      4 
      5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_MESSAGE_FILTER_H_
      6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_MESSAGE_FILTER_H_
      7 
      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"
     13 
     14 class GURL;
     15 
     16 namespace base {
     17 class NullableString16;
     18 }
     19 
     20 namespace content {
     21 
     22 class DOMStorageArea;
     23 class DOMStorageContextImpl;
     24 class DOMStorageContextWrapper;
     25 class DOMStorageHost;
     26 
     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 {
     32  public:
     33   explicit DOMStorageMessageFilter(int render_process_id,
     34                                    DOMStorageContextWrapper* context);
     35 
     36  private:
     37   virtual ~DOMStorageMessageFilter();
     38 
     39   void InitializeInSequence();
     40   void UninitializeInSequence();
     41 
     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;
     48 
     49   // Message Handlers.
     50   void OnOpenStorageArea(int connection_id, int64 namespace_id,
     51                          const GURL& origin);
     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();
     63 
     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;
     81 
     82   void SendDOMStorageEvent(
     83       const DOMStorageArea* area,
     84       const GURL& page_url,
     85       const base::NullableString16& key,
     86       const base::NullableString16& new_value,
     87       const base::NullableString16& old_value);
     88 
     89   int render_process_id_;
     90   scoped_refptr<DOMStorageContextImpl> context_;
     91   scoped_ptr<DOMStorageHost> host_;
     92   int connection_dispatching_message_for_;
     93 
     94   DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageMessageFilter);
     95 };
     96 
     97 }  // namespace content
     98 
     99 #endif  // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_MESSAGE_FILTER_H_
    100