Skip to content

Commit

Permalink
Move extension notifications to extensions/browser/notification_types.h
Browse files Browse the repository at this point in the history
As part of the extensions module refactor we temporarily allowed the use
of chrome_notification_types.h in src/extensions. However, this allowed
code moving into src/extensions to listen to notifications from Chrome,
which was a layering violation.

This CL moves all the extensions notifications into their own header and
cleans up DEPS to disallow the exception.

BUG=392622
TEST=compiles, unit_tests, browser_tests, extensions_unittests
TBR=miket@chromium.org for apps/

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286770 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jamescook@chromium.org committed Jul 31, 2014
1 parent 248ee9b commit adf5a10
Show file tree
Hide file tree
Showing 147 changed files with 1,017 additions and 907 deletions.
17 changes: 9 additions & 8 deletions apps/app_lifetime_monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/notification_types.h"
#include "extensions/common/extension.h"

namespace apps {
Expand All @@ -19,12 +20,12 @@ using extensions::ExtensionHost;

AppLifetimeMonitor::AppLifetimeMonitor(Profile* profile)
: profile_(profile) {
registrar_.Add(
this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
content::NotificationService::AllSources());
registrar_.Add(
this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::NotificationService::AllSources());
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
content::NotificationService::AllSources());
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::NotificationService::AllSources());
registrar_.Add(
this, chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
Expand All @@ -50,7 +51,7 @@ void AppLifetimeMonitor::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
const Extension* extension = host->extension();
if (!extension || !extension->is_platform_app())
Expand All @@ -60,7 +61,7 @@ void AppLifetimeMonitor::Observe(int type,
break;
}

case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
const Extension* extension = host->extension();
if (!extension || !extension->is_platform_app())
Expand Down
18 changes: 9 additions & 9 deletions apps/app_load_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "apps/app_restore_service.h"
#include "apps/app_window_registry.h"
#include "apps/launcher.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/profiles/profile.h"
Expand All @@ -18,6 +17,7 @@
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/notification_types.h"
#include "extensions/common/extension.h"

using extensions::Extension;
Expand All @@ -33,12 +33,12 @@ AppLoadService::PostReloadAction::PostReloadAction()

AppLoadService::AppLoadService(Profile* profile)
: profile_(profile) {
registrar_.Add(
this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
content::NotificationService::AllSources());
registrar_.Add(
this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::NotificationService::AllSources());
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
content::NotificationService::AllSources());
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::NotificationService::AllSources());
}

AppLoadService::~AppLoadService() {}
Expand Down Expand Up @@ -85,7 +85,7 @@ void AppLoadService::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
extensions::ExtensionHost* host =
content::Details<extensions::ExtensionHost>(details).ptr();
const Extension* extension = host->extension();
Expand Down Expand Up @@ -116,7 +116,7 @@ void AppLoadService::Observe(int type,
post_reload_actions_.erase(it);
break;
}
case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
const extensions::UnloadedExtensionInfo* unload_info =
content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
if (!unload_info->extension->is_platform_app())
Expand Down
8 changes: 4 additions & 4 deletions apps/app_restore_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#include "apps/app_restore_service_factory.h"
#include "apps/saved_files_service.h"
#include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/file_system/file_system_api.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/notification_types.h"
#include "extensions/common/extension.h"

