25190a6f8618330620b47c1943db036a300c6b22
[platform/framework/web/crosswalk.git] / src / content / public / browser / browser_context.h
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_PUBLIC_BROWSER_BROWSER_CONTEXT_H_
6 #define CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_
7
8 #include "base/callback_forward.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/supports_user_data.h"
12 #include "content/common/content_export.h"
13 #include "content/public/common/push_messaging_status.h"
14
15 class GURL;
16
17 namespace base {
18 class FilePath;
19 }
20
21 namespace storage {
22 class ExternalMountPoints;
23 }
24
25 namespace net {
26 class URLRequestContextGetter;
27 }
28
29 namespace storage {
30 class SpecialStoragePolicy;
31 }
32
33 namespace content {
34
35 class BlobHandle;
36 class BrowserPluginGuestManager;
37 class DownloadManager;
38 class DownloadManagerDelegate;
39 class IndexedDBContext;
40 class PushMessagingService;
41 class ResourceContext;
42 class SiteInstance;
43 class StoragePartition;
44 class SSLHostStateDelegate;
45
46 // This class holds the context needed for a browsing session.
47 // It lives on the UI thread. All these methods must only be called on the UI
48 // thread.
49 class CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
50  public:
51   static DownloadManager* GetDownloadManager(BrowserContext* browser_context);
52
53   // Returns BrowserContext specific external mount points. It may return NULL
54   // if the context doesn't have any BrowserContext specific external mount
55   // points. Currenty, non-NULL value is returned only on ChromeOS.
56   static storage::ExternalMountPoints* GetMountPoints(BrowserContext* context);
57
58   static content::StoragePartition* GetStoragePartition(
59       BrowserContext* browser_context, SiteInstance* site_instance);
60   static content::StoragePartition* GetStoragePartitionForSite(
61       BrowserContext* browser_context, const GURL& site);
62   typedef base::Callback<void(StoragePartition*)> StoragePartitionCallback;
63   static void ForEachStoragePartition(
64       BrowserContext* browser_context,
65       const StoragePartitionCallback& callback);
66   static void AsyncObliterateStoragePartition(
67       BrowserContext* browser_context,
68       const GURL& site,
69       const base::Closure& on_gc_required);
70
71   // This function clears the contents of |active_paths| but does not take
72   // ownership of the pointer.
73   static void GarbageCollectStoragePartitions(
74       BrowserContext* browser_context,
75       scoped_ptr<base::hash_set<base::FilePath> > active_paths,
76       const base::Closure& done);
77
78   // DON'T USE THIS. GetDefaultStoragePartition() is going away.
79   // Use GetStoragePartition() instead. Ask ajwong@ if you have problems.
80   static content::StoragePartition* GetDefaultStoragePartition(
81       BrowserContext* browser_context);
82
83   typedef base::Callback<void(scoped_ptr<BlobHandle>)> BlobCallback;
84
85   // |callback| returns a NULL scoped_ptr on failure.
86   static void CreateMemoryBackedBlob(BrowserContext* browser_context,
87                                      const char* data, size_t length,
88                                      const BlobCallback& callback);
89
90   // Delivers a push message with |data| to the Service Worker identified by
91   // |origin| and |service_worker_registration_id|.
92   static void DeliverPushMessage(
93       BrowserContext* browser_context,
94       const GURL& origin,
95       int64 service_worker_registration_id,
96       const std::string& data,
97       const base::Callback<void(PushMessagingStatus)>& callback);
98
99   // Ensures that the corresponding ResourceContext is initialized. Normally the
100   // BrowserContext initializs the corresponding getters when its objects are
101   // created, but if the embedder wants to pass the ResourceContext to another
102   // thread before they use BrowserContext, they should call this to make sure
103   // that the ResourceContext is ready.
104   static void EnsureResourceContextInitialized(BrowserContext* browser_context);
105
106   // Tells the HTML5 objects on this context to persist their session state
107   // across the next restart.
108   static void SaveSessionState(BrowserContext* browser_context);
109
110   virtual ~BrowserContext();
111
112   // Returns the path of the directory where this context's data is stored.
113   virtual base::FilePath GetPath() const = 0;
114
115   // Return whether this context is incognito. Default is false.
116   virtual bool IsOffTheRecord() const = 0;
117
118   // Returns the request context information associated with this context.  Call
119   // this only on the UI thread, since it can send notifications that should
120   // happen on the UI thread.
121   // TODO(creis): Remove this version in favor of the one below.
122   virtual net::URLRequestContextGetter* GetRequestContext() = 0;
123
124   // Returns the request context appropriate for the given renderer. If the
125   // renderer process doesn't have an associated installed app, or if the
126   // installed app doesn't have isolated storage, this is equivalent to calling
127   // GetRequestContext().
128   virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
129       int renderer_child_id) = 0;
130
131   // Returns the default request context for media resources associated with
132   // this context.
133   // TODO(creis): Remove this version in favor of the one below.
134   virtual net::URLRequestContextGetter* GetMediaRequestContext() = 0;
135
136   // Returns the request context for media resources associated with this
137   // context and renderer process.
138   virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
139       int renderer_child_id) = 0;
140   virtual net::URLRequestContextGetter*
141       GetMediaRequestContextForStoragePartition(
142           const base::FilePath& partition_path,
143           bool in_memory) = 0;
144
145   // Returns the resource context.
146   virtual ResourceContext* GetResourceContext() = 0;
147
148   // Returns the DownloadManagerDelegate for this context. This will be called
149   // once per context. The embedder owns the delegate and is responsible for
150   // ensuring that it outlives DownloadManager. It's valid to return NULL.
151   virtual DownloadManagerDelegate* GetDownloadManagerDelegate() = 0;
152
153   // Returns the guest manager for this context.
154   virtual BrowserPluginGuestManager* GetGuestManager() = 0;
155
156   // Returns a special storage policy implementation, or NULL.
157   virtual storage::SpecialStoragePolicy* GetSpecialStoragePolicy() = 0;
158
159   // Returns a push messaging service. The embedder owns the service, and is
160   // responsible for ensuring that it outlives RenderProcessHost. It's valid to
161   // return NULL.
162   virtual PushMessagingService* GetPushMessagingService() = 0;
163
164   // Returns the SSL host state decisions for this context. The context may
165   // return NULL, implementing the default exception storage strategy.
166   virtual SSLHostStateDelegate* GetSSLHostStateDelegate() = 0;
167 };
168
169 }  // namespace content
170
171 #if defined(COMPILER_GCC)
172 namespace BASE_HASH_NAMESPACE {
173
174 template<>
175 struct hash<content::BrowserContext*> {
176   std::size_t operator()(content::BrowserContext* const& p) const {
177     return reinterpret_cast<std::size_t>(p);
178   }
179 };
180
181 }  // namespace BASE_HASH_NAMESPACE
182 #endif
183
184 #endif  // CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_