Skip to content

Commit

Permalink
app_shell: Move chrome.audio extensions API to //extensions
Browse files Browse the repository at this point in the history
This allows app_shell to use chrome.audio. Extend the stub PrefHandler
to support get/set of volume so the audio API tests still pass. In a
later CL the audio code will be refactored to allow app_shell to use the
real AudioDevicePrefHandler.

BUG=442401
TEST=app_shell_browsertests AudioApiTest

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

Cr-Commit-Position: refs/heads/master@{#308611}
  • Loading branch information
jamescook authored and Commit bot committed Dec 16, 2014
1 parent 5f800e1 commit f1545b5
Show file tree
Hide file tree
Showing 32 changed files with 174 additions and 152 deletions.
7 changes: 1 addition & 6 deletions chrome/browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ static_library("extensions") {
rebase_path(gypi_values.chrome_browser_extensions_chromeos_sources,
".",
"//chrome")
sources -= [
"api/audio/audio_service_linux.cc",
"api/music_manager_private/device_id_linux.cc",
]
sources -= [ "api/music_manager_private/device_id_linux.cc" ]
configs += [ "//build/config/linux:dbus" ]
deps += [
"//third_party/libevent",
Expand Down Expand Up @@ -136,8 +133,6 @@ static_library("extensions") {
"//ui/events/platform/x11",
]
}
} else {
sources += [ "api/audio/audio_service.cc" ]
}

if (enable_configuration_policy) {
Expand Down
26 changes: 0 additions & 26 deletions chrome/browser/extensions/api/audio/audio_apitest.cc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "chrome/browser/extensions/activity_log/activity_log.h"
#include "chrome/browser/extensions/api/activity_log_private/activity_log_private_api.h"
#include "chrome/browser/extensions/api/alarms/alarm_manager.h"
#include "chrome/browser/extensions/api/audio/audio_api.h"
#include "chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.h"
#include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h"
#include "chrome/browser/extensions/api/braille_display_private/braille_display_private_api.h"
Expand Down Expand Up @@ -85,7 +84,6 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
extensions::AlarmManager::GetFactoryInstance();
extensions::ApiResourceManager<
extensions::UsbDeviceResource>::GetFactoryInstance();
extensions::AudioAPI::GetFactoryInstance();
extensions::BookmarksAPI::GetFactoryInstance();
extensions::BookmarkManagerPrivateAPI::GetFactoryInstance();
extensions::BluetoothAPI::GetFactoryInstance();
Expand Down
9 changes: 0 additions & 9 deletions chrome/chrome_browser_extensions.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@
'browser/extensions/api/alarms/alarm_manager.h',
'browser/extensions/api/alarms/alarms_api.cc',
'browser/extensions/api/alarms/alarms_api.h',
'browser/extensions/api/audio/audio_api.cc',
'browser/extensions/api/audio/audio_api.h',
'browser/extensions/api/audio/audio_service.h',
'browser/extensions/api/audio/audio_service_chromeos.cc',
'browser/extensions/api/audio/audio_service_linux.cc',
'browser/extensions/api/automation_internal/automation_action_adapter.h',
'browser/extensions/api/automation_internal/automation_internal_api.cc',
'browser/extensions/api/automation_internal/automation_internal_api.h',
Expand Down Expand Up @@ -1030,10 +1025,6 @@
],
}],
],
}, {
'sources': [
'browser/extensions/api/audio/audio_service.cc',
],
}],
['safe_browsing==1', {
'defines': [
Expand Down
1 change: 0 additions & 1 deletion chrome/chrome_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@
'browser/extensions/alert_apitest.cc',
'browser/extensions/all_urls_apitest.cc',
'browser/extensions/api/activity_log_private/activity_log_private_apitest.cc',
'browser/extensions/api/audio/audio_apitest.cc',
'browser/extensions/api/automation/automation_apitest.cc',
'browser/extensions/api/autotest_private/autotest_private_apitest.cc',
'browser/extensions/api/bookmark_manager_private/bookmark_manager_private_apitest.cc',
Expand Down
4 changes: 0 additions & 4 deletions chrome/common/extensions/api/_api_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@
"contexts": ["blessed_extension", "unblessed_extension", "content_script"],
"matches": []
},
"audio": {
"dependencies": ["permission:audio"],
"contexts": ["blessed_extension"]
},
"automationInternal": {
"internal": true,
"dependencies": ["manifest:automation"],
Expand Down
21 changes: 0 additions & 21 deletions chrome/common/extensions/api/_permission_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,6 @@
"extension_types": ["extension", "legacy_packaged_app", "platform_app"],
"min_manifest_version": 2
},
"audio": [
{
"channel": "dev",
"extension_types": ["platform_app"]
},
{
"channel": "stable",
"extension_types": ["platform_app"],
"whitelist": [
"8C3741E3AF0B93B6E8E0DDD499BB0B74839EA578",
"E703483CEF33DEC18B4B6DD84B5C776FB9182BDB",
"A3BC37E2148AC4E99BE4B16AF9D42DD1E592BBBE", // http://crbug.com/335729
"1C93BD3CF875F4A73C0B2A163BB8FBDA8B8B3D80", // http://crbug.com/335729
"307E96539209F95A1A8740C713E6998A73657D96", // http://crbug.com/335729
"4F25792AF1AA7483936DE29C07806F203C7170A0", // http://crbug.com/407693
"BD8781D757D830FC2E85470A1B6E8A718B7EE0D9", // http://crbug.com/407693
"4AC2B6C63C6480D150DFDA13E4A5956EB1D0DDBB", // http://crbug.com/407693
"81986D4F846CEDDDB962643FA501D1780DD441BB" // http://crbug.com/407693
]
}
],
"autotestPrivate": {
"channel": "stable",
"extension_types": ["extension", "legacy_packaged_app"],
Expand Down
1 change: 0 additions & 1 deletion chrome/common/extensions/api/schemas.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'accessibility_private.json',
'activity_log_private.json',
'alarms.idl',
'audio.idl',
'automation.idl',
'automation_internal.idl',
'autotest_private.idl',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ std::vector<APIPermissionInfo*> ChromeAPIPermissions::GetAllPermissions()
APIPermissionInfo::kFlagCannotBeOptional},
{APIPermission::kPointerLock, "pointerLock"},
{APIPermission::kPrinterProvider, "printerProvider"},
{APIPermission::kAudio, "audio"},
{APIPermission::kCastStreaming, "cast.streaming"},
{APIPermission::kBrowser, "browser"},
{APIPermission::kInterceptAllKeys,
Expand Down
9 changes: 9 additions & 0 deletions extensions/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ source_set("browser") {
"api/app_window/app_window_api.h",
"api/async_api_function.cc",
"api/async_api_function.h",
"api/audio/audio_api.cc",
"api/audio/audio_api.h",
"api/audio/audio_service.h",
"api/bluetooth/bluetooth_api.cc",
"api/bluetooth/bluetooth_api.h",
"api/bluetooth/bluetooth_api_pairing_delegate.cc",
Expand Down Expand Up @@ -519,13 +522,19 @@ source_set("browser") {
}

if (is_chromeos) {
deps += [ "//chromeos" ]
sources += [
"api/audio/audio_service_chromeos.cc",
"api/vpn_provider/vpn_provider_api.cc",
"api/vpn_provider/vpn_provider_api.h",
"api/vpn_provider/vpn_service.cc",
"api/vpn_provider/vpn_service.h",
"api/vpn_provider/vpn_service_factory.h",
]
} else if (is_linux) {
sources += [ "api/audio/audio_service_linux.cc" ]
} else {
sources += [ "api/audio/audio_service.cc" ]
}
}

Expand Down
1 change: 1 addition & 0 deletions extensions/browser/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+chromeos",
"+components/keyed_service",
"+components/omaha_client",
"+components/pref_registry",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/api/audio/audio_api.h"
#include "extensions/browser/api/audio/audio_api.h"

#include "base/lazy_instance.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/audio.h"
#include "extensions/browser/event_router.h"
#include "extensions/common/api/audio.h"

namespace extensions {

namespace audio = api::audio;
namespace audio = core_api::audio;

static base::LazyInstance<BrowserContextKeyedAPIFactory<AudioAPI> > g_factory =
LAZY_INSTANCE_INITIALIZER;
Expand Down Expand Up @@ -46,9 +45,11 @@ void AudioAPI::OnDeviceChanged() {
}
}

///////////////////////////////////////////////////////////////////////////////

bool AudioGetInfoFunction::RunAsync() {
AudioService* service =
AudioAPI::GetFactoryInstance()->Get(GetProfile())->GetService();
AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService();
DCHECK(service);
service->StartGetInfo(base::Bind(&AudioGetInfoFunction::OnGetInfoCompleted,
this));
Expand All @@ -59,32 +60,36 @@ void AudioGetInfoFunction::OnGetInfoCompleted(const OutputInfo& output_info,
const InputInfo& input_info,
bool success) {
if (success)
results_ = api::audio::GetInfo::Results::Create(output_info, input_info);
results_ = audio::GetInfo::Results::Create(output_info, input_info);
else
SetError("Error occurred when querying audio device information.");
SendResponse(success);
}

///////////////////////////////////////////////////////////////////////////////

bool AudioSetActiveDevicesFunction::RunSync() {
scoped_ptr<api::audio::SetActiveDevices::Params> params(
api::audio::SetActiveDevices::Params::Create(*args_));
scoped_ptr<audio::SetActiveDevices::Params> params(
audio::SetActiveDevices::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

AudioService* service =
AudioAPI::GetFactoryInstance()->Get(GetProfile())->GetService();
AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService();
DCHECK(service);

service->SetActiveDevices(params->ids);
return true;
}

///////////////////////////////////////////////////////////////////////////////

bool AudioSetPropertiesFunction::RunSync() {
scoped_ptr<api::audio::SetProperties::Params> params(
api::audio::SetProperties::Params::Create(*args_));
scoped_ptr<audio::SetProperties::Params> params(
audio::SetProperties::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

AudioService* service =
AudioAPI::GetFactoryInstance()->Get(GetProfile())->GetService();
AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService();
DCHECK(service);

int volume_value = params->properties.volume.get() ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_API_AUDIO_AUDIO_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_AUDIO_AUDIO_API_H_
#ifndef EXTENSIONS_BROWSER_API_AUDIO_AUDIO_API_H_
#define EXTENSIONS_BROWSER_API_AUDIO_AUDIO_API_H_

#include "chrome/browser/extensions/api/audio/audio_service.h"
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "extensions/browser/api/audio/audio_service.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_function.h"

namespace extensions {

Expand Down Expand Up @@ -38,10 +38,9 @@ class AudioAPI : public BrowserContextKeyedAPI, public AudioService::Observer {
AudioService* service_;
};

class AudioGetInfoFunction : public ChromeAsyncExtensionFunction {
class AudioGetInfoFunction : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("audio.getInfo",
AUDIO_GETINFO);
DECLARE_EXTENSION_FUNCTION("audio.getInfo", AUDIO_GETINFO);

protected:
~AudioGetInfoFunction() override {}
Expand All @@ -53,20 +52,18 @@ class AudioGetInfoFunction : public ChromeAsyncExtensionFunction {
bool success);
};

class AudioSetActiveDevicesFunction : public ChromeSyncExtensionFunction {
class AudioSetActiveDevicesFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("audio.setActiveDevices",
AUDIO_SETACTIVEDEVICES);
DECLARE_EXTENSION_FUNCTION("audio.setActiveDevices", AUDIO_SETACTIVEDEVICES);

protected:
~AudioSetActiveDevicesFunction() override {}
bool RunSync() override;
};

class AudioSetPropertiesFunction : public ChromeSyncExtensionFunction {
class AudioSetPropertiesFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("audio.setProperties",
AUDIO_SETPROPERTIES);
DECLARE_EXTENSION_FUNCTION("audio.setProperties", AUDIO_SETPROPERTIES);

protected:
~AudioSetPropertiesFunction() override {}
Expand All @@ -76,4 +73,4 @@ class AudioSetPropertiesFunction : public ChromeSyncExtensionFunction {

} // namespace extensions

#endif // CHROME_BROWSER_EXTENSIONS_API_AUDIO_AUDIO_API_H_
#endif // EXTENSIONS_BROWSER_API_AUDIO_AUDIO_API_H_
17 changes: 17 additions & 0 deletions extensions/browser/api/audio/audio_apitest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2013 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 "extensions/shell/test/shell_apitest.h"

namespace extensions {

using AudioApiTest = ShellApiTest;

#if defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(AudioApiTest, Audio) {
EXPECT_TRUE(RunAppTest("api_test/audio")) << message_;
}
#endif

} // namespace extensions
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/api/audio/audio_service.h"
#include "extensions/browser/api/audio/audio_service.h"

namespace extensions {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_API_AUDIO_AUDIO_SERVICE_H_
#define CHROME_BROWSER_EXTENSIONS_API_AUDIO_AUDIO_SERVICE_H_
#ifndef EXTENSIONS_BROWSER_API_AUDIO_AUDIO_SERVICE_H_
#define EXTENSIONS_BROWSER_API_AUDIO_AUDIO_SERVICE_H_

#include <string>
#include <vector>

#include "base/basictypes.h"
#include "base/callback.h"
#include "chrome/common/extensions/api/audio.h"
#include "base/macros.h"
#include "base/memory/linked_ptr.h"
#include "extensions/common/api/audio.h"

namespace extensions {

typedef std::vector<linked_ptr<api::audio::OutputDeviceInfo> > OutputInfo;
typedef std::vector<linked_ptr<api::audio::InputDeviceInfo> > InputInfo;
typedef std::vector<std::string> DeviceIdList;
using OutputInfo = std::vector<linked_ptr<core_api::audio::OutputDeviceInfo>>;
using InputInfo = std::vector<linked_ptr<core_api::audio::InputDeviceInfo>>;
using DeviceIdList = std::vector<std::string>;

class AudioService {
public:
Expand Down Expand Up @@ -62,10 +66,10 @@ class AudioService {
protected:
AudioService() {}

private:
DISALLOW_COPY_AND_ASSIGN(AudioService);
};


} // namespace extensions

#endif // CHROME_BROWSER_EXTENSIONS_API_AUDIO_AUDIO_SERVICE_H_
#endif // EXTENSIONS_BROWSER_API_AUDIO_AUDIO_SERVICE_H_
Loading

0 comments on commit f1545b5

Please sign in to comment.