OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 "athena/content/public/app_registry.h" |
| 6 |
| 7 #include "athena/content/app_activity_registry.h" |
| 8 #include "athena/content/public/app_content_delegate.h" |
| 9 |
| 10 namespace athena { |
| 11 |
| 12 namespace { |
| 13 // The global instance. |
| 14 AppRegistry* instance = NULL; |
| 15 } |
| 16 |
| 17 void AppRegistry::Create() { |
| 18 DCHECK(!instance); |
| 19 instance = new AppRegistry(); |
| 20 } |
| 21 // static |
| 22 AppRegistry* AppRegistry::Get() { |
| 23 return instance; |
| 24 } |
| 25 |
| 26 // static |
| 27 void AppRegistry::ShutDown() { |
| 28 if (instance) |
| 29 delete instance; |
| 30 instance = NULL; |
| 31 } |
| 32 |
| 33 void AppRegistry::SetDelegate(AppContentDelegate* delegate) { |
| 34 DCHECK(delegate); |
| 35 delegate_.reset(delegate); |
| 36 } |
| 37 |
| 38 AppContentDelegate* AppRegistry::GetDelegate() { |
| 39 return delegate_.get(); |
| 40 } |
| 41 |
| 42 AppActivityRegistry* AppRegistry::GetAppActivityRegistry( |
| 43 const std::string& app_id, |
| 44 content::BrowserContext* browser_context) { |
| 45 // Search for an existing proxy. |
| 46 for (std::vector<AppActivityRegistry*>::iterator it = app_list_.begin(); |
| 47 it != app_list_.end(); ++it) { |
| 48 if ((*it)->app_id() == app_id && |
| 49 (*it)->browser_context() == browser_context) |
| 50 return *it; |
| 51 } |
| 52 |
| 53 // Create and return a new application object. |
| 54 AppActivityRegistry* app_activity_registry = |
| 55 new AppActivityRegistry(app_id, browser_context); |
| 56 app_list_.push_back(app_activity_registry); |
| 57 return app_activity_registry; |
| 58 } |
| 59 |
| 60 void AppRegistry::RemoveAppActivityRegistry(AppActivityRegistry* registry) { |
| 61 std::vector<AppActivityRegistry*>::iterator item = |
| 62 std::find(app_list_.begin(), app_list_.end(), registry); |
| 63 CHECK(item != app_list_.end()); |
| 64 app_list_.erase(item); |
| 65 } |
| 66 |
| 67 AppRegistry::AppRegistry() : delegate_(new AppContentDelegate) {} |
| 68 |
| 69 AppRegistry::~AppRegistry() { |
| 70 DCHECK(app_list_.empty()); |
| 71 } |
| 72 |
| 73 } // namespace athena |
OLD | NEW |