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 class AppRegistryImpl : public AppRegistry { |
| 13 public: |
| 14 AppRegistryImpl(); |
| 15 virtual ~AppRegistryImpl(); |
| 16 |
| 17 // Overrides the used AppContentDelegate. This function will own it |
| 18 // afterwards. A value of NULL is invalid. |
| 19 virtual void SetDelegate(AppContentDelegate* delegate) OVERRIDE; |
| 20 |
| 21 // Retrieves the application content delegate. The ownership remains with this |
| 22 // class. |
| 23 virtual AppContentDelegate* GetDelegate() OVERRIDE; |
| 24 |
| 25 // Returns an |AppActivityRegistry| for a given activity |app_id| and |
| 26 // |browser_context|. |
| 27 virtual AppActivityRegistry* GetAppActivityRegistry( |
| 28 const std::string& app_id, |
| 29 content::BrowserContext* browser_context) OVERRIDE; |
| 30 |
| 31 // Returns the number of registered applications. |
| 32 virtual int NumberOfApplications() const OVERRIDE { return app_list_.size(); } |
| 33 |
| 34 protected: |
| 35 // Only the |AppActivityRegistry| can remove itself. |
| 36 friend AppActivityRegistry; |
| 37 |
| 38 // Removes an activity registry for an application from the list of known |
| 39 // applications. |
| 40 virtual void RemoveAppActivityRegistry( |
| 41 AppActivityRegistry* registry) OVERRIDE; |
| 42 |
| 43 private: |
| 44 std::vector<AppActivityRegistry*> app_list_; |
| 45 |
| 46 scoped_ptr<AppContentDelegate> delegate_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(AppRegistryImpl); |
| 49 }; |
| 50 |
| 51 namespace { |
| 52 |
| 53 // The global instance. |
| 54 AppRegistryImpl* instance = NULL; |
| 55 |
| 56 } // namespace |
| 57 |
| 58 AppRegistryImpl::AppRegistryImpl() : delegate_(new AppContentDelegate) {} |
| 59 |
| 60 AppRegistryImpl::~AppRegistryImpl() { |
| 61 DCHECK(app_list_.empty()); |
| 62 } |
| 63 |
| 64 void AppRegistryImpl::SetDelegate(AppContentDelegate* delegate) { |
| 65 DCHECK(delegate); |
| 66 delegate_.reset(delegate); |
| 67 } |
| 68 |
| 69 AppContentDelegate* AppRegistryImpl::GetDelegate() { |
| 70 return delegate_.get(); |
| 71 } |
| 72 |
| 73 AppActivityRegistry* AppRegistryImpl::GetAppActivityRegistry( |
| 74 const std::string& app_id, |
| 75 content::BrowserContext* browser_context) { |
| 76 // Search for an existing proxy. |
| 77 for (std::vector<AppActivityRegistry*>::iterator it = app_list_.begin(); |
| 78 it != app_list_.end(); ++it) { |
| 79 if ((*it)->app_id() == app_id && |
| 80 (*it)->browser_context() == browser_context) |
| 81 return *it; |
| 82 } |
| 83 |
| 84 // Create and return a new application object. |
| 85 AppActivityRegistry* app_activity_registry = |
| 86 new AppActivityRegistry(app_id, browser_context); |
| 87 app_list_.push_back(app_activity_registry); |
| 88 return app_activity_registry; |
| 89 } |
| 90 |
| 91 void AppRegistryImpl::RemoveAppActivityRegistry(AppActivityRegistry* registry) { |
| 92 std::vector<AppActivityRegistry*>::iterator item = |
| 93 std::find(app_list_.begin(), app_list_.end(), registry); |
| 94 CHECK(item != app_list_.end()); |
| 95 app_list_.erase(item); |
| 96 } |
| 97 |
| 98 // static |
| 99 void AppRegistry::Create() { |
| 100 DCHECK(!instance); |
| 101 instance = new AppRegistryImpl(); |
| 102 } |
| 103 |
| 104 // static |
| 105 AppRegistry* AppRegistry::Get() { |
| 106 return instance; |
| 107 } |
| 108 |
| 109 // static |
| 110 void AppRegistry::ShutDown() { |
| 111 if (instance) |
| 112 delete instance; |
| 113 instance = NULL; |
| 114 } |
| 115 |
| 116 AppRegistry::AppRegistry() {} |
| 117 AppRegistry::~AppRegistry() {} |
| 118 |
| 119 } // namespace athena |
OLD | NEW |