summaryrefslogtreecommitdiffstats
path: root/chrome/service
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-23 19:44:17 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-23 19:44:17 +0000
commit15e7eba9c74140f4e976c0d152ba738c36f14bb5 (patch)
tree1eed92b43c3dd47bd7f200f5454701d93e46fbf1 /chrome/service
parent809e10f57b8bbfb1b780e3963a7466b15aef45bf (diff)
downloadchromium_src-15e7eba9c74140f4e976c0d152ba738c36f14bb5.zip
chromium_src-15e7eba9c74140f4e976c0d152ba738c36f14bb5.tar.gz
chromium_src-15e7eba9c74140f4e976c0d152ba738c36f14bb5.tar.bz2
Move directory code from chrome/service to chrome/browser.
Renamed RemotingDirectoryService to DirectoryAddRequest. It will be used in RemotingSetupFlow to register host. Also added unittests for this code. BUG=67218 TEST=Unittests Review URL: http://codereview.chromium.org/6036001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70082 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/service')
-rw-r--r--chrome/service/remoting/remoting_directory_service.cc84
-rw-r--r--chrome/service/remoting/remoting_directory_service.h72
2 files changed, 0 insertions, 156 deletions
diff --git a/chrome/service/remoting/remoting_directory_service.cc b/chrome/service/remoting/remoting_directory_service.cc
deleted file mode 100644
index e61c0fd..0000000
--- a/chrome/service/remoting/remoting_directory_service.cc
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright (c) 2010 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 <vector>
-
-#include "base/json/json_reader.h"
-#include "base/json/json_writer.h"
-#include "base/values.h"
-#include "chrome/common/guid.h"
-#include "chrome/common/net/url_request_context_getter.h"
-#include "chrome/service/net/service_url_request_context.h"
-#include "chrome/service/remoting/remoting_directory_service.h"
-#include "net/base/net_util.h"
-#include "net/http/http_request_headers.h"
-#include "remoting/host/host_key_pair.h"
-
-static const char kRemotingDirectoryUrl[] =
- "https://www.googleapis.com/chromoting/v1/@me/hosts";
-
-RemotingDirectoryService::RemotingDirectoryService(Client* client)
- : client_(client) {
-}
-
-RemotingDirectoryService::~RemotingDirectoryService() {
- DCHECK(!fetcher_.get()) << "URLFetcher not destroyed.";
-}
-
-void RemotingDirectoryService::AddHost(const std::string& token) {
- // TODO(hclam): This is a time consuming operation so we should run it on
- // a separate thread.
- host_key_pair_.reset(new remoting::HostKeyPair());
- host_key_pair_->Generate();
-
- // Get a host name and generate a UUID for the request.
- host_id_ = guid::GenerateGUID();
- host_name_ = net::GetHostName();
-
- // Prepare the parameters for the request.
- DictionaryValue data;
- data.SetString("hostId", host_id_);
- data.SetString("hostName", host_name_);
- data.SetString("publicKey", host_key_pair_->GetPublicKey());
-
- // Generate the final json query.
- DictionaryValue args;
- args.Set("data", data.DeepCopy());
- std::string request_content;
- base::JSONWriter::Write(&args, false, &request_content);
-
- // Prepare the HTTP header for authentication.
- net::HttpRequestHeaders headers;
- headers.SetHeader("Authorization", "GoogleLogin auth=" + token);
- fetcher_.reset(
- new URLFetcher(GURL(kRemotingDirectoryUrl), URLFetcher::POST, this));
- fetcher_->set_request_context(new ServiceURLRequestContextGetter());
- fetcher_->set_upload_data("application/json", request_content);
- fetcher_->set_extra_request_headers(headers.ToString());
-
- // And then start the request.
- fetcher_->Start();
-}
-
-void RemotingDirectoryService::CancelRequest() {
- fetcher_.reset();
-}
-
-void RemotingDirectoryService::OnURLFetchComplete(
- const URLFetcher* source,
- const GURL& url,
- const URLRequestStatus& status,
- int response_code,
- const ResponseCookies& cookies,
- const std::string& data) {
- // Destroy the fetcher after the response has been received.
- fetcher_.reset();
-
- // TODO(hclam): Simply checking 200 status is not enough.
- if (response_code == 200) {
- client_->OnRemotingHostAdded();
- } else {
- client_->OnRemotingDirectoryError();
- }
-}
diff --git a/chrome/service/remoting/remoting_directory_service.h b/chrome/service/remoting/remoting_directory_service.h
deleted file mode 100644
index 2c9fc0f..0000000
--- a/chrome/service/remoting/remoting_directory_service.h
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright (c) 2010 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_SERVICE_REMOTING_REMOTING_DIRECTORY_SERVICE_H_
-#define CHROME_SERVICE_REMOTING_REMOTING_DIRECTORY_SERVICE_H_
-
-#include <string>
-
-#include "base/scoped_ptr.h"
-#include "chrome/common/net/url_fetcher.h"
-#include "googleurl/src/gurl.h"
-
-namespace remoting {
-class HostKeyPair;
-} // namespace remoting
-
-// A class to provide access to the remoting directory service.
-// TODO(hclam): Should implement this in Javascript.
-class RemotingDirectoryService : public URLFetcher::Delegate {
- public:
- // Client to receive events from the directory service.
- class Client {
- public:
- virtual ~Client() {}
-
- // Called when a remoting host was added.
- virtual void OnRemotingHostAdded() {}
-
- // Called when the last operation has failed.
- virtual void OnRemotingDirectoryError() {}
- };
-
- explicit RemotingDirectoryService(Client* client);
- ~RemotingDirectoryService();
-
- // Add this computer as host. Use the token for authentication.
- // TODO(hclam): Need more information for this method call.
- void AddHost(const std::string& token);
-
- // Cancel the last requested operation.
- void CancelRequest();
-
- // URLFetcher::Delegate implementation.
- virtual void OnURLFetchComplete(const URLFetcher* source,
- const GURL& url,
- const URLRequestStatus& status,
- int response_code,
- const ResponseCookies& cookies,
- const std::string& data);
-
- const std::string& host_id() const { return host_id_; }
- const std::string& host_name() const { return host_name_; }
- remoting::HostKeyPair* host_key_pair() const {
- return host_key_pair_.get();
- }
-
- private:
- Client* client_;
- scoped_ptr<URLFetcher> fetcher_;
-
- // Host key generated during host registration.
- scoped_ptr<remoting::HostKeyPair> host_key_pair_;
-
- // Host info used for registration.
- std::string host_id_;
- std::string host_name_;
-
- DISALLOW_COPY_AND_ASSIGN(RemotingDirectoryService);
-};
-
-#endif // CHROME_SERVICE_REMOTING_REMOTING_DIRECTORY_SERVICE_H_