Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(970)

Unified Diff: content/public/browser/graph/browser_context_dependency_manager.cc

Issue 18796007: Content API changes to integrate base/graph. (Closed) Base URL: marinoni.mon:/usr/local/google/src/chromium/src@base_graph_review
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/browser/graph/browser_context_dependency_manager.cc
diff --git a/content/public/browser/graph/browser_context_dependency_manager.cc b/content/public/browser/graph/browser_context_dependency_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7e2fe3811ce9fc8d38161922bc55764d50ceab27
--- /dev/null
+++ b/content/public/browser/graph/browser_context_dependency_manager.cc
@@ -0,0 +1,76 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/browser/graph/browser_context_dependency_manager.h"
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "content/public/browser/browser_context.h"
+
+namespace content {
+
+namespace {
+
+class ShutdownManager : public base::RefCounted<ShutdownManager> {
+ public:
+ explicit ShutdownManager(const base::Closure& completion_callback)
+ : pending_(2),
+ completion_callback_(completion_callback) {}
+
+ void OnShutdownComplete() {
+ --pending_;
+ if (pending_ == 0)
+ completion_callback_.Run();
+ }
+
+ private:
+ friend class base::RefCounted<ShutdownManager>;
+
+ ~ShutdownManager() {}
+
+ size_t pending_;
+ base::Closure completion_callback_;
+};
+
+} // namespace
+
+BrowserContextDependencyManager::BrowserContextDependencyManager(
+ scoped_ptr<graph::KeyedDependencyManager<BrowserContext*> >
+ default_dependency_manager,
+ scoped_ptr<graph::KeyedDependencyManager<BrowserContext*> >
+ off_the_record_dependency_manager)
+ : default_dependency_manager_(default_dependency_manager.Pass()),
+ off_the_record_dependency_manager_(
+ off_the_record_dependency_manager.Pass()) {}
+
+BrowserContextDependencyManager::~BrowserContextDependencyManager() {}
+
+void BrowserContextDependencyManager::Startup(
+ BrowserContext* browser_context,
+ BrowserContextDependencyManager::StartupCallback completion_callback) {
+ if (browser_context->IsOffTheRecord()) {
+ off_the_record_dependency_manager_->Startup(
+ browser_context, completion_callback);
+ } else {
+ default_dependency_manager_->Startup(browser_context, completion_callback);
+ }
+}
+
+// static
+void BrowserContextDependencyManager::Shutdown(
+ scoped_ptr<BrowserContextDependencyManager> instance,
+ const base::Closure& completion_callback) {
+ scoped_refptr<ShutdownManager>
+ shutdown_manager(new ShutdownManager(completion_callback));
+
+ graph::KeyedDependencyManager<BrowserContext*>::Shutdown(
+ instance->off_the_record_dependency_manager_.Pass(),
+ base::Bind(&ShutdownManager::OnShutdownComplete, shutdown_manager));
+ graph::KeyedDependencyManager<BrowserContext*>::Shutdown(
+ instance->default_dependency_manager_.Pass(),
+ base::Bind(&ShutdownManager::OnShutdownComplete, shutdown_manager));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698