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