| 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_control_delegate.h" | |
| 9 #include "base/logging.h" | |
| 10 | |
| 11 namespace athena { | |
| 12 | |
| 13 class AppRegistryImpl : public AppRegistry { | |
| 14 public: | |
| 15 AppRegistryImpl(); | |
| 16 virtual ~AppRegistryImpl(); | |
| 17 | |
| 18 // AppRegistry: | |
| 19 virtual void SetDelegate(AppContentControlDelegate* delegate) OVERRIDE; | |
| 20 virtual AppContentControlDelegate* GetDelegate() OVERRIDE; | |
| 21 virtual AppActivityRegistry* GetAppActivityRegistry( | |
| 22 const std::string& app_id, | |
| 23 content::BrowserContext* browser_context) OVERRIDE; | |
| 24 virtual int NumberOfApplications() const OVERRIDE { return app_list_.size(); } | |
| 25 | |
| 26 private: | |
| 27 virtual void RemoveAppActivityRegistry( | |
| 28 AppActivityRegistry* registry) OVERRIDE; | |
| 29 | |
| 30 std::vector<AppActivityRegistry*> app_list_; | |
| 31 | |
| 32 scoped_ptr<AppContentControlDelegate> delegate_; | |
| 33 | |
| 34 DISALLOW_COPY_AND_ASSIGN(AppRegistryImpl); | |
| 35 }; | |
| 36 | |
| 37 namespace { | |
| 38 | |
| 39 AppRegistryImpl* instance = NULL; | |
| 40 | |
| 41 } // namespace | |
| 42 | |
| 43 AppRegistryImpl::AppRegistryImpl() : | |
| 44 delegate_(AppContentControlDelegate::CreateAppContentControlDelegate()) {} | |
| 45 | |
| 46 AppRegistryImpl::~AppRegistryImpl() { | |
| 47 DCHECK(app_list_.empty()); | |
| 48 } | |
| 49 | |
| 50 void AppRegistryImpl::SetDelegate(AppContentControlDelegate* delegate) { | |
| 51 DCHECK(delegate); | |
| 52 delegate_.reset(delegate); | |
| 53 } | |
| 54 | |
| 55 AppContentControlDelegate* AppRegistryImpl::GetDelegate() { | |
| 56 return delegate_.get(); | |
| 57 } | |
| 58 | |
| 59 AppActivityRegistry* AppRegistryImpl::GetAppActivityRegistry( | |
| 60 const std::string& app_id, | |
| 61 content::BrowserContext* browser_context) { | |
| 62 // Search for an existing proxy. | |
| 63 for (std::vector<AppActivityRegistry*>::iterator it = app_list_.begin(); | |
| 64 it != app_list_.end(); ++it) { | |
| 65 if ((*it)->app_id() == app_id && | |
| 66 (*it)->browser_context() == browser_context) | |
| 67 return *it; | |
| 68 } | |
| 69 | |
| 70 // Create and return a new application object. | |
| 71 AppActivityRegistry* app_activity_registry = | |
| 72 new AppActivityRegistry(app_id, browser_context); | |
| 73 app_list_.push_back(app_activity_registry); | |
| 74 return app_activity_registry; | |
| 75 } | |
| 76 | |
| 77 void AppRegistryImpl::RemoveAppActivityRegistry(AppActivityRegistry* registry) { | |
| 78 std::vector<AppActivityRegistry*>::iterator item = | |
| 79 std::find(app_list_.begin(), app_list_.end(), registry); | |
| 80 CHECK(item != app_list_.end()); | |
| 81 app_list_.erase(item); | |
| 82 } | |
| 83 | |
| 84 // static | |
| 85 void AppRegistry::Create() { | |
| 86 DCHECK(!instance); | |
| 87 instance = new AppRegistryImpl(); | |
| 88 } | |
| 89 | |
| 90 // static | |
| 91 AppRegistry* AppRegistry::Get() { | |
| 92 DCHECK(instance); | |
| 93 return instance; | |
| 94 } | |
| 95 | |
| 96 // static | |
| 97 void AppRegistry::ShutDown() { | |
| 98 DCHECK(instance); | |
| 99 delete instance; | |
| 100 } | |
| 101 | |
| 102 AppRegistry::AppRegistry() {} | |
| 103 | |
| 104 AppRegistry::~AppRegistry() { | |
| 105 instance = NULL; | |
| 106 } | |
| 107 | |
| 108 } // namespace athena | |
| OLD | NEW |