diff options
author | vitalybuka <vitalybuka@chromium.org> | 2015-11-04 18:25:56 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-05 02:26:43 +0000 |
commit | 7f65981227ba0cf89ac9c1565a845e5af6e1879d (patch) | |
tree | 0cc6882a016cfd1695eed0efbe7890986bc18d8e | |
parent | b6f8a4c101840c3c72cb91287fc7dc5af6d2f046 (diff) | |
download | chromium_src-7f65981227ba0cf89ac9c1565a845e5af6e1879d.zip chromium_src-7f65981227ba0cf89ac9c1565a845e5af6e1879d.tar.gz chromium_src-7f65981227ba0cf89ac9c1565a845e5af6e1879d.tar.bz2 |
Remove unused function from chrome.gcdPrivate API
The only user of this API is Weave app.
Current implementation uses chrome.networkingPrivate and chrome.mdns API for device enumeration.
And chrome.gcdPrivate.SendMessage is enough for command execution.
BUG=383167
Review URL: https://codereview.chromium.org/1408383004
Cr-Commit-Position: refs/heads/master@{#357985}
13 files changed, 11 insertions, 974 deletions
diff --git a/chrome/browser/extensions/api/gcd_private/gcd_private_api.cc b/chrome/browser/extensions/api/gcd_private/gcd_private_api.cc index cafa806..50d24d6 100644 --- a/chrome/browser/extensions/api/gcd_private/gcd_private_api.cc +++ b/chrome/browser/extensions/api/gcd_private/gcd_private_api.cc @@ -6,30 +6,14 @@ #include "base/command_line.h" #include "base/lazy_instance.h" -#include "base/location.h" #include "base/memory/linked_ptr.h" -#include "base/memory/scoped_ptr.h" -#include "base/single_thread_task_runner.h" -#include "base/strings/stringprintf.h" -#include "base/thread_task_runner_handle.h" -#include "chrome/browser/local_discovery/cloud_device_list.h" -#include "chrome/browser/local_discovery/cloud_print_printer_list.h" -#include "chrome/browser/local_discovery/gcd_api_flow.h" -#include "chrome/browser/local_discovery/gcd_constants.h" -#include "chrome/browser/local_discovery/privet_device_lister_impl.h" +#include "chrome/browser/local_discovery/privet_http.h" #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" -#include "chrome/browser/local_discovery/privet_http_impl.h" #include "chrome/browser/local_discovery/privetv3_session.h" #include "chrome/browser/local_discovery/service_discovery_shared_client.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" -#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/common/chrome_switches.h" -#include "components/signin/core/browser/profile_oauth2_token_service.h" -#include "components/signin/core/browser/signin_manager.h" -#include "components/signin/core/browser/signin_manager_base.h" -#include "extensions/browser/event_router.h" -#include "net/base/net_util.h" +#include "content/public/browser/browser_context.h" namespace extensions { @@ -37,66 +21,19 @@ namespace gcd_private = api::gcd_private; namespace { -const int kNumRequestsNeeded = 2; - -const char kIDPrefixCloudPrinter[] = "cloudprint:"; -const char kIDPrefixGcd[] = "gcd:"; -const char kIDPrefixMdns[] = "mdns:"; - const char kPrivatAPISetup[] = "/privet/v3/setup/start"; const char kPrivetKeyWifi[] = "wifi"; const char kPrivetKeyPassphrase[] = "passphrase"; const char kPrivetKeySSID[] = "ssid"; -const char kPrivetKeyPassphraseDotted[] = "wifi.passphrase"; - -scoped_ptr<Event> MakeDeviceStateChangedEvent( - const gcd_private::GCDDevice& device) { - scoped_ptr<base::ListValue> params = - gcd_private::OnDeviceStateChanged::Create(device); - scoped_ptr<Event> event( - new Event(events::GCD_PRIVATE_ON_DEVICE_STATE_CHANGED, - gcd_private::OnDeviceStateChanged::kEventName, params.Pass())); - return event.Pass(); -} - -scoped_ptr<Event> MakeDeviceRemovedEvent(const std::string& device) { - scoped_ptr<base::ListValue> params = - gcd_private::OnDeviceRemoved::Create(device); - scoped_ptr<Event> event(new Event(events::GCD_PRIVATE_ON_DEVICE_REMOVED, - gcd_private::OnDeviceRemoved::kEventName, - params.Pass())); - return event.Pass(); -} - -GcdPrivateAPI::GCDApiFlowFactoryForTests* g_gcd_api_flow_factory = NULL; base::LazyInstance<BrowserContextKeyedAPIFactory<GcdPrivateAPI> > g_factory = LAZY_INSTANCE_INITIALIZER; -scoped_ptr<local_discovery::GCDApiFlow> MakeGCDApiFlow(Profile* profile) { - if (g_gcd_api_flow_factory) - return g_gcd_api_flow_factory->CreateGCDApiFlow(); - - ProfileOAuth2TokenService* token_service = - ProfileOAuth2TokenServiceFactory::GetForProfile(profile); - if (!token_service) - return scoped_ptr<local_discovery::GCDApiFlow>(); - SigninManagerBase* signin_manager = - SigninManagerFactory::GetInstance()->GetForProfile(profile); - if (!signin_manager) - return scoped_ptr<local_discovery::GCDApiFlow>(); - return local_discovery::GCDApiFlow::Create( - profile->GetRequestContext(), - token_service, - signin_manager->GetAuthenticatedAccountId()); -} - } // namespace class GcdPrivateSessionHolder; -class GcdPrivateAPIImpl : public EventRouter::Observer, - public local_discovery::PrivetDeviceLister::Delegate { +class GcdPrivateAPIImpl { public: typedef base::Callback<void(bool success)> SuccessCallback; @@ -116,8 +53,6 @@ class GcdPrivateAPIImpl : public EventRouter::Observer, static GcdPrivateAPIImpl* Get(content::BrowserContext* context); - bool QueryForDevices(); - void CreateSession(const std::string& service_name, const CreateSessionCallback& callback); @@ -134,33 +69,15 @@ class GcdPrivateAPIImpl : public EventRouter::Observer, const base::DictionaryValue& input, const MessageResponseCallback& callback); - void RequestWifiPassword(const std::string& ssid, - const SuccessCallback& callback); - void RemoveSession(int session_id); void RemoveSessionDelayed(int session_id); scoped_ptr<base::ListValue> GetPrefetchedSSIDList(); private: - typedef std::map<std::string /* id_string */, - linked_ptr<api::gcd_private::GCDDevice> > GCDDeviceMap; - typedef std::map<std::string /* ssid */, std::string /* password */> PasswordMap; - // EventRouter::Observer implementation. - void OnListenerAdded(const EventListenerInfo& details) override; - void OnListenerRemoved(const EventListenerInfo& details) override; - - // local_discovery::PrivetDeviceLister implementation. - void DeviceChanged( - bool added, - const std::string& name, - const local_discovery::DeviceDescription& description) override; - void DeviceRemoved(const std::string& name) override; - void DeviceCacheFlushed() override; - void SendMessageInternal(int session_id, const std::string& api, const base::DictionaryValue& input, @@ -170,11 +87,8 @@ class GcdPrivateAPIImpl : public EventRouter::Observer, const CreateSessionCallback& callback, scoped_ptr<local_discovery::PrivetHTTPClient> client); - int num_device_listeners_; scoped_refptr<local_discovery::ServiceDiscoverySharedClient> service_discovery_client_; - scoped_ptr<local_discovery::PrivetDeviceLister> privet_device_lister_; - GCDDeviceMap known_devices_; struct SessionInfo { linked_ptr<local_discovery::PrivetV3Session> session; @@ -182,12 +96,10 @@ class GcdPrivateAPIImpl : public EventRouter::Observer, }; std::map<int, SessionInfo> sessions_; - int last_session_id_; + int last_session_id_ = 0; content::BrowserContext* const browser_context_; - PasswordMap wifi_passwords_; - base::WeakPtrFactory<GcdPrivateAPIImpl> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(GcdPrivateAPIImpl); @@ -195,92 +107,11 @@ class GcdPrivateAPIImpl : public EventRouter::Observer, GcdPrivateAPIImpl::GcdPrivateAPIImpl(content::BrowserContext* context) - : num_device_listeners_(0), last_session_id_(0), browser_context_(context) { + : browser_context_(context) { DCHECK(browser_context_); - if (EventRouter::Get(context)) { - EventRouter::Get(context) - ->RegisterObserver(this, gcd_private::OnDeviceStateChanged::kEventName); - EventRouter::Get(context) - ->RegisterObserver(this, gcd_private::OnDeviceRemoved::kEventName); - } } GcdPrivateAPIImpl::~GcdPrivateAPIImpl() { - if (EventRouter::Get(browser_context_)) - EventRouter::Get(browser_context_)->UnregisterObserver(this); -} - -void GcdPrivateAPIImpl::OnListenerAdded(const EventListenerInfo& details) { - if (details.event_name == gcd_private::OnDeviceStateChanged::kEventName || - details.event_name == gcd_private::OnDeviceRemoved::kEventName) { - num_device_listeners_++; - - if (num_device_listeners_ == 1) { - service_discovery_client_ = - local_discovery::ServiceDiscoverySharedClient::GetInstance(); - privet_device_lister_.reset(new local_discovery::PrivetDeviceListerImpl( - service_discovery_client_.get(), this)); - privet_device_lister_->Start(); - } - - for (GCDDeviceMap::iterator i = known_devices_.begin(); - i != known_devices_.end(); - i++) { - EventRouter::Get(browser_context_)->DispatchEventToExtension( - details.extension_id, MakeDeviceStateChangedEvent(*i->second)); - } - } -} - -void GcdPrivateAPIImpl::OnListenerRemoved(const EventListenerInfo& details) { - if (details.event_name == gcd_private::OnDeviceStateChanged::kEventName || - details.event_name == gcd_private::OnDeviceRemoved::kEventName) { - num_device_listeners_--; - - if (num_device_listeners_ == 0) { - privet_device_lister_.reset(); - service_discovery_client_ = NULL; - } - } -} - -void GcdPrivateAPIImpl::DeviceChanged( - bool added, - const std::string& name, - const local_discovery::DeviceDescription& description) { - linked_ptr<gcd_private::GCDDevice> device(new gcd_private::GCDDevice); - device->setup_type = gcd_private::SETUP_TYPE_MDNS; - device->device_id = kIDPrefixMdns + name; - device->device_type = description.type; - device->device_name = description.name; - device->device_description = description.description; - if (!description.id.empty()) - device->cloud_id.reset(new std::string(description.id)); - - known_devices_[device->device_id] = device; - - EventRouter::Get(browser_context_) - ->BroadcastEvent(MakeDeviceStateChangedEvent(*device)); -} - -void GcdPrivateAPIImpl::DeviceRemoved(const std::string& name) { - GCDDeviceMap::iterator found = known_devices_.find(kIDPrefixMdns + name); - linked_ptr<gcd_private::GCDDevice> device = found->second; - known_devices_.erase(found); - - EventRouter::Get(browser_context_) - ->BroadcastEvent(MakeDeviceRemovedEvent(device->device_id)); -} - -void GcdPrivateAPIImpl::DeviceCacheFlushed() { - for (GCDDeviceMap::iterator i = known_devices_.begin(); - i != known_devices_.end(); - i++) { - EventRouter::Get(browser_context_) - ->BroadcastEvent(MakeDeviceRemovedEvent(i->second->device_id)); - } - - known_devices_.clear(); } // static @@ -290,15 +121,6 @@ GcdPrivateAPIImpl* GcdPrivateAPIImpl::Get(content::BrowserContext* context) { return gcd_api ? gcd_api->impl_.get() : NULL; } -bool GcdPrivateAPIImpl::QueryForDevices() { - if (!privet_device_lister_) - return false; - - privet_device_lister_->DiscoverNewDevices(true); - - return true; -} - void GcdPrivateAPIImpl::CreateSession(const std::string& service_name, const CreateSessionCallback& callback) { int session_id = last_session_id_++; @@ -374,19 +196,9 @@ void GcdPrivateAPIImpl::SendMessage(int session_id, } if (!wifi->HasKey(kPrivetKeyPassphrase)) { - // If the message is a setup message, has a wifi section, try sending - // the passphrase. - - PasswordMap::iterator found = wifi_passwords_.find(ssid); - if (found == wifi_passwords_.end()) { - LOG(ERROR) << "Password is unknown"; - return callback.Run(gcd_private::STATUS_WIFIPASSWORDERROR, - base::DictionaryValue()); - } - - input_cloned.reset(input.DeepCopy()); - input_cloned->SetString(kPrivetKeyPassphraseDotted, found->second); - input_actual = input_cloned.get(); + LOG(ERROR) << "Password is unknown"; + return callback.Run(gcd_private::STATUS_WIFIPASSWORDERROR, + base::DictionaryValue()); } } } @@ -401,11 +213,6 @@ void GcdPrivateAPIImpl::SendMessage(int session_id, found->second.session->SendMessage(api, *input_actual, callback); } -void GcdPrivateAPIImpl::RequestWifiPassword(const std::string& ssid, - const SuccessCallback& callback) { - callback.Run(false); -} - void GcdPrivateAPIImpl::RemoveSession(int session_id) { sessions_.erase(session_id); } @@ -437,140 +244,6 @@ GcdPrivateAPI::GetFactoryInstance() { return g_factory.Pointer(); } -// static -void GcdPrivateAPI::SetGCDApiFlowFactoryForTests( - GCDApiFlowFactoryForTests* factory) { - g_gcd_api_flow_factory = factory; -} - -GcdPrivateGetCloudDeviceListFunction::GcdPrivateGetCloudDeviceListFunction() { -} - -GcdPrivateGetCloudDeviceListFunction::~GcdPrivateGetCloudDeviceListFunction() { -} - -bool GcdPrivateGetCloudDeviceListFunction::RunAsync() { - requests_succeeded_ = 0; - requests_failed_ = 0; - - printer_list_ = MakeGCDApiFlow(GetProfile()); - device_list_ = MakeGCDApiFlow(GetProfile()); - - if (!printer_list_ || !device_list_) - return false; - - // Balanced in CheckListingDone() - AddRef(); - - printer_list_->Start(make_scoped_ptr<local_discovery::GCDApiFlow::Request>( - new local_discovery::CloudPrintPrinterList(this))); - device_list_->Start(make_scoped_ptr<local_discovery::GCDApiFlow::Request>( - new local_discovery::CloudDeviceList(this))); - - return true; -} - -void GcdPrivateGetCloudDeviceListFunction::OnDeviceListReady( - const DeviceList& devices) { - requests_succeeded_++; - - devices_.insert(devices_.end(), devices.begin(), devices.end()); - - CheckListingDone(); -} - -void GcdPrivateGetCloudDeviceListFunction::OnDeviceListUnavailable() { - requests_failed_++; - - CheckListingDone(); -} - -void GcdPrivateGetCloudDeviceListFunction::CheckListingDone() { - if (requests_failed_ + requests_succeeded_ != kNumRequestsNeeded) - return; - - if (requests_succeeded_ == 0) { - SendResponse(false); - return; - } - - std::vector<linked_ptr<gcd_private::GCDDevice> > devices; - - for (DeviceList::iterator i = devices_.begin(); i != devices_.end(); i++) { - linked_ptr<gcd_private::GCDDevice> device(new gcd_private::GCDDevice); - device->setup_type = gcd_private::SETUP_TYPE_CLOUD; - if (i->type == local_discovery::kGCDTypePrinter) { - device->device_id = kIDPrefixCloudPrinter + i->id; - } else { - device->device_id = kIDPrefixGcd + i->id; - } - - device->cloud_id.reset(new std::string(i->id)); - device->device_type = i->type; - device->device_name = i->display_name; - device->device_description = i->description; - - devices.push_back(device); - } - - results_ = gcd_private::GetCloudDeviceList::Results::Create(devices); - - SendResponse(true); - Release(); -} - -GcdPrivateQueryForNewLocalDevicesFunction:: - GcdPrivateQueryForNewLocalDevicesFunction() { -} - -GcdPrivateQueryForNewLocalDevicesFunction:: - ~GcdPrivateQueryForNewLocalDevicesFunction() { -} - -bool GcdPrivateQueryForNewLocalDevicesFunction::RunSync() { - GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); - - if (!gcd_api->QueryForDevices()) { - error_ = - "You must first subscribe to onDeviceStateChanged or onDeviceRemoved " - "notifications"; - return false; - } - - return true; -} - -GcdPrivatePrefetchWifiPasswordFunction:: - GcdPrivatePrefetchWifiPasswordFunction() { -} - -GcdPrivatePrefetchWifiPasswordFunction:: - ~GcdPrivatePrefetchWifiPasswordFunction() { -} - -bool GcdPrivatePrefetchWifiPasswordFunction::RunAsync() { - scoped_ptr<gcd_private::PrefetchWifiPassword::Params> params = - gcd_private::PrefetchWifiPassword::Params::Create(*args_); - - if (!params) - return false; - - GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); - - gcd_api->RequestWifiPassword( - params->ssid, - base::Bind(&GcdPrivatePrefetchWifiPasswordFunction::OnResponse, this)); - - return true; -} - -void GcdPrivatePrefetchWifiPasswordFunction::OnResponse(bool response) { - scoped_ptr<base::FundamentalValue> response_value( - new base::FundamentalValue(response)); - SetResult(response_value.release()); - SendResponse(true); -} - GcdPrivateGetDeviceInfoFunction::GcdPrivateGetDeviceInfoFunction() { } @@ -770,74 +443,4 @@ bool GcdPrivateTerminateSessionFunction::RunAsync() { return true; } -GcdPrivateGetCommandDefinitionsFunction:: - GcdPrivateGetCommandDefinitionsFunction() { -} - -GcdPrivateGetCommandDefinitionsFunction:: - ~GcdPrivateGetCommandDefinitionsFunction() { -} - -GcdPrivateGetPrefetchedWifiNameListFunction:: - GcdPrivateGetPrefetchedWifiNameListFunction() { -} - -GcdPrivateGetPrefetchedWifiNameListFunction:: - ~GcdPrivateGetPrefetchedWifiNameListFunction() { -} - -bool GcdPrivateGetPrefetchedWifiNameListFunction::RunSync() { - GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); - - scoped_ptr<base::ListValue> ssid_list = gcd_api->GetPrefetchedSSIDList(); - - SetResult(ssid_list.release()); - - return true; -} - -bool GcdPrivateGetCommandDefinitionsFunction::RunAsync() { - return false; -} - -GcdPrivateInsertCommandFunction::GcdPrivateInsertCommandFunction() { -} - -GcdPrivateInsertCommandFunction::~GcdPrivateInsertCommandFunction() { -} - -bool GcdPrivateInsertCommandFunction::RunAsync() { - return false; -} - -GcdPrivateGetCommandFunction::GcdPrivateGetCommandFunction() { -} - -GcdPrivateGetCommandFunction::~GcdPrivateGetCommandFunction() { -} - -bool GcdPrivateGetCommandFunction::RunAsync() { - return false; -} - -GcdPrivateCancelCommandFunction::GcdPrivateCancelCommandFunction() { -} - -GcdPrivateCancelCommandFunction::~GcdPrivateCancelCommandFunction() { -} - -bool GcdPrivateCancelCommandFunction::RunAsync() { - return false; -} - -GcdPrivateGetCommandsListFunction::GcdPrivateGetCommandsListFunction() { -} - -GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() { -} - -bool GcdPrivateGetCommandsListFunction::RunAsync() { - return false; -} - } // namespace extensions diff --git a/chrome/browser/extensions/api/gcd_private/gcd_private_api.h b/chrome/browser/extensions/api/gcd_private/gcd_private_api.h index 856133a..746e387 100644 --- a/chrome/browser/extensions/api/gcd_private/gcd_private_api.h +++ b/chrome/browser/extensions/api/gcd_private/gcd_private_api.h @@ -7,32 +7,18 @@ #include "base/memory/scoped_ptr.h" #include "chrome/browser/extensions/chrome_extension_function.h" -#include "chrome/browser/local_discovery/cloud_device_list_delegate.h" #include "chrome/common/extensions/api/gcd_private.h" #include "extensions/browser/browser_context_keyed_api_factory.h" -namespace local_discovery { -class GCDApiFlow; -} - namespace extensions { class GcdPrivateAPIImpl; class GcdPrivateAPI : public BrowserContextKeyedAPI { public: - class GCDApiFlowFactoryForTests { - public: - virtual ~GCDApiFlowFactoryForTests() {} - - virtual scoped_ptr<local_discovery::GCDApiFlow> CreateGCDApiFlow() = 0; - }; - explicit GcdPrivateAPI(content::BrowserContext* context); ~GcdPrivateAPI() override; - static void SetGCDApiFlowFactoryForTests(GCDApiFlowFactoryForTests* factory); - // BrowserContextKeyedAPI implementation. static BrowserContextKeyedAPIFactory<GcdPrivateAPI>* GetFactoryInstance(); @@ -46,83 +32,6 @@ class GcdPrivateAPI : public BrowserContextKeyedAPI { scoped_ptr<GcdPrivateAPIImpl> impl_; }; -class GcdPrivateGetCloudDeviceListFunction - : public ChromeAsyncExtensionFunction, - public local_discovery::CloudDeviceListDelegate { - public: - DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCloudDeviceList", - GCDPRIVATE_GETCLOUDDEVICELIST) - - GcdPrivateGetCloudDeviceListFunction(); - - protected: - ~GcdPrivateGetCloudDeviceListFunction() override; - - // AsyncExtensionFunction overrides. - bool RunAsync() override; - - private: - // CloudDeviceListDelegate implementation - void OnDeviceListReady(const DeviceList& devices) override; - void OnDeviceListUnavailable() override; - - void CheckListingDone(); - - int requests_succeeded_; - int requests_failed_; - DeviceList devices_; - - scoped_ptr<local_discovery::GCDApiFlow> printer_list_; - scoped_ptr<local_discovery::GCDApiFlow> device_list_; -}; - -class GcdPrivateQueryForNewLocalDevicesFunction - : public ChromeSyncExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("gcdPrivate.queryForNewLocalDevices", - GCDPRIVATE_QUERYFORNEWLOCALDEVICES) - - GcdPrivateQueryForNewLocalDevicesFunction(); - - protected: - ~GcdPrivateQueryForNewLocalDevicesFunction() override; - - // SyncExtensionFunction overrides. - bool RunSync() override; -}; - -class GcdPrivatePrefetchWifiPasswordFunction - : public ChromeAsyncExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("gcdPrivate.prefetchWifiPassword", - GCDPRIVATE_PREFETCHWIFIPASSWORD) - - GcdPrivatePrefetchWifiPasswordFunction(); - - protected: - ~GcdPrivatePrefetchWifiPasswordFunction() override; - - // AsyncExtensionFunction overrides. - bool RunAsync() override; - - void OnResponse(bool response); -}; - -class GcdPrivateGetPrefetchedWifiNameListFunction - : public ChromeSyncExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("gcdPrivate.getPrefetchedWifiNameList", - GCDPRIVATE_GETPREFETCHEDWIFINAMELIST); - - GcdPrivateGetPrefetchedWifiNameListFunction(); - - protected: - ~GcdPrivateGetPrefetchedWifiNameListFunction() override; - - // SyncExtensionFunction overrides. - bool RunSync() override; -}; - class GcdPrivateGetDeviceInfoFunction : public ChromeAsyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("gcdPrivate.getDeviceInfo", @@ -226,86 +135,6 @@ class GcdPrivateTerminateSessionFunction : public ChromeAsyncExtensionFunction { bool RunAsync() override; }; -class GcdPrivateGetCommandDefinitionsFunction - : public ChromeAsyncExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommandDefinitions", - GCDPRIVATE_GETCOMMANDDEFINITIONS) - - GcdPrivateGetCommandDefinitionsFunction(); - - protected: - ~GcdPrivateGetCommandDefinitionsFunction() override; - - // AsyncExtensionFunction overrides. - bool RunAsync() override; - - private: -}; - -class GcdPrivateInsertCommandFunction : public ChromeAsyncExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("gcdPrivate.insertCommand", - GCDPRIVATE_INSERTCOMMAND) - - GcdPrivateInsertCommandFunction(); - - protected: - ~GcdPrivateInsertCommandFunction() override; - - // AsyncExtensionFunction overrides. - bool RunAsync() override; - - private: -}; - -class GcdPrivateGetCommandFunction : public ChromeAsyncExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommand", GCDPRIVATE_GETCOMMAND) - - GcdPrivateGetCommandFunction(); - - protected: - ~GcdPrivateGetCommandFunction() override; - - // AsyncExtensionFunction overrides. - bool RunAsync() override; - - private: -}; - -class GcdPrivateCancelCommandFunction : public ChromeAsyncExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("gcdPrivate.cancelCommand", - GCDPRIVATE_CANCELCOMMAND) - - GcdPrivateCancelCommandFunction(); - - protected: - ~GcdPrivateCancelCommandFunction() override; - - // AsyncExtensionFunction overrides. - bool RunAsync() override; - - private: -}; - -class GcdPrivateGetCommandsListFunction : public ChromeAsyncExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommandsList", - GCDPRIVATE_GETCOMMANDSLIST) - - GcdPrivateGetCommandsListFunction(); - - protected: - ~GcdPrivateGetCommandsListFunction() override; - - // AsyncExtensionFunction overrides. - bool RunAsync() override; - - private: -}; - } // namespace extensions #endif // CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_ diff --git a/chrome/browser/extensions/api/gcd_private/gcd_private_apitest.cc b/chrome/browser/extensions/api/gcd_private/gcd_private_apitest.cc index 1552a78..f2c6b33 100644 --- a/chrome/browser/extensions/api/gcd_private/gcd_private_apitest.cc +++ b/chrome/browser/extensions/api/gcd_private/gcd_private_apitest.cc @@ -2,65 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/bind.h" #include "base/command_line.h" -#include "base/json/json_reader.h" -#include "base/thread_task_runner_handle.h" #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h" #include "chrome/browser/extensions/extension_apitest.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/local_discovery/gcd_api_flow.h" +#include "chrome/browser/local_discovery/test_service_discovery_client.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/extensions/api/mdns.h" #include "extensions/common/switches.h" #include "net/url_request/test_url_fetcher_factory.h" -#include "testing/gmock/include/gmock/gmock.h" - -#if defined(ENABLE_MDNS) -#include "chrome/browser/local_discovery/test_service_discovery_client.h" -#endif // ENABLE_MDNS namespace api = extensions::api; -using testing::Invoke; - namespace { -const char kCloudPrintResponse[] = - "{" - " \"success\": true," - " \"printers\": [" - " {\"id\" : \"someCloudPrintID\"," - " \"displayName\": \"someCloudPrintDisplayName\"," - " \"description\": \"someCloudPrintDescription\"}" - " ]" - "}"; - -const char kGCDResponse[] = - "{" - "\"kind\": \"clouddevices#devicesListResponse\"," - "\"devices\": [{" - " \"kind\": \"clouddevices#device\"," - " \"id\": \"someGCDID\"," - " \"deviceKind\": \"someType\"," - " \"creationTimeMs\": \"123\"," - " \"systemName\": \"someGCDDisplayName\"," - " \"owner\": \"user@domain.com\"," - " \"description\": \"someGCDDescription\"," - " \"state\": {" - " \"base\": {" - " \"connectionStatus\": \"offline\"" - " }" - " }," - " \"channel\": {" - " \"supportedType\": \"xmpp\"" - " }," - " \"personalizedInfo\": {" - " \"maxRole\": \"owner\"" - " }}]}"; - -#if defined(ENABLE_MDNS) - const char kPrivetInfoResponse[] = "{\"version\":\"3.0\"," "\"endpoints\":{\"httpsPort\": 443}," @@ -120,103 +73,6 @@ const uint8 kAnnouncePacket[] = { 0x03, 0x04, }; -const uint8 kGoodbyePacket[] = { - // Header - 0x00, 0x00, // ID is zeroed out - 0x80, 0x00, // Standard query response, RA, no error - 0x00, 0x00, // No questions (for simplicity) - 0x00, 0x02, // 1 RR (answers) - 0x00, 0x00, // 0 authority RRs - 0x00, 0x00, // 0 additional RRs - 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', - 'p', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x0c, // TYPE is PTR. - 0x00, 0x01, // CLASS is IN. - 0x00, 0x00, // TTL (4 bytes) is 0 seconds. - 0x00, 0x00, 0x00, 0x0c, // RDLENGTH is 12 bytes. - 0x09, 'm', 'y', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 0xc0, 0x0c, - 0x09, 'm', 'y', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 0xc0, 0x0c, - 0x00, 0x21, // Type is SRV - 0x00, 0x01, // CLASS is IN - 0x00, 0x00, // TTL (4 bytes) is 0 seconds. - 0x00, 0x00, 0x00, 0x17, // RDLENGTH is 23 - 0x00, 0x00, 0x00, 0x00, 0x22, 0xb8, // port 8888 - 0x09, 'm', 'y', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 0x05, 'l', - 'o', 'c', 'a', 'l', 0x00, -}; - -const uint8 kQueryPacket[] = { - // Header - 0x00, 0x00, // ID is zeroed out - 0x00, 0x00, // No flags. - 0x00, 0x01, // One question. - 0x00, 0x00, // 0 RRs (answers) - 0x00, 0x00, // 0 authority RRs - 0x00, 0x00, // 0 additional RRs - - // Question - // This part is echoed back from the respective query. - 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', - 'p', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x0c, // TYPE is PTR. - 0x00, 0x01, // CLASS is IN. -}; - -#endif // ENABLE_MDNS - -// Sentinel value to signify the request should fail. -const char kResponseValueFailure[] = "FAILURE"; - -class FakeGCDApiFlowFactory - : public extensions::GcdPrivateAPI::GCDApiFlowFactoryForTests { - public: - FakeGCDApiFlowFactory() { - extensions::GcdPrivateAPI::SetGCDApiFlowFactoryForTests(this); - } - - ~FakeGCDApiFlowFactory() override { - extensions::GcdPrivateAPI::SetGCDApiFlowFactoryForTests(NULL); - } - - scoped_ptr<local_discovery::GCDApiFlow> CreateGCDApiFlow() override { - return scoped_ptr<local_discovery::GCDApiFlow>(new FakeGCDApiFlow(this)); - } - - void SetResponse(const GURL& url, const std::string& response) { - responses_[url] = response; - } - - private: - class FakeGCDApiFlow : public local_discovery::GCDApiFlow { - public: - explicit FakeGCDApiFlow(FakeGCDApiFlowFactory* factory) - : factory_(factory) {} - - ~FakeGCDApiFlow() override {} - - void Start(scoped_ptr<Request> request) override { - std::string response_str = factory_->responses_[request->GetURL()]; - - if (response_str == kResponseValueFailure) { - request->OnGCDAPIFlowError( - local_discovery::GCDApiFlow::ERROR_MALFORMED_RESPONSE); - return; - } - - scoped_ptr<base::Value> response = base::JSONReader::Read(response_str); - ASSERT_TRUE(response); - - base::DictionaryValue* response_dict; - ASSERT_TRUE(response->GetAsDictionary(&response_dict)); - - request->OnGCDAPIFlowComplete(*response_dict); - } - - private: - FakeGCDApiFlowFactory* factory_; - }; - - std::map<GURL /*request url*/, std::string /*response json*/> responses_; -}; - class GcdPrivateAPITest : public ExtensionApiTest { public: GcdPrivateAPITest() : url_fetcher_factory_(&url_fetcher_impl_factory_) { @@ -231,22 +87,10 @@ class GcdPrivateAPITest : public ExtensionApiTest { } protected: - FakeGCDApiFlowFactory api_flow_factory_; net::URLFetcherImplFactory url_fetcher_impl_factory_; net::FakeURLFetcherFactory url_fetcher_factory_; }; -IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, GetCloudList) { - api_flow_factory_.SetResponse( - GURL("https://www.google.com/cloudprint/search"), kCloudPrintResponse); - - api_flow_factory_.SetResponse( - GURL("https://www.googleapis.com/clouddevices/v1/devices"), kGCDResponse); - - EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "get_cloud_list.html")); -} - -#if defined(ENABLE_MDNS) class GcdPrivateWithMdnsAPITest : public GcdPrivateAPITest { public: void SetUpOnMainThread() override { @@ -296,35 +140,4 @@ IN_PROC_BROWSER_TEST_F(GcdPrivateWithMdnsAPITest, Session) { EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "session.html")); } -IN_PROC_BROWSER_TEST_F(GcdPrivateWithMdnsAPITest, AddBefore) { - test_service_discovery_client_->SimulateReceive(kAnnouncePacket, - sizeof(kAnnouncePacket)); - - EXPECT_TRUE( - RunExtensionSubtest("gcd_private/api", "receive_new_device.html")); -} - -IN_PROC_BROWSER_TEST_F(GcdPrivateWithMdnsAPITest, AddAfter) { - SimulateReceiveWithDelay(kAnnouncePacket, sizeof(kAnnouncePacket)); - EXPECT_TRUE( - RunExtensionSubtest("gcd_private/api", "receive_new_device.html")); -} - -IN_PROC_BROWSER_TEST_F(GcdPrivateWithMdnsAPITest, AddRemove) { - test_service_discovery_client_->SimulateReceive(kAnnouncePacket, - sizeof(kAnnouncePacket)); - SimulateReceiveWithDelay(kGoodbyePacket, sizeof(kGoodbyePacket)); - EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "remove_device.html")); -} - -IN_PROC_BROWSER_TEST_F(GcdPrivateWithMdnsAPITest, SendQuery) { - if (ExtensionSubtestsAreSkipped()) - return; - EXPECT_CALL(*test_service_discovery_client_.get(), - OnSendTo(std::string(reinterpret_cast<const char*>(kQueryPacket), - sizeof(kQueryPacket)))).Times(2); - EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "send_query.html")); -} -#endif // ENABLE_MDNS - } // namespace diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index e134a8d..55d4fa9 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -157,7 +157,6 @@ 'browser/extensions/api/file_system/file_system_apitest.cc', 'browser/extensions/api/file_system/file_system_apitest_chromeos.cc', 'browser/extensions/api/font_settings/font_settings_apitest.cc', - 'browser/extensions/api/gcd_private/gcd_private_apitest.cc', 'browser/extensions/api/gcm/gcm_apitest.cc', 'browser/extensions/api/history/history_apitest.cc', 'browser/extensions/api/hotword_private/hotword_private_apitest.cc', @@ -2596,6 +2595,7 @@ }], ['enable_mdns==1', { 'sources' : [ + 'browser/extensions/api/gcd_private/gcd_private_apitest.cc', 'browser/ui/webui/local_discovery/local_discovery_ui_browsertest.cc', ] }], diff --git a/chrome/common/extensions/api/gcd_private.idl b/chrome/common/extensions/api/gcd_private.idl index ac5481f..12f5c43 100644 --- a/chrome/common/extensions/api/gcd_private.idl +++ b/chrome/common/extensions/api/gcd_private.idl @@ -6,29 +6,6 @@ // them. namespace gcdPrivate { - enum SetupType { mdns, wifi, cloud }; - - // Represents a GCD device discovered locally or registered to a given user. - dictionary GCDDevice { - // Opaque device identifier to be passed to API. - DOMString deviceId; - - // How this device was discovered. - SetupType setupType; - - // Cloud identifier string. - DOMString? cloudId; - - // Device type (camera, printer, etc) - DOMString deviceType; - - // Device human readable name. - DOMString deviceName; - - // Device human readable description. - DOMString deviceDescription; - }; - enum Status { // Success. success, @@ -61,28 +38,9 @@ namespace gcdPrivate { enum PairingType { pinCode, - embeddedCode, - ultrasound32, - audible32 + embeddedCode }; - callback CloudDeviceListCallback = void(GCDDevice[] devices); - - // |commandDefinitions| : Is "commandDefs" value of device described at - // https://developers.google.com/cloud-devices/v1/reference/devices - // TODO(vitalybuka): consider to describe object in IDL. - callback CommandDefinitionsCallback = void(object commandDefinitions); - - // |command| : Described at - // https://developers.google.com/cloud-devices/v1/reference/commands - // TODO(vitalybuka): consider to describe object in IDL. - callback CommandCallback = void(object command); - - // |commands| : Array of commands described at - // https://developers.google.com/cloud-devices/v1/reference/commands - // TODO(vitalybuka): consider to describe object in IDL. - callback CommandListCallback = void(object[] commands); - // Generic callback for session calls, with status only. callback SessionCallback = void(Status status); @@ -112,30 +70,7 @@ namespace gcdPrivate { // |success| : Denotes whether the password fetch has succeeded or failed. callback SuccessCallback = void(boolean success); - // Called as a response to |getPrefetchedWifiNameList| - // |networks| : The list of SSIDs for which wifi passwords were prefetched. - callback SSIDListCallback = void(DOMString[] networks); - interface Functions { - // Returns the list of cloud devices visible locally or available in the - // cloud for user account. - static void getCloudDeviceList(CloudDeviceListCallback callback); - - // Queries network for local devices. Triggers an onDeviceStateChanged and - // onDeviceRemoved events. Call this function *only* after registering for - // onDeviceStateChanged and onDeviceRemoved events, or it will do nothing. - static void queryForNewLocalDevices(); - - // Cache the WiFi password in the browser process for use during - // provisioning. This is done to allow the gathering of the wifi password to - // not be done while connected to the device's network. Callback is called - // with true if wifi password was cached and false if it was unavailable. - // |ssid| : The network to prefetch password for. - static void prefetchWifiPassword(DOMString ssid, SuccessCallback callback); - - // Get the list of SSIDs with prefetched callbacks. - static void getPrefetchedWifiNameList(SSIDListCallback callback); - // Returns local device information. // |serviceName| : The mDns service name of the device. static void getDeviceInfo(DOMString serviceName, @@ -179,57 +114,5 @@ namespace gcdPrivate { // Terminate the session with the device. // |sessionId| : The ID of the session created with |establishSession|. static void terminateSession(long sessionId); - - // Returns command definitions. - // |deviceId| : The device to get command definitions for. - // |callback| : The result callback. - static void getCommandDefinitions(DOMString deviceId, - CommandDefinitionsCallback callback); - - // Creates and sends a new command. - // |deviceId| : The device to send the command to. - // |expireInMs| : The number of milliseconds since now before the command - // expires. Expired command should not be executed by device. Acceptable - // values are 10000 to 2592000000, inclusive. All values outside that range - // will be replaced by 2592000000. - // |command| : Described at - // https://developers.google.com/cloud-devices/v1/reference/commands - // |callback| : The result callback. - static void insertCommand(DOMString deviceId, - long expireInMs, - object command, - CommandCallback callback); - - // Returns a particular command. - // |commandId| : Unique command ID. - // |callback| : The result callback. - static void getCommand(DOMString commandId, CommandCallback callback); - - // Cancels a command. - // |commandId| : Unique command ID. - // |callback| : The result callback. - static void cancelCommand(DOMString commandId, CommandCallback callback); - - // Lists all commands in order of creation. - // |deviceId| : The device to get the commands for. - // |byUser| : List all the commands issued by the user. Special value 'me' - // can be used to list by the current user. - // |state| : Command state. - // |callback| : The result callback. - static void getCommandsList(DOMString deviceId, - DOMString byUser, - DOMString state, - CommandListCallback callback); - }; - - interface Events { - // Subscribe to this event to start listening new or updated devices. New - // listeners will get called with all known devices on the network, and - // status updates for devices available through the cloud. - static void onDeviceStateChanged(GCDDevice device); - - // Notifies that device has disappeared. - // |deviceId| : The device has disappeared. - static void onDeviceRemoved(DOMString deviceId); }; }; diff --git a/chrome/test/data/extensions/api_test/gcd_private/api/get_cloud_list.html b/chrome/test/data/extensions/api_test/gcd_private/api/get_cloud_list.html deleted file mode 100644 index c658bdd..0000000 --- a/chrome/test/data/extensions/api_test/gcd_private/api/get_cloud_list.html +++ /dev/null @@ -1 +0,0 @@ -<script src="get_cloud_list.js"></script> diff --git a/chrome/test/data/extensions/api_test/gcd_private/api/get_cloud_list.js b/chrome/test/data/extensions/api_test/gcd_private/api/get_cloud_list.js deleted file mode 100644 index 3dfb44f..0000000 --- a/chrome/test/data/extensions/api_test/gcd_private/api/get_cloud_list.js +++ /dev/null @@ -1,37 +0,0 @@ -// 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. - -onload = function() { - chrome.test.runTests([ - function getCloudList() { - chrome.gcdPrivate.getCloudDeviceList(function(services) { - // Sort to avoid order dependence - services.sort(function(a,b) { - return a.deviceId.localeCompare(b.deviceId); - }); - - chrome.test.assertEq(2, services.length); - - chrome.test.assertEq(services[0].setupType, "cloud"); - chrome.test.assertEq(services[0].deviceId, - "cloudprint:someCloudPrintID"); - chrome.test.assertEq(services[0].cloudId, "someCloudPrintID"); - chrome.test.assertEq(services[0].deviceType, "printer"); - chrome.test.assertEq(services[0].deviceName, - "someCloudPrintDisplayName"); - chrome.test.assertEq(services[0].deviceDescription, - "someCloudPrintDescription"); - - chrome.test.assertEq(services[1].setupType, "cloud"); - chrome.test.assertEq(services[1].deviceId, "gcd:someGCDID"); - chrome.test.assertEq(services[1].cloudId, "someGCDID"); - chrome.test.assertEq(services[1].deviceType, "someType"); - chrome.test.assertEq(services[1].deviceName, "someGCDDisplayName"); - chrome.test.assertEq(services[1].deviceDescription, - "someGCDDescription"); - - chrome.test.notifyPass(); - }) - }]); -}; diff --git a/chrome/test/data/extensions/api_test/gcd_private/api/receive_new_device.html b/chrome/test/data/extensions/api_test/gcd_private/api/receive_new_device.html deleted file mode 100644 index 5570a76..0000000 --- a/chrome/test/data/extensions/api_test/gcd_private/api/receive_new_device.html +++ /dev/null @@ -1 +0,0 @@ -<script src="receive_new_device.js"></script> diff --git a/chrome/test/data/extensions/api_test/gcd_private/api/receive_new_device.js b/chrome/test/data/extensions/api_test/gcd_private/api/receive_new_device.js deleted file mode 100644 index cc52e80..0000000 --- a/chrome/test/data/extensions/api_test/gcd_private/api/receive_new_device.js +++ /dev/null @@ -1,22 +0,0 @@ -// 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. - -onload = function() { - chrome.test.runTests([ - function receiveNewDevice() { - chrome.gcdPrivate.onDeviceStateChanged.addListener( - function(device) { - chrome.test.assertEq(device.setupType, "mdns"); - chrome.test.assertEq(device.deviceId, - "mdns:myService._privet._tcp.local"); - chrome.test.assertEq(device.deviceType, "printer"); - chrome.test.assertEq(device.deviceName, - "Sample device"); - chrome.test.assertEq(device.deviceDescription, - "Sample device description"); - - chrome.test.notifyPass(); - }) - }]); -}; diff --git a/chrome/test/data/extensions/api_test/gcd_private/api/remove_device.html b/chrome/test/data/extensions/api_test/gcd_private/api/remove_device.html deleted file mode 100644 index ecbcf39a..0000000 --- a/chrome/test/data/extensions/api_test/gcd_private/api/remove_device.html +++ /dev/null @@ -1 +0,0 @@ -<script src="remove_device.js"></script> diff --git a/chrome/test/data/extensions/api_test/gcd_private/api/remove_device.js b/chrome/test/data/extensions/api_test/gcd_private/api/remove_device.js deleted file mode 100644 index af281bf..0000000 --- a/chrome/test/data/extensions/api_test/gcd_private/api/remove_device.js +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -onload = function() { - chrome.test.runTests([ - function addRemoveDevice() { - chrome.gcdPrivate.onDeviceRemoved.addListener( - function(deviceId) { - chrome.test.assertEq(deviceId, - "mdns:myService._privet._tcp.local"); - chrome.test.notifyPass(); - }) - }]); -}; diff --git a/chrome/test/data/extensions/api_test/gcd_private/api/send_query.html b/chrome/test/data/extensions/api_test/gcd_private/api/send_query.html deleted file mode 100644 index e101848..0000000 --- a/chrome/test/data/extensions/api_test/gcd_private/api/send_query.html +++ /dev/null @@ -1 +0,0 @@ -<script src="send_query.js"></script> diff --git a/chrome/test/data/extensions/api_test/gcd_private/api/send_query.js b/chrome/test/data/extensions/api_test/gcd_private/api/send_query.js deleted file mode 100644 index 519e5f4..0000000 --- a/chrome/test/data/extensions/api_test/gcd_private/api/send_query.js +++ /dev/null @@ -1,13 +0,0 @@ -// 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. - -onload = function() { - chrome.test.runTests([ - function sendQuery() { - chrome.gcdPrivate.onDeviceStateChanged.addListener(function(device) {}); - chrome.gcdPrivate.queryForNewLocalDevices(); - chrome.test.notifyPass(); - } - ]); -}; |