Update To 11.40.268.0
[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(PushDeliveryStatus)>& callback);
98
99   static void NotifyWillBeDestroyed(BrowserContext* browser_context);
100
101   // Ensures that the corresponding ResourceContext is initialized. Normally the
102   // BrowserContext initializs the corresponding getters when its objects are
103   // created, but if the embedder wants to pass the ResourceContext to another
104   // thread before they use BrowserContext, they should call this to make sure
105   // that the ResourceContext is ready.
106   static void EnsureResourceContextInitialized(BrowserContext* browser_context);
107
108   // Tells the HTML5 objects on this context to persist their session state
109   // across the next restart.
110   static void SaveSessionState(BrowserContext* browser_context);
111
112   ~BrowserContext() override;
113
114   // Returns the path of the directory where this context's data is stored.
115   virtual base::FilePath GetPath() const = 0;
116
117   // Return whether this context is incognito. Default is false.
118   virtual bool IsOffTheRecord() const = 0;
119
120   // Returns the request context information associated with this context.  Call
121   // this only on the UI thread, since it can send notifications that should
122   // happen on the UI thread.
123   // TODO(creis): Remove this version in favor of the one below.
124   virtual net::URLRequestContextGetter* GetRequestContext() = 0;
125
126   // Returns the request context appropriate for the given renderer. If the
127   // renderer process doesn't have an associated installed app, or if the
128   // installed app doesn't have isolated storage, this is equivalent to calling
129   // GetRequestContext().
130   virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
131       int renderer_child_id) = 0;
132
133   // Returns the default request context for media resources associated with
134   // this context.
135   // TODO(creis): Remove this version in favor of the one below.
136   virtual net::URLRequestContextGetter* GetMediaRequestContext() = 0;
137
138   // Returns the request context for media resources associated with this
139   // context and renderer process.
140   virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
141       int renderer_child_id) = 0;
142   virtual net::URLRequestContextGetter*
143       GetMediaRequestContextForStoragePartition(
144           const base::FilePath& partition_path,
145           bool in_memory) = 0;
146
147   // Returns the resource context.
148   virtual ResourceContext* GetResourceContext() = 0;
149
150   // Returns the DownloadManagerDelegate for this context. This will be called
151   // once per context. The embedder owns the delegate and is responsible for
152   // ensuring that it outlives DownloadManager. It's valid to return NULL.
153   virtual DownloadManagerDelegate* GetDownloadManagerDelegate() = 0;
154
155   // Returns the guest manager for this context.
156   virtual BrowserPluginGuestManager* GetGuestManager() = 0;
157
158   // Returns a special storage policy implementation, or NULL.
159   virtual storage::SpecialStoragePolicy* GetSpecialStoragePolicy() = 0;
160
161   // Returns a push messaging service. The embedder owns the service, and is
162   // responsible for ensuring that it outlives RenderProcessHost. It's valid to
163   // return NULL.
164   virtual PushMessagingService* GetPushMessagingService() = 0;
165
166   // Returns the SSL host state decisions for this context. The context may
167   // return NULL, implementing the default exception storage strategy.
168   virtual SSLHostStateDelegate* GetSSLHostStateDelegate() = 0;
169 };
170
171 }  // namespace content
172
173 #endif  // CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_