Commit 07f59264 authored by oshima's avatar oshima Committed by Commit bot

Consolidate AppControllDelegate to ExtensionsDelegate.

* Prep for athena on chrome.

Another notable change:
* pass app_id to AppActivity. it's known at creation time.

Note: this depends on https://codereview.chromium.org/505273002/

BUG=397167

Review URL: https://codereview.chromium.org/501093003

Cr-Commit-Position: refs/heads/master@{#292264}
parent 86c315c3
...@@ -44,8 +44,8 @@ class ATHENA_EXPORT ActivityFactory { ...@@ -44,8 +44,8 @@ class ATHENA_EXPORT ActivityFactory {
// The returned activity should own |app_window|. // The returned activity should own |app_window|.
// TODO(oshima): Consolidate these two methods to create AppActivity // TODO(oshima): Consolidate these two methods to create AppActivity
// once crbug.com/403726 is finished. // once crbug.com/403726 is finished.
virtual Activity* CreateAppActivity( virtual Activity* CreateAppActivity(extensions::ShellAppWindow* app_window,
extensions::ShellAppWindow* app_window) = 0; const std::string& id) = 0;
// Create an activity of an app with |app_window| for chrome environment. // Create an activity of an app with |app_window| for chrome environment.
virtual Activity* CreateAppActivity(apps::AppWindow* app_window) = 0; virtual Activity* CreateAppActivity(apps::AppWindow* app_window) = 0;
......
...@@ -129,8 +129,6 @@ ...@@ -129,8 +129,6 @@
'content/app_registry_impl.cc', 'content/app_registry_impl.cc',
'content/content_activity_factory.cc', 'content/content_activity_factory.cc',
'content/content_app_model_builder.cc', 'content/content_app_model_builder.cc',
'content/delegate/app_content_control_delegate_impl.cc',
'content/public/app_content_control_delegate.h',
'content/public/app_registry.h', 'content/public/app_registry.h',
'content/content_activity_factory.h', 'content/content_activity_factory.h',
'content/public/content_activity_factory_creator.h', 'content/public/content_activity_factory_creator.h',
...@@ -181,7 +179,6 @@ ...@@ -181,7 +179,6 @@
'resources/athena_resources.gyp:athena_resources', 'resources/athena_resources.gyp:athena_resources',
], ],
'sources': [ 'sources': [
'content/public/app_content_control_delegate.h',
'extensions/test/test_extensions_delegate.cc', 'extensions/test/test_extensions_delegate.cc',
'test/athena_test_base.cc', 'test/athena_test_base.cc',
'test/athena_test_base.h', 'test/athena_test_base.h',
...@@ -191,7 +188,6 @@ ...@@ -191,7 +188,6 @@
'test/sample_activity.h', 'test/sample_activity.h',
'test/sample_activity_factory.cc', 'test/sample_activity_factory.cc',
'test/sample_activity_factory.h', 'test/sample_activity_factory.h',
'test/test_app_content_control_delegate_impl.cc',
'test/test_app_model_builder.cc', 'test/test_app_model_builder.cc',
'test/test_app_model_builder.h', 'test/test_app_model_builder.h',
'wm/test/window_manager_impl_test_api.cc', 'wm/test/window_manager_impl_test_api.cc',
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "athena/activity/public/activity_manager.h" #include "athena/activity/public/activity_manager.h"
#include "athena/content/app_activity_registry.h" #include "athena/content/app_activity_registry.h"
#include "athena/content/public/app_content_control_delegate.h"
#include "athena/content/public/app_registry.h" #include "athena/content/public/app_registry.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "ui/views/controls/webview/webview.h" #include "ui/views/controls/webview/webview.h"
...@@ -15,8 +14,9 @@ ...@@ -15,8 +14,9 @@
namespace athena { namespace athena {
// TODO(mukai): specifies the same accelerators of WebActivity. // TODO(mukai): specifies the same accelerators of WebActivity.
AppActivity::AppActivity() AppActivity::AppActivity(const std::string& app_id)
: web_view_(NULL), : app_id_(app_id),
web_view_(NULL),
current_state_(ACTIVITY_UNLOADED), current_state_(ACTIVITY_UNLOADED),
app_activity_registry_(NULL) { app_activity_registry_(NULL) {
} }
...@@ -120,6 +120,7 @@ views::View* AppActivity::GetContentsView() { ...@@ -120,6 +120,7 @@ views::View* AppActivity::GetContentsView() {
SetCurrentState(ACTIVITY_INVISIBLE); SetCurrentState(ACTIVITY_INVISIBLE);
Observe(web_contents); Observe(web_contents);
overview_mode_image_ = gfx::ImageSkia(); overview_mode_image_ = gfx::ImageSkia();
RegisterActivity();
} }
return web_view_; return web_view_;
} }
...@@ -142,13 +143,6 @@ void AppActivity::DidUpdateFaviconURL( ...@@ -142,13 +143,6 @@ void AppActivity::DidUpdateFaviconURL(
ActivityManager::Get()->UpdateActivity(this); ActivityManager::Get()->UpdateActivity(this);
} }
void AppActivity::DidStartNavigationToPendingEntry(
const GURL& url,
content::NavigationController::ReloadType reload_type) {
if (!app_activity_registry_)
RegisterActivity();
}
// Register an |activity| with an application. // Register an |activity| with an application.
// Note: This should only get called once for an |app_window| of the // Note: This should only get called once for an |app_window| of the
// |activity|. // |activity|.
...@@ -157,8 +151,7 @@ void AppActivity::RegisterActivity() { ...@@ -157,8 +151,7 @@ void AppActivity::RegisterActivity() {
AppRegistry* app_registry = AppRegistry::Get(); AppRegistry* app_registry = AppRegistry::Get();
// Get the application's registry. // Get the application's registry.
app_activity_registry_ = app_registry->GetAppActivityRegistry( app_activity_registry_ = app_registry->GetAppActivityRegistry(
app_registry->GetDelegate()->GetApplicationID(web_contents), app_id_, web_contents->GetBrowserContext());
web_contents->GetBrowserContext());
DCHECK(app_activity_registry_); DCHECK(app_activity_registry_);
// Register the activity. // Register the activity.
app_activity_registry_->RegisterAppActivity(this); app_activity_registry_->RegisterAppActivity(this);
......
...@@ -27,7 +27,7 @@ class AppActivity : public Activity, ...@@ -27,7 +27,7 @@ class AppActivity : public Activity,
public ActivityViewModel, public ActivityViewModel,
public content::WebContentsObserver { public content::WebContentsObserver {
public: public:
AppActivity(); explicit AppActivity(const std::string& app_id);
virtual ~AppActivity(); virtual ~AppActivity();
// Activity: // Activity:
...@@ -53,9 +53,6 @@ class AppActivity : public Activity, ...@@ -53,9 +53,6 @@ class AppActivity : public Activity,
bool explicit_set) OVERRIDE; bool explicit_set) OVERRIDE;
virtual void DidUpdateFaviconURL( virtual void DidUpdateFaviconURL(
const std::vector<content::FaviconURL>& candidates) OVERRIDE; const std::vector<content::FaviconURL>& candidates) OVERRIDE;
virtual void DidStartNavigationToPendingEntry(
const GURL& url,
content::NavigationController::ReloadType reload_type) OVERRIDE;
protected: protected:
virtual content::WebContents* GetWebContents() = 0; virtual content::WebContents* GetWebContents() = 0;
...@@ -64,6 +61,8 @@ class AppActivity : public Activity, ...@@ -64,6 +61,8 @@ class AppActivity : public Activity,
// Register this activity with its application. // Register this activity with its application.
void RegisterActivity(); void RegisterActivity();
const std::string app_id_;
views::WebView* web_view_; views::WebView* web_view_;
// The current state for this activity. // The current state for this activity.
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include "athena/activity/public/activity_manager.h" #include "athena/activity/public/activity_manager.h"
#include "athena/content/app_activity.h" #include "athena/content/app_activity.h"
#include "athena/content/app_activity_proxy.h" #include "athena/content/app_activity_proxy.h"
#include "athena/content/public/app_content_control_delegate.h"
#include "athena/content/public/app_registry.h" #include "athena/content/public/app_registry.h"
#include "athena/extensions/public/extensions_delegate.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -91,8 +91,7 @@ void AppActivityRegistry::Unload() { ...@@ -91,8 +91,7 @@ void AppActivityRegistry::Unload() {
MoveBeforeMruApplicationWindow(unloaded_activity_proxy_->GetWindow()); MoveBeforeMruApplicationWindow(unloaded_activity_proxy_->GetWindow());
// Unload the application. This operation will be asynchronous. // Unload the application. This operation will be asynchronous.
if (!AppRegistry::Get()->GetDelegate()->UnloadApplication(app_id_, if (!ExtensionsDelegate::Get(browser_context_)->UnloadApp(app_id_)) {
browser_context_)) {
while(!activity_list_.empty()) while(!activity_list_.empty())
delete activity_list_.back(); delete activity_list_.back();
} }
...@@ -110,8 +109,7 @@ void AppActivityRegistry::ProxyDestroyed(AppActivityProxy* proxy) { ...@@ -110,8 +109,7 @@ void AppActivityRegistry::ProxyDestroyed(AppActivityProxy* proxy) {
void AppActivityRegistry::RestartApplication(AppActivityProxy* proxy) { void AppActivityRegistry::RestartApplication(AppActivityProxy* proxy) {
DCHECK_EQ(unloaded_activity_proxy_, proxy); DCHECK_EQ(unloaded_activity_proxy_, proxy);
// Restart the application. // Restart the application.
AppRegistry::Get()->GetDelegate()->RestartApplication(app_id_, ExtensionsDelegate::Get(browser_context_)->LaunchApp(app_id_);
browser_context_);
// Remove the activity from the Activity manager. // Remove the activity from the Activity manager.
ActivityManager::Get()->RemoveActivity(unloaded_activity_proxy_); ActivityManager::Get()->RemoveActivity(unloaded_activity_proxy_);
delete unloaded_activity_proxy_; // Will call ProxyDestroyed. delete unloaded_activity_proxy_; // Will call ProxyDestroyed.
......
This diff is collapsed.
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "athena/content/public/app_registry.h" #include "athena/content/public/app_registry.h"
#include "athena/content/app_activity_registry.h" #include "athena/content/app_activity_registry.h"
#include "athena/content/public/app_content_control_delegate.h"
#include "base/logging.h" #include "base/logging.h"
namespace athena { namespace athena {
...@@ -16,8 +15,6 @@ class AppRegistryImpl : public AppRegistry { ...@@ -16,8 +15,6 @@ class AppRegistryImpl : public AppRegistry {
virtual ~AppRegistryImpl(); virtual ~AppRegistryImpl();
// AppRegistry: // AppRegistry:
virtual void SetDelegate(AppContentControlDelegate* delegate) OVERRIDE;
virtual AppContentControlDelegate* GetDelegate() OVERRIDE;
virtual AppActivityRegistry* GetAppActivityRegistry( virtual AppActivityRegistry* GetAppActivityRegistry(
const std::string& app_id, const std::string& app_id,
content::BrowserContext* browser_context) OVERRIDE; content::BrowserContext* browser_context) OVERRIDE;
...@@ -27,9 +24,7 @@ class AppRegistryImpl : public AppRegistry { ...@@ -27,9 +24,7 @@ class AppRegistryImpl : public AppRegistry {
virtual void RemoveAppActivityRegistry( virtual void RemoveAppActivityRegistry(
AppActivityRegistry* registry) OVERRIDE; AppActivityRegistry* registry) OVERRIDE;
std::vector<AppActivityRegistry*> app_list_; std::vector<AppActivityRegistry*> app_list_;
scoped_ptr<AppContentControlDelegate> delegate_;
DISALLOW_COPY_AND_ASSIGN(AppRegistryImpl); DISALLOW_COPY_AND_ASSIGN(AppRegistryImpl);
}; };
...@@ -40,22 +35,12 @@ AppRegistryImpl* instance = NULL; ...@@ -40,22 +35,12 @@ AppRegistryImpl* instance = NULL;
} // namespace } // namespace
AppRegistryImpl::AppRegistryImpl() : AppRegistryImpl::AppRegistryImpl() {
delegate_(AppContentControlDelegate::CreateAppContentControlDelegate()) {} }
AppRegistryImpl::~AppRegistryImpl() { AppRegistryImpl::~AppRegistryImpl() {
DCHECK(app_list_.empty()); DCHECK(app_list_.empty());
} }
void AppRegistryImpl::SetDelegate(AppContentControlDelegate* delegate) {
DCHECK(delegate);
delegate_.reset(delegate);
}
AppContentControlDelegate* AppRegistryImpl::GetDelegate() {
return delegate_.get();
}
AppActivityRegistry* AppRegistryImpl::GetAppActivityRegistry( AppActivityRegistry* AppRegistryImpl::GetAppActivityRegistry(
const std::string& app_id, const std::string& app_id,
content::BrowserContext* browser_context) { content::BrowserContext* browser_context) {
......
...@@ -18,8 +18,8 @@ class ContentActivityFactory : public ActivityFactory { ...@@ -18,8 +18,8 @@ class ContentActivityFactory : public ActivityFactory {
// Overridden from ActivityFactory: // Overridden from ActivityFactory:
virtual Activity* CreateWebActivity(content::BrowserContext* browser_context, virtual Activity* CreateWebActivity(content::BrowserContext* browser_context,
const GURL& url) OVERRIDE; const GURL& url) OVERRIDE;
virtual Activity* CreateAppActivity( virtual Activity* CreateAppActivity(extensions::ShellAppWindow* app_window,
extensions::ShellAppWindow* app_window) OVERRIDE; const std::string& app_id) OVERRIDE;
virtual Activity* CreateAppActivity(apps::AppWindow* app_window) OVERRIDE; virtual Activity* CreateAppActivity(apps::AppWindow* app_window) OVERRIDE;
private: private:
......
// 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.
#ifndef ATHENA_CONTENT_PUBLIC_APP_CONTENT_CONTROL_DLEGATE_H_
#define ATHENA_CONTENT_PUBLIC_APP_CONTENT_CONTROL_DLEGATE_H_
#include <string>
#include "base/macros.h"
namespace content {
class BrowserContext;
class WebContents;
}
namespace athena {
// The application content delegate which can be overwritten for unit tests to
// eliminate dependencies to the content / browser system.
class AppContentControlDelegate {
public:
static AppContentControlDelegate* CreateAppContentControlDelegate();
AppContentControlDelegate() {}
virtual ~AppContentControlDelegate() {}
// Unload an application. Returns true when unloaded.
virtual bool UnloadApplication(const std::string& app_id,
content::BrowserContext* browser_context) = 0;
// Restarts an application. Returns true when the restart was initiated.
virtual bool RestartApplication(const std::string& app_id,
content::BrowserContext* browser_context) = 0;
// Returns the application ID (or an empty string) for a given web content.
virtual std::string GetApplicationID(content::WebContents* web_contents) = 0;
};
} // namespace athena
#endif // ATHENA_CONTENT_PUBLIC_APP_CONTENT_CONTROL_DLEGATE_H_
...@@ -19,7 +19,6 @@ class BrowserContext; ...@@ -19,7 +19,6 @@ class BrowserContext;
namespace athena { namespace athena {
class AppActivityRegistry; class AppActivityRegistry;
class AppContentControlDelegate;
class AppRegistryImpl; class AppRegistryImpl;
// This class holds for each application, held by a user, a list of activities. // This class holds for each application, held by a user, a list of activities.
...@@ -37,14 +36,6 @@ class ATHENA_EXPORT AppRegistry { ...@@ -37,14 +36,6 @@ class ATHENA_EXPORT AppRegistry {
// Shuts down the registry (all applications should be shut down by then). // Shuts down the registry (all applications should be shut down by then).
static void ShutDown(); static void ShutDown();
// Overrides the used AppContentDelegate. This function will own it
// afterwards. A value of NULL is invalid.
virtual void SetDelegate(AppContentControlDelegate* delegate) = 0;
// Retrieves the application content delegate. The ownership remains with this
// class.
virtual AppContentControlDelegate* GetDelegate() = 0;
// Returns an |AppActivityRegistry| for a given activity |app_id| and // Returns an |AppActivityRegistry| for a given activity |app_id| and
// |browser_context|. // |browser_context|.
virtual AppActivityRegistry* GetAppActivityRegistry( virtual AppActivityRegistry* GetAppActivityRegistry(
......
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
namespace athena { namespace athena {
Activity* ContentActivityFactory::CreateAppActivity( Activity* ContentActivityFactory::CreateAppActivity(
extensions::ShellAppWindow* app_window) { extensions::ShellAppWindow* app_window,
return new ShellAppActivity(app_window); const std::string& app_id) {
return new ShellAppActivity(app_window, app_id);
} }
Activity* ContentActivityFactory::CreateAppActivity( Activity* ContentActivityFactory::CreateAppActivity(
......
...@@ -8,11 +8,13 @@ ...@@ -8,11 +8,13 @@
namespace athena { namespace athena {
ShellAppActivity::ShellAppActivity(extensions::ShellAppWindow* app_window) ShellAppActivity::ShellAppActivity(extensions::ShellAppWindow* app_window,
: shell_app_window_(app_window) { const std::string& app_id)
: AppActivity(app_id), shell_app_window_(app_window) {
} }
ShellAppActivity::~ShellAppActivity() {} ShellAppActivity::~ShellAppActivity() {
}
content::WebContents* ShellAppActivity::GetWebContents() { content::WebContents* ShellAppActivity::GetWebContents() {
return shell_app_window_->GetAssociatedWebContents(); return shell_app_window_->GetAssociatedWebContents();
......
...@@ -17,7 +17,8 @@ namespace athena { ...@@ -17,7 +17,8 @@ namespace athena {
class ShellAppActivity : public AppActivity { class ShellAppActivity : public AppActivity {
public: public:
explicit ShellAppActivity(extensions::ShellAppWindow* app_window); ShellAppActivity(extensions::ShellAppWindow* app_window,
const std::string& app_id);
virtual ~ShellAppActivity(); virtual ~ShellAppActivity();
private: private:
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
namespace content { namespace content {
class BrowserContext; class BrowserContext;
class WebContents;
} }
namespace extensions { namespace extensions {
...@@ -43,8 +44,13 @@ class ATHENA_EXPORT ExtensionsDelegate { ...@@ -43,8 +44,13 @@ class ATHENA_EXPORT ExtensionsDelegate {
// Returns the set of extensions that are currently installed. // Returns the set of extensions that are currently installed.
virtual const extensions::ExtensionSet& GetInstalledExtensions() = 0; virtual const extensions::ExtensionSet& GetInstalledExtensions() = 0;
// Launch an application specified by |app_id|. // Starts an application. Returns true if the application was
virtual void LaunchApp(const std::string& app_id) = 0; // successfully started.
virtual bool LaunchApp(const std::string& app_id) = 0;
// Unload an application. Returns true if the application was
// successfully unloaded.
virtual bool UnloadApp(const std::string& app_id) = 0;
}; };
} // namespace athena } // namespace athena
......
...@@ -30,10 +30,13 @@ class ShellExtensionsDelegate : public ExtensionsDelegate { ...@@ -30,10 +30,13 @@ class ShellExtensionsDelegate : public ExtensionsDelegate {
shell_extensions_.Insert(extension_system_->extension()); shell_extensions_.Insert(extension_system_->extension());
return shell_extensions_; return shell_extensions_;
} }
virtual void LaunchApp(const std::string& app_id) OVERRIDE { virtual bool LaunchApp(const std::string& app_id) OVERRIDE {
extension_system_->LaunchApp(); extension_system_->LaunchApp();
return true;
} }
virtual bool UnloadApp(const std::string& app_id) OVERRIDE { return false; }
content::BrowserContext* context_; content::BrowserContext* context_;
extensions::ShellExtensionSystem* extension_system_; extensions::ShellExtensionSystem* extension_system_;
extensions::ExtensionSet shell_extensions_; extensions::ExtensionSet shell_extensions_;
......
...@@ -23,7 +23,8 @@ class TestExtensionsDelegate : public ExtensionsDelegate { ...@@ -23,7 +23,8 @@ class TestExtensionsDelegate : public ExtensionsDelegate {
virtual const extensions::ExtensionSet& GetInstalledExtensions() OVERRIDE { virtual const extensions::ExtensionSet& GetInstalledExtensions() OVERRIDE {
return shell_extensions_; return shell_extensions_;
} }
virtual void LaunchApp(const std::string& app_id) OVERRIDE {} virtual bool LaunchApp(const std::string& app_id) OVERRIDE { return true; }
virtual bool UnloadApp(const std::string& app_id) OVERRIDE { return false; }
extensions::ExtensionSet shell_extensions_; extensions::ExtensionSet shell_extensions_;
......
...@@ -53,7 +53,8 @@ class AthenaDesktopController : public extensions::DesktopController { ...@@ -53,7 +53,8 @@ class AthenaDesktopController : public extensions::DesktopController {
extensions::ShellAppWindow* app_window = new extensions::ShellAppWindow(); extensions::ShellAppWindow* app_window = new extensions::ShellAppWindow();
app_window->Init(context, extension, gfx::Size(100, 100)); app_window->Init(context, extension, gfx::Size(100, 100));
athena::ActivityManager::Get()->AddActivity( athena::ActivityManager::Get()->AddActivity(
athena::ActivityFactory::Get()->CreateAppActivity(app_window)); athena::ActivityFactory::Get()->CreateAppActivity(app_window,
extension->id()));
return app_window; return app_window;
} }
......
...@@ -35,7 +35,8 @@ Activity* SampleActivityFactory::CreateWebActivity( ...@@ -35,7 +35,8 @@ Activity* SampleActivityFactory::CreateWebActivity(
} }
Activity* SampleActivityFactory::CreateAppActivity( Activity* SampleActivityFactory::CreateAppActivity(
extensions::ShellAppWindow* app_window) { extensions::ShellAppWindow* app_window,
const std::string& app_id) {
// SampleActivityFactory can't own the |app_window|, so it must be NULL. // SampleActivityFactory can't own the |app_window|, so it must be NULL.
DCHECK(app_window == NULL); DCHECK(app_window == NULL);
return new SampleActivity( return new SampleActivity(
......
...@@ -19,10 +19,9 @@ class SampleActivityFactory : public ActivityFactory { ...@@ -19,10 +19,9 @@ class SampleActivityFactory : public ActivityFactory {
// Overridden from ActivityFactory: // Overridden from ActivityFactory:
virtual Activity* CreateWebActivity(content::BrowserContext* browser_context, virtual Activity* CreateWebActivity(content::BrowserContext* browser_context,
const GURL& url) OVERRIDE; const GURL& url) OVERRIDE;
virtual Activity* CreateAppActivity( virtual Activity* CreateAppActivity(extensions::ShellAppWindow* app_window,
extensions::ShellAppWindow* app_window) OVERRIDE; const std::string& app_id) OVERRIDE;
virtual Activity* CreateAppActivity( virtual Activity* CreateAppActivity(apps::AppWindow* app_window) OVERRIDE;
apps::AppWindow* app_window) OVERRIDE;
private: private:
DISALLOW_COPY_AND_ASSIGN(SampleActivityFactory); DISALLOW_COPY_AND_ASSIGN(SampleActivityFactory);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment