Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1021)

Unified Diff: chrome/browser/extensions/api/networking_private/networking_private_process_client.h

Issue 22295002: Base infrastructure for Networking Private API on Windows and Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use crypto_verify_mock for browser_test. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/networking_private/networking_private_process_client.h
diff --git a/chrome/browser/extensions/api/networking_private/networking_private_process_client.h b/chrome/browser/extensions/api/networking_private/networking_private_process_client.h
new file mode 100644
index 0000000000000000000000000000000000000000..3b33cd040092244610ba7b9abe44fc6f9ca593de
--- /dev/null
+++ b/chrome/browser/extensions/api/networking_private/networking_private_process_client.h
@@ -0,0 +1,248 @@
+// Copyright 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.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_PROCESS_CLIENT_H_
+#define CHROME_BROWSER_EXTENSIONS_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_PROCESS_CLIENT_H_
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/id_map.h"
+#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
+#include "base/strings/string16.h"
+#include "base/supports_user_data.h"
+#include "base/values.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/utility_process_host.h"
+#include "content/public/browser/utility_process_host_client.h"
+
+class Profile;
+
+namespace extensions {
+
+namespace api {
+namespace networking_private {
+struct VerificationProperties;
+} // namespace networking_private
+} // namespace api
+
+// This class is the client for the out-of-process networkingPrivate handler.
+class NetworkingPrivateProcessClient
+ : public content::UtilityProcessHostClient {
+ public:
+ // Interface for Verify* methods implementation.
+ class CryptoVerify {
+ public:
+ virtual bool VerifyDestination(
+ const api::networking_private::VerificationProperties& properties) = 0;
+
+ virtual bool VerifyAndEncryptData(
+ const api::networking_private::VerificationProperties& properties,
+ const std::string& plaintext,
+ std::string* base64_encoded_ciphertext) = 0;
+ };
+
+ // Interface for observing Network Events.
+ class Observer {
+ public:
+ virtual void OnNetworksChangedEvent(
+ const std::vector<std::string>& network_guids) = 0;
+ virtual void OnNetworkListChangedEvent(
+ const std::vector<std::string>& network_guids) = 0;
+ };
+
+ // An error callback used by most of API functions to receive error results
+ // from the NetworkingPrivateProcessClient.
+ typedef base::Callback<
+ void(const std::string& error_name,
+ scoped_ptr<base::DictionaryValue> error_data)> ErrorCallback;
+
+ // An error callback used by most of Crypto Verify* API functions to receive
+ // error results from the NetworkingPrivateProcessClient.
+ // TODO(mef): Cleanup networking_private_api.* to make consistent
+ // NetworkingPrivateXXXFunction naming and error callbacks.
+ typedef base::Callback<
+ void(const std::string& error_name,
+ const std::string& error)> CryptoErrorCallback;
+
+ // Callback used to return bool result from VerifyDestination function.
+ typedef base::Callback<void(bool result)> BoolResultCallback;
+
+ // Callback used to return string result from VerifyAndEncryptData function.
+ typedef base::Callback<void(const std::string& result)> StringResultCallback;
+
+ // Callback used to return Dictionary of network properties.
+ typedef base::Callback<
+ void(const std::string& network_guid,
+ const base::DictionaryValue& dictionary)> DictionaryResultCallback;
+
+ // Callback used to return List of visibile networks.
+ typedef base::Callback<
+ void(const base::ListValue& network_list)> ListResultCallback;
+
+ // Callback used to notify API function of completed API call without data.
+ typedef base::Callback<void()> VoidResultCallback;
+
+ explicit NetworkingPrivateProcessClient(Profile* profile);
+
+ // Gets the properties of the network with id |service_path|. See note on
+ // |callback| and |error_callback|, in class description above.
+ void GetProperties(const std::string& service_path,
+ const DictionaryResultCallback& callback,
+ const ErrorCallback& error_callback);
+
+ // Start connect to the network with id |service_path|. See note on
+ // |callback| and |error_callback|, in class description above.
+ void StartConnect(const std::string& service_path,
+ const VoidResultCallback& callback,
+ const ErrorCallback& error_callback);
+
+ // Start disconnect from the network with id |service_path|. See note on
+ // |callback| and |error_callback|, in class description above.
+ void StartDisconnect(const std::string& service_path,
+ const VoidResultCallback& callback,
+ const ErrorCallback& error_callback);
+
+ // Sets the |properties| of the network with id |service_path|. See note on
+ // |callback| and |error_callback|, in class description above.
+ void SetProperties(const std::string& service_path,
+ const base::DictionaryValue& properties,
+ const VoidResultCallback& callback,
+ const ErrorCallback& error_callback);
+
+ // Requests network scan. Broadcasts NetworkListChangedEvent upon completion.
+ void RequestNetworkScan();
+
+ // Gets the list of visible networks and calls |callback|.
+ void GetVisibleNetworks(const ListResultCallback& callback);
+
+ // Verify that Chromecast provides valid cryptographically signed properties.
+ void VerifyDestination(scoped_ptr<base::ListValue> args,
+ const BoolResultCallback& callback,
+ const CryptoErrorCallback& error_callback);
+
+ // Verify that Chromecast provides valid cryptographically signed properties.
+ // If valid, then encrypt data using Chromecast's public key.
+ void VerifyAndEncryptData(scoped_ptr<base::ListValue> args,
+ const StringResultCallback& callback,
+ const CryptoErrorCallback& error_callback);
+
+ // Adds observer to network events.
+ void AddObserver(Observer* network_events_observer);
+
+ // Removes observer to network events. If there is no observers,
+ // then process can be shut down when there are no more calls pending return.
+ void RemoveObserver(Observer* network_events_observer);
+
+ // Switches Utility Process to use WiFiServiceMock for browser_tests and
+ // mock CryptoVerify implementation.
+ void SetUpForTest(const base::DictionaryValue& parameters,
+ CryptoVerify* crypto_verify_mock);
+
+ // Teardown test for browser_tests.
+ void TearDownForTest();
+
+ // Gets a NetworkingPrivateProcessClient instances, creating one if it
+ // doesn't exist.
+ static scoped_refptr<NetworkingPrivateProcessClient>
+ GetForProfile(Profile* profile);
+
+ private:
+ // Callbacks to run when reply message is received from UtilityProcess.
+ typedef int32 MessageCallbacksID;
+ struct MessageCallbacks {
+ MessageCallbacks();
+ ~MessageCallbacks();
+
+ DictionaryResultCallback get_properties_callback;
+ VoidResultCallback start_connect_callback;
+ VoidResultCallback start_disconnect_callback;
+ VoidResultCallback set_properties_callback;
+ ListResultCallback get_visible_networks_callback;
+ ErrorCallback error_callback;
+
+ MessageCallbacksID id;
+ };
+ typedef IDMap<MessageCallbacks, IDMapOwnPointer> MessageCallbacksMap;
+
+ // UtilityProcessHostClient implementation:
+ virtual void OnProcessCrashed(int exit_code) OVERRIDE;
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ // Message handlers
+ void OnApiError(MessageCallbacksID message_id,
+ const std::string& error_code,
+ const base::DictionaryValue& error_data);
+ void OnGetPropertiesSucceeded(MessageCallbacksID message_id,
+ const std::string& network_guid,
+ const base::DictionaryValue& properties);
+ void OnGetVisibleNetworksSucceeded(MessageCallbacksID message_id,
+ const base::ListValue& network_list);
+ void OnNetworksChangedEvent(const std::vector<std::string>& network_guids);
+ void OnNetworkListChangedEvent(const std::vector<std::string>& network_guids);
+ void OnSetPropertiesSucceeded(MessageCallbacksID message_id,
+ const std::string& network_guid);
+ void OnStartConnectSucceeded(MessageCallbacksID message_id,
+ const std::string& network_guid);
+ void OnStartDisconnectSucceeded(MessageCallbacksID message_id,
+ const std::string& network_guid);
+
+ virtual ~NetworkingPrivateProcessClient();
+
+ // Launches the task to start the external process.
+ void Start();
+ // Creates a new UtilityProcessHost, which launches the utility process.
+ void StartProcessOnIOThread(content::BrowserThread::ID thread_id);
+ // Deletes a UtilityProcessHost, which stops the utility process.
+ void ShutdownProcessOnIOThread();
+ // Shuts down utility process if there are no more events listeners and
+ // all calls are completed.
+ void ShutdownIfDone();
+
+ // Sends message to UtilityProcess.
+ void Send(IPC::Message* message);
+ void SendOnIOThread(IPC::Message* message);
+
+ void VerifyDestinationOnWorkerThread(
+ scoped_ptr<base::ListValue> args,
+ const BoolResultCallback& callback,
+ const CryptoErrorCallback& error_callback);
+
+ void VerifyAndEncryptDataOnWorkerThread(
+ scoped_ptr<base::ListValue> args,
+ const StringResultCallback& callback,
+ const CryptoErrorCallback& error_callback);
+
+ // Add new |MessageCallbacks| to |callbacks_map_|.
+ MessageCallbacks* AddMessageCallbacks();
+ // Removes MessageCallbacks for |message_id| from |callbacks_map_|.
+ // Shuts down utility process if there are no more events listeners and
+ // all calls are completed.
+ void RemoveMessageCallbacks(MessageCallbacksID message_id);
+
+ // Callbacks to run when message is received from UtilityProcess.
+ MessageCallbacksMap callbacks_map_;
+
+ // Browser profile, which is running API listening for events.
+ Profile* profile_;
+
+ // Handles sending messages to the external process. Deletes itself when
+ // the external process dies.
+ base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
+
+ // Observers to Network Events.
+ ObserverList<Observer> network_events_observers_;
+
+ // Interface for Verify* methods.
+ scoped_ptr<CryptoVerify> crypto_verify_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateProcessClient);
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_PROCESS_CLIENT_H_

Powered by Google App Engine
This is Rietveld 408576698