f4ca784b2fa4bf023133c8141a28db0ccac63b94
[platform/framework/web/crosswalk.git] / src / content / browser / dom_storage / dom_storage_host.h
1 // Copyright 2013 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_HOST_H_
6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_HOST_H_
7
8 #include <map>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/strings/nullable_string16.h"
12 #include "base/strings/string16.h"
13 #include "content/browser/dom_storage/dom_storage_namespace.h"
14 #include "content/common/content_export.h"
15 #include "content/common/dom_storage/dom_storage_types.h"
16
17 class GURL;
18
19 namespace content {
20
21 class DOMStorageContextImpl;
22 class DOMStorageHost;
23 class DOMStorageNamespace;
24 class DOMStorageArea;
25
26 // One instance is allocated in the main process for each client process.
27 // Used by DOMStorageMessageFilter in Chrome.
28 // This class is single threaded, and performs blocking file reads/writes,
29 // so it shouldn't be used on chrome's IO thread.
30 // See class comments for DOMStorageContextImpl for a larger overview.
31 class CONTENT_EXPORT DOMStorageHost {
32  public:
33   DOMStorageHost(DOMStorageContextImpl* context, int render_process_id);
34   ~DOMStorageHost();
35
36   bool OpenStorageArea(int connection_id, int namespace_id,
37                        const GURL& origin);
38   void CloseStorageArea(int connection_id);
39   bool ExtractAreaValues(int connection_id, DOMStorageValuesMap* map,
40                          bool* send_log_get_messages);
41   unsigned GetAreaLength(int connection_id);
42   base::NullableString16 GetAreaKey(int connection_id, unsigned index);
43   base::NullableString16 GetAreaItem(int connection_id,
44                                      const base::string16& key);
45   bool SetAreaItem(int connection_id, const base::string16& key,
46                    const base::string16& value, const GURL& page_url,
47                    base::NullableString16* old_value);
48   void LogGetAreaItem(int connection_id, const base::string16& key,
49                       const base::NullableString16& value);
50   bool RemoveAreaItem(int connection_id, const base::string16& key,
51                   const GURL& page_url,
52                   base::string16* old_value);
53   bool ClearArea(int connection_id, const GURL& page_url);
54   bool HasAreaOpen(int64 namespace_id, const GURL& origin,
55                    int64* alias_namespace_id) const;
56   // Resets all open areas for the namespace provided. Returns true
57   // iff there were any areas to reset.
58   bool ResetOpenAreasForNamespace(int64 namespace_id);
59
60  private:
61   // Struct to hold references needed for areas that are open
62   // within our associated client process.
63   struct NamespaceAndArea {
64     scoped_refptr<DOMStorageNamespace> namespace_;
65     scoped_refptr<DOMStorageArea> area_;
66     NamespaceAndArea();
67     ~NamespaceAndArea();
68   };
69   typedef std::map<int, NamespaceAndArea > AreaMap;
70
71   DOMStorageArea* GetOpenArea(int connection_id);
72   DOMStorageNamespace* GetNamespace(int connection_id);
73   void MaybeLogTransaction(
74       int connection_id,
75       DOMStorageNamespace::LogType transaction_type,
76       const GURL& origin,
77       const GURL& page_url,
78       const base::string16& key,
79       const base::NullableString16& value);
80
81   scoped_refptr<DOMStorageContextImpl> context_;
82   AreaMap connections_;
83   int render_process_id_;
84 };
85
86 }  // namespace content
87
88 #endif  // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_HOST_H_