103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// found in the LICENSE file. 403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "athena/content/public/app_registry.h" 603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "athena/content/app_activity_registry.h" 803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "base/logging.h" 903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 1003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace athena { 1103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 1203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class AppRegistryImpl : public AppRegistry { 1303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) public: 1403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) AppRegistryImpl(); 1503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual ~AppRegistryImpl(); 1603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 1703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // AppRegistry: 1803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual AppActivityRegistry* GetAppActivityRegistry( 1903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const std::string& app_id, 2003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) content::BrowserContext* browser_context) OVERRIDE; 2103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual int NumberOfApplications() const OVERRIDE { return app_list_.size(); } 2203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 2303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) private: 2403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void RemoveAppActivityRegistry( 2503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) AppActivityRegistry* registry) OVERRIDE; 2603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci std::vector<AppActivityRegistry*> app_list_; 2803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 2903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AppRegistryImpl); 3003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}; 3103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 3203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)namespace { 3303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 3403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)AppRegistryImpl* instance = NULL; 3503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 3603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} // namespace 3703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciAppRegistryImpl::AppRegistryImpl() { 391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} 4003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)AppRegistryImpl::~AppRegistryImpl() { 4103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK(app_list_.empty()); 4203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} 4303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 4403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)AppActivityRegistry* AppRegistryImpl::GetAppActivityRegistry( 4503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const std::string& app_id, 4603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) content::BrowserContext* browser_context) { 4703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Search for an existing proxy. 4803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) for (std::vector<AppActivityRegistry*>::iterator it = app_list_.begin(); 4903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) it != app_list_.end(); ++it) { 5003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if ((*it)->app_id() == app_id && 5103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) (*it)->browser_context() == browser_context) 5203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) return *it; 5303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 5403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 5503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Create and return a new application object. 5603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) AppActivityRegistry* app_activity_registry = 5703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) new AppActivityRegistry(app_id, browser_context); 5803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) app_list_.push_back(app_activity_registry); 5903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) return app_activity_registry; 6003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} 6103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 6203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)void AppRegistryImpl::RemoveAppActivityRegistry(AppActivityRegistry* registry) { 6303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) std::vector<AppActivityRegistry*>::iterator item = 6403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) std::find(app_list_.begin(), app_list_.end(), registry); 6503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) CHECK(item != app_list_.end()); 6603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) app_list_.erase(item); 6703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) delete registry; 6803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} 6903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 7003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// static 7103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)void AppRegistry::Create() { 7203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK(!instance); 7303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) instance = new AppRegistryImpl(); 7403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} 7503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 7603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// static 7703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)AppRegistry* AppRegistry::Get() { 7803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK(instance); 7903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) return instance; 8003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} 8103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 8203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// static 8303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)void AppRegistry::ShutDown() { 8403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK(instance); 8503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) delete instance; 8603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} 8703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 8803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)AppRegistry::AppRegistry() {} 8903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 9003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)AppRegistry::~AppRegistry() { 9103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) instance = NULL; 9203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} 9303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 9403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} // namespace athena 95