| Index: athena/content/app_registry.cc
|
| diff --git a/athena/content/app_registry.cc b/athena/content/app_registry.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..329151d46ce70dad4cfcf831c65ec3f1f61712b7
|
| --- /dev/null
|
| +++ b/athena/content/app_registry.cc
|
| @@ -0,0 +1,73 @@
|
| +// 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_delegate.h"
|
| +
|
| +namespace athena {
|
| +
|
| +namespace {
|
| +// The global instance.
|
| +AppRegistry* instance = NULL;
|
| +}
|
| +
|
| +void AppRegistry::Create() {
|
| + DCHECK(!instance);
|
| + instance = new AppRegistry();
|
| +}
|
| +// static
|
| +AppRegistry* AppRegistry::Get() {
|
| + return instance;
|
| +}
|
| +
|
| +// static
|
| +void AppRegistry::ShutDown() {
|
| + if (instance)
|
| + delete instance;
|
| + instance = NULL;
|
| +}
|
| +
|
| +void AppRegistry::SetDelegate(AppContentDelegate* delegate) {
|
| + DCHECK(delegate);
|
| + delegate_.reset(delegate);
|
| +}
|
| +
|
| +AppContentDelegate* AppRegistry::GetDelegate() {
|
| + return delegate_.get();
|
| +}
|
| +
|
| +AppActivityRegistry* AppRegistry::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 AppRegistry::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);
|
| +}
|
| +
|
| +AppRegistry::AppRegistry() : delegate_(new AppContentDelegate) {}
|
| +
|
| +AppRegistry::~AppRegistry() {
|
| + DCHECK(app_list_.empty());
|
| +}
|
| +
|
| +} // namespace athena
|
|
|