using extensions::Extension;
Expand All @@ -29,7 +29,7 @@ namespace apps {
// Tests that a running app is recorded in the preferences as such.
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, RunningAppsAreRecorded) {
content::WindowedNotificationObserver extension_suspended(
chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::NotificationService::AllSources());

const Extension* extension = LoadExtension(
Expand Down Expand Up @@ -111,7 +111,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ActiveAppsAreRecorded) {

IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, FileAccessIsSavedToPrefs) {
content::WindowedNotificationObserver extension_suspended(
chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::NotificationService::AllSources());

base::ScopedTempDir temp_directory;
Expand Down Expand Up @@ -151,7 +151,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, FileAccessIsSavedToPrefs) {

IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_FileAccessIsRestored) {
content::WindowedNotificationObserver extension_suspended(
chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::NotificationService::AllSources());

base::ScopedTempDir temp_directory;
Expand Down
16 changes: 9 additions & 7 deletions apps/app_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/notification_types.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/view_type_utils.h"
#include "extensions/common/extension.h"
Expand Down Expand Up @@ -326,18 +327,19 @@ void AppWindow::Init(const GURL& url,
extensions::ExtensionsBrowserClient* client =
extensions::ExtensionsBrowserClient::Get();
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<content::BrowserContext>(
client->GetOriginalContext(browser_context_)));
// Close when the browser process is exiting.
registrar_.Add(this,
chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
// Update the app menu if an ephemeral app becomes installed.
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
content::Source<content::BrowserContext>(
client->GetOriginalContext(browser_context_)));
registrar_.Add(
this,
extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
content::Source<content::BrowserContext>(
client->GetOriginalContext(browser_context_)));

app_window_contents_->LoadContents(new_params.creator_process_id);

Expand Down Expand Up @@ -996,15 +998,15 @@ void AppWindow::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
const extensions::Extension* unloaded_extension =
content::Details<extensions::UnloadedExtensionInfo>(details)
->extension;
if (extension_id_ == unloaded_extension->id())
native_app_window_->Close();
break;
}
case chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: {
case extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: {
const extensions::Extension* installed_extension =
content::Details<const extensions::InstalledExtensionInfo>(details)
->extension;
Expand Down
5 changes: 3 additions & 2 deletions apps/saved_files_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/notification_types.h"
#include "extensions/common/permissions/api_permission.h"
#include "extensions/common/permissions/permission_set.h"
#include "extensions/common/permissions/permissions_data.h"
Expand Down Expand Up @@ -197,7 +198,7 @@ SavedFilesService::SavedFilesService(Profile* profile)
: extension_id_to_saved_files_deleter_(&extension_id_to_saved_files_),
profile_(profile) {
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::NotificationService::AllSources());
registrar_.Add(this,
chrome::NOTIFICATION_APP_TERMINATING,
Expand All @@ -210,7 +211,7 @@ void SavedFilesService::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
const Extension* extension = host->extension();
if (extension) {
Expand Down
8 changes: 5 additions & 3 deletions chrome/browser/apps/app_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/notification_types.h"
#include "extensions/browser/pref_names.h"
#include "extensions/common/api/app_runtime.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
Expand Down Expand Up @@ -938,9 +939,10 @@ namespace {
class CheckExtensionInstalledObserver : public content::NotificationObserver {
public:
CheckExtensionInstalledObserver() : seen_(false) {
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
content::NotificationService::AllSources());
registrar_.Add(
this,
extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
content::NotificationService::AllSources());
}

bool seen() const {
Expand Down
9 changes: 5 additions & 4 deletions chrome/browser/apps/ephemeral_app_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/notification_types.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/uninstall_reason.h"
#include "extensions/common/extension.h"
Expand Down Expand Up @@ -202,7 +203,7 @@ const Extension* EphemeralAppTestBase::UpdateEphemeralApp(
// Update the ephemeral app and wait for the update to finish.
extensions::CrxInstaller* crx_installer = NULL;
content::WindowedNotificationObserver windowed_observer(
chrome::NOTIFICATION_CRX_INSTALLER_DONE,
extensions::NOTIFICATION_CRX_INSTALLER_DONE,
content::Source<extensions::CrxInstaller>(crx_installer));
ExtensionService* service =
ExtensionSystem::Get(profile())->extension_service();
Expand All @@ -223,7 +224,7 @@ void EphemeralAppTestBase::PromoteEphemeralApp(

void EphemeralAppTestBase::CloseApp(const std::string& app_id) {
content::WindowedNotificationObserver event_page_destroyed_signal(
chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::Source<Profile>(profile()));

EXPECT_EQ(1U, GetAppWindowCountForApp(app_id));
Expand All @@ -238,7 +239,7 @@ void EphemeralAppTestBase::EvictApp(const std::string& app_id) {
// Uninstall the app, which is what happens when ephemeral apps get evicted
// from the cache.
content::WindowedNotificationObserver uninstalled_signal(
chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
content::Source<Profile>(profile()));

ExtensionService* service =
Expand Down Expand Up @@ -697,7 +698,7 @@ IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest,

// The delayed installation will occur when the ephemeral app is closed.
content::WindowedNotificationObserver installed_signal(
chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
content::Source<Profile>(profile()));
InstallObserver installed_observer(profile());
CloseApp(app_id);
Expand Down
6 changes: 4 additions & 2 deletions chrome/browser/apps/ephemeral_app_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/notification_types.h"
#include "extensions/browser/uninstall_reason.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
Expand Down Expand Up @@ -63,7 +64,8 @@ EphemeralAppService::EphemeralAppService(Profile* profile)
return;

extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::Source<Profile>(profile_));
Expand Down Expand Up @@ -113,7 +115,7 @@ void EphemeralAppService::Observe(
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_EXTENSIONS_READY: {
case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: {
Init();
break;
}
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/apps/ephemeral_app_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/notification_types.h"
#include "extensions/common/manifest.h"

using extensions::Extension;
Expand Down Expand Up @@ -83,7 +84,7 @@ IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest,

// Perform garbage collection.
content::WindowedNotificationObserver uninstall_signal(
chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
content::Source<Profile>(browser()->profile()));
GarbageCollectEphemeralApps();
uninstall_signal.Wait();
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/apps/event_page_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// found in the LICENSE file.

#include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/notification_types.h"

using extensions::Extension;
using extensions::PlatformAppBrowserTest;
Expand All @@ -22,7 +22,7 @@ class AppEventPageTest : public PlatformAppBrowserTest {
ASSERT_TRUE(extension);

content::WindowedNotificationObserver event_page_suspended(
chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::NotificationService::AllSources());

// Close the app window.
Expand Down
Loading

0 comments on commit adf5a10

Please sign in to comment.