Index: content/public/browser/browser_context.h |
diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h |
index c7c664d097e5d5fe2a4c5546d84afadfceb22ebf..f38d38635051b57f00025813ab1300e1d5c75e23 100644 |
--- a/content/public/browser/browser_context.h |
+++ b/content/public/browser/browser_context.h |
@@ -5,11 +5,14 @@ |
#ifndef CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_ |
#define CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_ |
-#include "base/callback_forward.h" |
+#include "base/callback.h" |
+#include "base/compiler_specific.h" |
#include "base/hash_tables.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/supports_user_data.h" |
#include "content/common/content_export.h" |
+#include "content/public/browser/graph/browser_context_dependency_visitor.h" |
+#include "content/public/browser/graph/browser_context_dependency_visitor_impl.h" |
#include "ui/base/clipboard/clipboard_sourcetag.h" |
class GURL; |
@@ -22,6 +25,10 @@ namespace fileapi { |
class ExternalMountPoints; |
} |
+namespace graph { |
+class DependencyManagerInstance; |
+} |
+ |
namespace net { |
class URLRequestContextGetter; |
} |
@@ -154,6 +161,64 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { |
// Returns a special storage policy implementation, or NULL. |
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() = 0; |
+ |
+ // Retrieves a Component instance associated with the BrowserContext. |
+ // |completion_callback| will be invoked when the Component instance is fully |
+ // initialized, or during Profile shutdown (with a NULL Component pointer) if |
+ // the initialization has not completed by that time. |
+ // This should only be called on the UI thread. |completion_callback| will |
+ // always be called back on the UI thread. |
+ template <typename Component> |
+ void Get(base::Callback<void(Component*)> completion_callback) { |
+ VisitDependencyManager(scoped_ptr<BrowserContextDependencyVisitor>( |
+ new BrowserContextDependencyVisitorImpl<Component>( |
+ completion_callback))); |
+ } |
+ |
+ // Attempts to synchronously retrieve a Component instance associated with the |
+ // BrowserContext. If the component is available, the return value will be |
+ // |true|, and |component_storage| will contain the component instance. If the |
+ // component is not available, then the return value will be |false| and |
+ // |component_storage| will contain a NULL pointer. |
+ // It is the callers responsibility to check that the component was |
+ // successfully retrieved before using it. |
+ template <typename Component> |
+ bool GetNow(Component** component_storage) WARN_UNUSED_RESULT { |
+ graph::DependencyManagerInstance* manager = GetDependencyManager(); |
+ if (!manager) { |
+ *component_storage = NULL; |
+ return false; |
+ } |
+ |
+ return manager->GetNow<Component>(component_storage); |
+ } |
+ |
+ // Attempts to synchronously retrieve a Component instance associated with the |
+ // BrowserContext. If the component is available, the return value will be |
+ // |true|, and |component_storage| will contain the component instance. If the |
+ // component is not available, then the return value will be |false| and |
+ // |component_storage| will contain a NULL pointer. |
+ // It is the callers responsibility to check that the component was |
+ // successfully retrieved before using it. |
+ template <typename Component> bool IsDefined() { |
+ graph::DependencyManagerInstance* manager = GetDependencyManager(); |
+ if (!manager) { |
+ return false; |
+ } |
+ |
+ return manager->IsDefined<Component>(); |
+ } |
+ |
+ private: |
+ // Executes visitor against the DependencyManagerInstance associated with |
+ // this BrowserContext, possibly asynchronously if the |
+ // DependencyManagerInstance is not fully initialized yet. |
+ // May be executed against a NULL DependencyManagerInstance pointer if |
+ // shutdown begins before the DependencyManagerInstance is fully initialized. |
+ virtual void VisitDependencyManager( |
+ scoped_ptr<content::BrowserContextDependencyVisitor> visitor) = 0; |
+ |
+ virtual graph::DependencyManagerInstance* GetDependencyManager() = 0; |
}; |
} // namespace content |