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