Chromium Code Reviews| Index: athena/content/app_registry_impl.cc |
| diff --git a/athena/content/app_registry_impl.cc b/athena/content/app_registry_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..03e10511cdc55439d89ddf37f56a85b442f0d660 |
| --- /dev/null |
| +++ b/athena/content/app_registry_impl.cc |
| @@ -0,0 +1,110 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "athena/content/public/app_registry.h" |
| + |
| +#include "athena/content/app_activity_registry.h" |
| +#include "athena/content/public/app_content_control_delegate.h" |
| + |
| +namespace athena { |
| + |
| +class AppRegistryImpl : public AppRegistry { |
| + public: |
| + AppRegistryImpl(); |
| + virtual ~AppRegistryImpl(); |
| + |
|
oshima
2014/08/19 21:22:25
// AppRegistry:
I think all impl methods can be p
Mr4D (OOO till 08-26)
2014/08/20 14:34:40
Added comment.
However - moving private here make
oshima
2014/08/20 19:51:49
I always prefer to limit the exposure of API. This
Mr4D (OOO till 08-26)
2014/08/20 22:34:21
Acknowledged.
|
| + virtual void SetDelegate(AppContentControlDelegate* delegate) OVERRIDE; |
| + virtual AppContentControlDelegate* GetDelegate() OVERRIDE; |
| + virtual AppActivityRegistry* GetAppActivityRegistry( |
| + const std::string& app_id, |
| + content::BrowserContext* browser_context) OVERRIDE; |
| + virtual int NumberOfApplications() const OVERRIDE { return app_list_.size(); } |
| + |
| + protected: |
|
oshima
2014/08/20 19:51:49
why not private: ?
Mr4D (OOO till 08-26)
2014/08/20 22:34:22
Done.
|
| + // Only the |AppActivityRegistry| can remove itself. |
| + friend AppActivityRegistry; |
| + |
| + // Removes an activity registry for an application from the list of known |
| + // applications. |
| + virtual void RemoveAppActivityRegistry( |
| + AppActivityRegistry* registry) OVERRIDE; |
| + |
| + private: |
| + std::vector<AppActivityRegistry*> app_list_; |
| + |
| + scoped_ptr<AppContentControlDelegate> delegate_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AppRegistryImpl); |
| +}; |
| + |
| +namespace { |
| + |
| +// The global instance. |
|
oshima
2014/08/19 21:22:25
"global" is a bit mislaeding as this is file scope
Mr4D (OOO till 08-26)
2014/08/20 14:34:40
Done.
|
| +AppRegistryImpl* instance = NULL; |
| + |
| +} // namespace |
| + |
| +AppRegistryImpl::AppRegistryImpl() : |
| + delegate_(AppContentControlDelegate::CreateAppContentControlDelegate()) {} |
| + |
| +AppRegistryImpl::~AppRegistryImpl() { |
| + DCHECK(app_list_.empty()); |
| +} |
| + |
| +void AppRegistryImpl::SetDelegate(AppContentControlDelegate* delegate) { |
| + DCHECK(delegate); |
| + delegate_.reset(delegate); |
| +} |
| + |
| +AppContentControlDelegate* AppRegistryImpl::GetDelegate() { |
| + return delegate_.get(); |
| +} |
| + |
| +AppActivityRegistry* AppRegistryImpl::GetAppActivityRegistry( |
| + const std::string& app_id, |
| + content::BrowserContext* browser_context) { |
| + // Search for an existing proxy. |
| + for (std::vector<AppActivityRegistry*>::iterator it = app_list_.begin(); |
| + it != app_list_.end(); ++it) { |
| + if ((*it)->app_id() == app_id && |
| + (*it)->browser_context() == browser_context) |
| + return *it; |
| + } |
| + |
| + // Create and return a new application object. |
| + AppActivityRegistry* app_activity_registry = |
| + new AppActivityRegistry(app_id, browser_context); |
| + app_list_.push_back(app_activity_registry); |
| + return app_activity_registry; |
| +} |
| + |
| +void AppRegistryImpl::RemoveAppActivityRegistry(AppActivityRegistry* registry) { |
| + std::vector<AppActivityRegistry*>::iterator item = |
| + std::find(app_list_.begin(), app_list_.end(), registry); |
| + CHECK(item != app_list_.end()); |
| + app_list_.erase(item); |
| +} |
| + |
| +// static |
| +void AppRegistry::Create() { |
| + DCHECK(!instance); |
| + instance = new AppRegistryImpl(); |
| +} |
| + |
| +// static |
| +AppRegistry* AppRegistry::Get() { |
| + return instance; |
| +} |
| + |
| +// static |
| +void AppRegistry::ShutDown() { |
| + if (instance) |
| + delete instance; |
| + instance = NULL; |
| +} |
| + |
| +AppRegistry::AppRegistry() {} |
| +AppRegistry::~AppRegistry() {} |
| + |
| +} // namespace athena |