From beafd8cb70f31a44502a9040af396b8cd61dcdb1 Mon Sep 17 00:00:00 2001 From: "sudarsana.nagineni" Date: Tue, 3 Feb 2015 07:16:26 -0800 Subject: [PATCH] Move chrome.diagnostics API to extensions/. Move the chrome.diagnostics extension API from chrome/ to extensions/. BUG=395240 Review URL: https://codereview.chromium.org/883703004 Cr-Commit-Position: refs/heads/master@{#314338} --- chrome/chrome_browser_extensions.gypi | 3 --- chrome/common/extensions/api/_api_features.json | 5 ----- .../extensions/api/_permission_features.json | 15 ------------- chrome/common/extensions/api/schemas.gypi | 1 - .../permissions/chrome_api_permissions.cc | 3 --- extensions/browser/BUILD.gn | 3 +++ .../browser}/api/diagnostics/diagnostics_api.cc | 15 +++++++------ .../browser}/api/diagnostics/diagnostics_api.h | 14 ++++++------ .../api/diagnostics/diagnostics_api_chromeos.cc | 25 +++++++++------------- extensions/common/api/_api_features.json | 5 +++++ extensions/common/api/_permission_features.json | 15 +++++++++++++ .../common}/api/diagnostics.idl | 0 extensions/common/api/schemas.gypi | 1 + .../permissions/extensions_api_permissions.cc | 3 +++ extensions/extensions.gyp | 3 +++ 15 files changed, 54 insertions(+), 57 deletions(-) rename {chrome/browser/extensions => extensions/browser}/api/diagnostics/diagnostics_api.cc (86%) rename {chrome/browser/extensions => extensions/browser}/api/diagnostics/diagnostics_api.h (74%) rename {chrome/browser/extensions => extensions/browser}/api/diagnostics/diagnostics_api_chromeos.cc (79%) rename {chrome/common/extensions => extensions/common}/api/diagnostics.idl (100%) diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index 1f97eb847f93..67dedf5e585d 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -5,9 +5,6 @@ { 'variables': { 'chrome_browser_extensions_chromeos_sources': [ - 'browser/extensions/api/diagnostics/diagnostics_api.cc', - 'browser/extensions/api/diagnostics/diagnostics_api.h', - 'browser/extensions/api/diagnostics/diagnostics_api_chromeos.cc', 'browser/extensions/api/document_scan/document_scan_interface_chromeos.cc', 'browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc', 'browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.h', diff --git a/chrome/common/extensions/api/_api_features.json b/chrome/common/extensions/api/_api_features.json index b68b8cb30e9d..65518e95899b 100644 --- a/chrome/common/extensions/api/_api_features.json +++ b/chrome/common/extensions/api/_api_features.json @@ -262,11 +262,6 @@ "dependencies": ["manifest:devtools_page"], "contexts": ["blessed_extension"] }, - "diagnostics": { - "dependencies": ["permission:diagnostics"], - "extension_types": ["platform_app"], - "contexts": ["blessed_extension"] - }, "dial": { "dependencies": ["permission:dial"], "contexts": ["blessed_extension"] diff --git a/chrome/common/extensions/api/_permission_features.json b/chrome/common/extensions/api/_permission_features.json index acc679501da3..aedc4e1fa3d2 100644 --- a/chrome/common/extensions/api/_permission_features.json +++ b/chrome/common/extensions/api/_permission_features.json @@ -249,21 +249,6 @@ "852290F2442EEE45EF673B8DA6090112079012A2" // http://crbug.com/375484 ] }, - "diagnostics": [ - { - "channel": "dev", - "extension_types": ["platform_app"] - }, - { - "channel": "stable", - "extension_types": ["platform_app"], - "whitelist": [ - "7AE714FFD394E073F0294CFA134C9F91DB5FBAA4", // CCD Development - "C7DA3A55C2355F994D3FDDAD120B426A0DF63843", // CCD Testing - "75E3CFFFC530582C583E4690EF97C70B9C8423B7" // CCD Release - ] - } - ], "debugger": [ { "channel": "stable", diff --git a/chrome/common/extensions/api/schemas.gypi b/chrome/common/extensions/api/schemas.gypi index 7b630c00456d..d02d0a1719bc 100644 --- a/chrome/common/extensions/api/schemas.gypi +++ b/chrome/common/extensions/api/schemas.gypi @@ -107,7 +107,6 @@ # ChromeOS-specific schemas. 'chromeos_schema_files': [ 'accessibility_features.json', - 'diagnostics.idl', 'enterprise_platform_keys.idl', 'enterprise_platform_keys_internal.idl', 'file_browser_handler_internal.json', diff --git a/chrome/common/extensions/permissions/chrome_api_permissions.cc b/chrome/common/extensions/permissions/chrome_api_permissions.cc index a40fe6aec792..4ca22c00794c 100644 --- a/chrome/common/extensions/permissions/chrome_api_permissions.cc +++ b/chrome/common/extensions/permissions/chrome_api_permissions.cc @@ -229,9 +229,6 @@ std::vector ChromeAPIPermissions::GetAllPermissions() {APIPermission::kDeveloperPrivate, "developerPrivate", APIPermissionInfo::kFlagCannotBeOptional}, - {APIPermission::kDiagnostics, - "diagnostics", - APIPermissionInfo::kFlagCannotBeOptional}, {APIPermission::kDial, "dial", APIPermissionInfo::kFlagCannotBeOptional}, {APIPermission::kDownloadsInternal, "downloadsInternal"}, {APIPermission::kExperienceSamplingPrivate, diff --git a/extensions/browser/BUILD.gn b/extensions/browser/BUILD.gn index b11f1d22485e..8ba3c8a8a558 100644 --- a/extensions/browser/BUILD.gn +++ b/extensions/browser/BUILD.gn @@ -580,6 +580,9 @@ source_set("browser") { if (is_chromeos) { sources += [ + "api/diagnostics/diagnostics_api.cc", + "api/diagnostics/diagnostics_api.h", + "api/diagnostics/diagnostics_api_chromeos.cc", "api/networking_config/networking_config_api.cc", "api/networking_config/networking_config_api.h", "api/networking_config/networking_config_service.cc", diff --git a/chrome/browser/extensions/api/diagnostics/diagnostics_api.cc b/extensions/browser/api/diagnostics/diagnostics_api.cc similarity index 86% rename from chrome/browser/extensions/api/diagnostics/diagnostics_api.cc rename to extensions/browser/api/diagnostics/diagnostics_api.cc index 0f6e8d286d2a..684577ce6fdf 100644 --- a/chrome/browser/extensions/api/diagnostics/diagnostics_api.cc +++ b/extensions/browser/api/diagnostics/diagnostics_api.cc @@ -2,22 +2,23 @@ // 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/diagnostics/diagnostics_api.h" - -namespace SendPacket = extensions::api::diagnostics::SendPacket; +#include "extensions/browser/api/diagnostics/diagnostics_api.h" namespace { const char kErrorPingNotImplemented[] = "Not implemented"; const char kErrorPingFailed[] = "Failed to send ping packet"; - } namespace extensions { -DiagnosticsSendPacketFunction::DiagnosticsSendPacketFunction() {} +namespace SendPacket = core_api::diagnostics::SendPacket; -DiagnosticsSendPacketFunction::~DiagnosticsSendPacketFunction() {} +DiagnosticsSendPacketFunction::DiagnosticsSendPacketFunction() { +} + +DiagnosticsSendPacketFunction::~DiagnosticsSendPacketFunction() { +} bool DiagnosticsSendPacketFunction::Prepare() { parameters_ = SendPacket::Params::Create(*args_); @@ -35,7 +36,7 @@ void DiagnosticsSendPacketFunction::OnCompleted( double latency) { switch (result_code) { case SEND_PACKET_OK: { - extensions::api::diagnostics::SendPacketResult result; + core_api::diagnostics::SendPacketResult result; result.ip = ip; result.latency = latency; results_ = SendPacket::Results::Create(result); diff --git a/chrome/browser/extensions/api/diagnostics/diagnostics_api.h b/extensions/browser/api/diagnostics/diagnostics_api.h similarity index 74% rename from chrome/browser/extensions/api/diagnostics/diagnostics_api.h rename to extensions/browser/api/diagnostics/diagnostics_api.h index ac0da6351824..451bd7946637 100644 --- a/chrome/browser/extensions/api/diagnostics/diagnostics_api.h +++ b/extensions/browser/api/diagnostics/diagnostics_api.h @@ -2,14 +2,14 @@ // 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_DIAGNOSTICS_DIAGNOSTICS_API_H_ -#define CHROME_BROWSER_EXTENSIONS_API_DIAGNOSTICS_DIAGNOSTICS_API_H_ +#ifndef EXTENSIONS_BROWSER_API_DIAGNOSTICS_DIAGNOSTICS_API_H_ +#define EXTENSIONS_BROWSER_API_DIAGNOSTICS_DIAGNOSTICS_API_H_ #include #include "base/memory/scoped_ptr.h" -#include "chrome/common/extensions/api/diagnostics.h" #include "extensions/browser/api/async_api_function.h" +#include "extensions/common/api/diagnostics.h" namespace extensions { @@ -28,8 +28,7 @@ class DiagnosticsSendPacketFunction : public AsyncApiFunction { SEND_PACKET_FAILED, }; - DECLARE_EXTENSION_FUNCTION("diagnostics.sendPacket", - DIAGNOSTICS_SENDPACKET); + DECLARE_EXTENSION_FUNCTION("diagnostics.sendPacket", DIAGNOSTICS_SENDPACKET); DiagnosticsSendPacketFunction(); @@ -48,10 +47,9 @@ class DiagnosticsSendPacketFunction : public AsyncApiFunction { const std::string& ip, double latency); - scoped_ptr - parameters_; + scoped_ptr parameters_; }; } // namespace extensions -#endif // CHROME_BROWSER_EXTENSIONS_API_DIAGNOSTICS_DIAGNOSTICS_API_H_ +#endif // EXTENSIONS_BROWSER_API_DIAGNOSTICS_DIAGNOSTICS_API_H_ diff --git a/chrome/browser/extensions/api/diagnostics/diagnostics_api_chromeos.cc b/extensions/browser/api/diagnostics/diagnostics_api_chromeos.cc similarity index 79% rename from chrome/browser/extensions/api/diagnostics/diagnostics_api_chromeos.cc rename to extensions/browser/api/diagnostics/diagnostics_api_chromeos.cc index 9ae0f18e5b35..f14b8fb0cbe6 100644 --- a/chrome/browser/extensions/api/diagnostics/diagnostics_api_chromeos.cc +++ b/extensions/browser/api/diagnostics/diagnostics_api_chromeos.cc @@ -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/diagnostics/diagnostics_api.h" +#include "extensions/browser/api/diagnostics/diagnostics_api.h" #include "base/bind.h" #include "base/callback.h" @@ -25,12 +25,9 @@ const char kSize[] = "size"; typedef base::Callback - SendPacketCallback; + double latency)> SendPacketCallback; -bool ParseResult(const std::string& status, - std::string* ip, - double* latency) { +bool ParseResult(const std::string& status, std::string* ip, double* latency) { // Parses the result and returns IP and latency. scoped_ptr parsed_value(base::JSONReader::Read(status)); if (!parsed_value) @@ -54,18 +51,15 @@ bool ParseResult(const std::string& status, return true; } -void OnTestICMPCompleted( - const SendPacketCallback& callback, - bool succeeded, - const std::string& status) { +void OnTestICMPCompleted(const SendPacketCallback& callback, + bool succeeded, + const std::string& status) { std::string ip; double latency; if (!succeeded || !ParseResult(status, &ip, &latency)) { callback.Run(DiagnosticsSendPacketFunction::SEND_PACKET_FAILED, "", 0.0); } else { - callback.Run(DiagnosticsSendPacketFunction::SEND_PACKET_OK, - ip, - latency); + callback.Run(DiagnosticsSendPacketFunction::SEND_PACKET_OK, ip, latency); } } @@ -81,8 +75,9 @@ void DiagnosticsSendPacketFunction::AsyncWorkStart() { if (parameters_->options.size) config[kSize] = base::IntToString(*parameters_->options.size); - chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> - TestICMPWithOptions( + chromeos::DBusThreadManager::Get() + ->GetDebugDaemonClient() + ->TestICMPWithOptions( parameters_->options.ip, config, base::Bind( OnTestICMPCompleted, diff --git a/extensions/common/api/_api_features.json b/extensions/common/api/_api_features.json index 68e3fa3b6d36..7e002d6bf01a 100644 --- a/extensions/common/api/_api_features.json +++ b/extensions/common/api/_api_features.json @@ -111,6 +111,11 @@ "dependencies": ["permission:copresence"], "contexts": ["blessed_extension"] }, + "diagnostics": { + "dependencies": ["permission:diagnostics"], + "extension_types": ["platform_app"], + "contexts": ["blessed_extension"] + }, "dns": { "dependencies": ["permission:dns"], "contexts": ["blessed_extension"] diff --git a/extensions/common/api/_permission_features.json b/extensions/common/api/_permission_features.json index 9f24ab963c87..d2f39ff27a30 100644 --- a/extensions/common/api/_permission_features.json +++ b/extensions/common/api/_permission_features.json @@ -151,6 +151,21 @@ "channel": "beta", "extension_types": ["extension", "legacy_packaged_app"] }, + "diagnostics": [ + { + "channel": "dev", + "extension_types": ["platform_app"] + }, + { + "channel": "stable", + "extension_types": ["platform_app"], + "whitelist": [ + "7AE714FFD394E073F0294CFA134C9F91DB5FBAA4", // CCD Development + "C7DA3A55C2355F994D3FDDAD120B426A0DF63843", // CCD Testing + "75E3CFFFC530582C583E4690EF97C70B9C8423B7" // CCD Release + ] + } + ], "dns": [ { "channel": "dev", diff --git a/chrome/common/extensions/api/diagnostics.idl b/extensions/common/api/diagnostics.idl similarity index 100% rename from chrome/common/extensions/api/diagnostics.idl rename to extensions/common/api/diagnostics.idl diff --git a/extensions/common/api/schemas.gypi b/extensions/common/api/schemas.gypi index ab8f8806d7d7..478dcde83d3f 100644 --- a/extensions/common/api/schemas.gypi +++ b/extensions/common/api/schemas.gypi @@ -59,6 +59,7 @@ ], # ChromeOS-specific schemas. 'chromeos_schema_files': [ + 'diagnostics.idl', 'networking_config.idl', 'vpn_provider.idl', 'webcam_private.idl', diff --git a/extensions/common/permissions/extensions_api_permissions.cc b/extensions/common/permissions/extensions_api_permissions.cc index 825ccf24fb66..d9a811e81a7d 100644 --- a/extensions/common/permissions/extensions_api_permissions.cc +++ b/extensions/common/permissions/extensions_api_permissions.cc @@ -61,6 +61,9 @@ std::vector ExtensionsAPIPermissions::GetAllPermissions() APIPermissionInfo::kFlagNone, IDS_EXTENSION_PROMPT_WARNING_DECLARATIVE_WEB_REQUEST, PermissionMessage::kDeclarativeWebRequest}, + {APIPermission::kDiagnostics, + "diagnostics", + APIPermissionInfo::kFlagCannotBeOptional}, {APIPermission::kDns, "dns"}, {APIPermission::kExtensionView, "extensionview", diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp index a0e437026a7f..a9b80af64399 100644 --- a/extensions/extensions.gyp +++ b/extensions/extensions.gyp @@ -890,6 +890,9 @@ '../chromeos/chromeos.gyp:chromeos', ], 'sources': [ + 'browser/api/diagnostics/diagnostics_api.cc', + 'browser/api/diagnostics/diagnostics_api.h', + 'browser/api/diagnostics/diagnostics_api_chromeos.cc', 'browser/api/networking_config/networking_config_api.cc', 'browser/api/networking_config/networking_config_api.h', 'browser/api/networking_config/networking_config_service.cc', -- 2.11.4.GIT