OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 #include "content/public/browser/graph/browser_context_dependency_manager.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "content/public/browser/browser_context.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 namespace { |
| 15 |
| 16 class ShutdownManager : public base::RefCounted<ShutdownManager> { |
| 17 public: |
| 18 explicit ShutdownManager(const base::Closure& completion_callback) |
| 19 : pending_(2), |
| 20 completion_callback_(completion_callback) {} |
| 21 |
| 22 void OnShutdownComplete() { |
| 23 --pending_; |
| 24 if (pending_ == 0) |
| 25 completion_callback_.Run(); |
| 26 } |
| 27 |
| 28 private: |
| 29 friend class base::RefCounted<ShutdownManager>; |
| 30 |
| 31 ~ShutdownManager() {} |
| 32 |
| 33 size_t pending_; |
| 34 base::Closure completion_callback_; |
| 35 }; |
| 36 |
| 37 } // namespace |
| 38 |
| 39 BrowserContextDependencyManager::BrowserContextDependencyManager( |
| 40 scoped_ptr<graph::KeyedDependencyManager<BrowserContext*> > |
| 41 default_dependency_manager, |
| 42 scoped_ptr<graph::KeyedDependencyManager<BrowserContext*> > |
| 43 off_the_record_dependency_manager) |
| 44 : default_dependency_manager_(default_dependency_manager.Pass()), |
| 45 off_the_record_dependency_manager_( |
| 46 off_the_record_dependency_manager.Pass()) {} |
| 47 |
| 48 BrowserContextDependencyManager::~BrowserContextDependencyManager() {} |
| 49 |
| 50 void BrowserContextDependencyManager::Startup( |
| 51 BrowserContext* browser_context, |
| 52 BrowserContextDependencyManager::StartupCallback completion_callback) { |
| 53 if (browser_context->IsOffTheRecord()) { |
| 54 off_the_record_dependency_manager_->Startup( |
| 55 browser_context, completion_callback); |
| 56 } else { |
| 57 default_dependency_manager_->Startup(browser_context, completion_callback); |
| 58 } |
| 59 } |
| 60 |
| 61 // static |
| 62 void BrowserContextDependencyManager::Shutdown( |
| 63 scoped_ptr<BrowserContextDependencyManager> instance, |
| 64 const base::Closure& completion_callback) { |
| 65 scoped_refptr<ShutdownManager> |
| 66 shutdown_manager(new ShutdownManager(completion_callback)); |
| 67 |
| 68 graph::KeyedDependencyManager<BrowserContext*>::Shutdown( |
| 69 instance->off_the_record_dependency_manager_.Pass(), |
| 70 base::Bind(&ShutdownManager::OnShutdownComplete, shutdown_manager)); |
| 71 graph::KeyedDependencyManager<BrowserContext*>::Shutdown( |
| 72 instance->default_dependency_manager_.Pass(), |
| 73 base::Bind(&ShutdownManager::OnShutdownComplete, shutdown_manager)); |
| 74 } |
| 75 |
| 76 } // namespace content |
OLD | NEW |