summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/cros
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-17 05:10:30 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-17 05:10:30 +0000
commit83aa77e873d1dfde716c0083f6f5704999c93748 (patch)
tree0523199cb0032c5b48e2ca82aa243d1b65ce1fc9 /chrome/browser/chromeos/cros
parentaf3b0898b4adf7961c5af8c6e1ef4909672c8488 (diff)
downloadchromium_src-83aa77e873d1dfde716c0083f6f5704999c93748.zip
chromium_src-83aa77e873d1dfde716c0083f6f5704999c93748.tar.gz
chromium_src-83aa77e873d1dfde716c0083f6f5704999c93748.tar.bz2
Rework LibcrosService using our D-Bus library.
Also introduce DBusThreadManager, that manages the D-Bus thread, and D-Bus clients using the thread. cros_dbus_service.cc and proxy_resolution_service_provider.cc are based on libcros_service_library.cc. The basic logic is kept as before. The major changes are: - Get rid of all libcros function calls (ex. StartLibCrosService). - Export "ResolveProxy" D-Bus method from Chrome, instead of libcros. - CrosDBusService is now managed by DBusThreadManager, instead of CrosLibrary. - Reduce use of nested class per the C++ style guide. - Now unit tested: libcros_service_unittest.cc BUG=chromium-os:18904 TEST=on the device, change the proxy config to use http://proxyconfig.corp.google.com/wpad.dat, run /opt/google/chrome/chromeos/libcros_service_tester (installed by USE=install_tests gmerge libcros), and confirm the libcros service works as before. Review URL: http://codereview.chromium.org/7819012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101640 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/cros')
-rw-r--r--chrome/browser/chromeos/cros/cros_library.cc3
-rw-r--r--chrome/browser/chromeos/cros/cros_library.h4
-rw-r--r--chrome/browser/chromeos/cros/libcros_service_library.cc322
-rw-r--r--chrome/browser/chromeos/cros/libcros_service_library.h29
4 files changed, 0 insertions, 358 deletions
diff --git a/chrome/browser/chromeos/cros/cros_library.cc b/chrome/browser/chromeos/cros/cros_library.cc
index e3dc355..a3a748d 100644
--- a/chrome/browser/chromeos/cros/cros_library.cc
+++ b/chrome/browser/chromeos/cros/cros_library.cc
@@ -8,7 +8,6 @@
#include "chrome/browser/chromeos/cros/burn_library.h"
#include "chrome/browser/chromeos/cros/cert_library.h"
#include "chrome/browser/chromeos/cros/cryptohome_library.h"
-#include "chrome/browser/chromeos/cros/libcros_service_library.h"
#include "chrome/browser/chromeos/cros/library_loader.h"
#include "chrome/browser/chromeos/cros/login_library.h"
#include "chrome/browser/chromeos/cros/mount_library.h"
@@ -82,7 +81,6 @@ DEFINE_GET_LIBRARY_METHOD(Brightness, brightness);
DEFINE_GET_LIBRARY_METHOD(Burn, burn);
DEFINE_GET_LIBRARY_METHOD(Cert, cert);
DEFINE_GET_LIBRARY_METHOD(Cryptohome, crypto);
-DEFINE_GET_LIBRARY_METHOD(LibCrosService, libcros_service);
DEFINE_GET_LIBRARY_METHOD(Login, login);
DEFINE_GET_LIBRARY_METHOD(Mount, mount);
DEFINE_GET_LIBRARY_METHOD(Network, network);
@@ -132,7 +130,6 @@ DEFINE_SET_LIBRARY_METHOD(Brightness, brightness);
DEFINE_SET_LIBRARY_METHOD(Cert, cert);
DEFINE_SET_LIBRARY_METHOD(Burn, burn);
DEFINE_SET_LIBRARY_METHOD(Cryptohome, crypto);
-DEFINE_SET_LIBRARY_METHOD(LibCrosService, libcros_service);
DEFINE_SET_LIBRARY_METHOD(Login, login);
DEFINE_SET_LIBRARY_METHOD(Mount, mount);
DEFINE_SET_LIBRARY_METHOD(Network, network);
diff --git a/chrome/browser/chromeos/cros/cros_library.h b/chrome/browser/chromeos/cros/cros_library.h
index 5683e5e1..bc16426 100644
--- a/chrome/browser/chromeos/cros/cros_library.h
+++ b/chrome/browser/chromeos/cros/cros_library.h
@@ -20,7 +20,6 @@ class BrightnessLibrary;
class BurnLibrary;
class CertLibrary;
class CryptohomeLibrary;
-class LibCrosServiceLibrary;
class LibraryLoader;
class LoginLibrary;
class MountLibrary;
@@ -52,7 +51,6 @@ class CrosLibrary {
void SetCertLibrary(CertLibrary* library, bool own);
void SetBurnLibrary(BurnLibrary* library, bool own);
void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own);
- void SetLibCrosServiceLibrary(LibCrosServiceLibrary* library, bool own);
void SetLoginLibrary(LoginLibrary* library, bool own);
void SetMountLibrary(MountLibrary* library, bool own);
void SetNetworkLibrary(NetworkLibrary* library, bool own);
@@ -82,7 +80,6 @@ class CrosLibrary {
BurnLibrary* GetBurnLibrary();
CertLibrary* GetCertLibrary();
CryptohomeLibrary* GetCryptohomeLibrary();
- LibCrosServiceLibrary* GetLibCrosServiceLibrary();
LoginLibrary* GetLoginLibrary();
MountLibrary* GetMountLibrary();
NetworkLibrary* GetNetworkLibrary();
@@ -157,7 +154,6 @@ class CrosLibrary {
Library<BurnLibrary> burn_lib_;
Library<CertLibrary> cert_lib_;
Library<CryptohomeLibrary> crypto_lib_;
- Library<LibCrosServiceLibrary> libcros_service_lib_;
Library<LoginLibrary> login_lib_;
Library<MountLibrary> mount_lib_;
Library<NetworkLibrary> network_lib_;
diff --git a/chrome/browser/chromeos/cros/libcros_service_library.cc b/chrome/browser/chromeos/cros/libcros_service_library.cc
deleted file mode 100644
index cd4d578d..0000000
--- a/chrome/browser/chromeos/cros/libcros_service_library.cc
+++ /dev/null
@@ -1,322 +0,0 @@
-// Copyright (c) 2011 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 "chrome/browser/chromeos/cros/libcros_service_library.h"
-
-#include "base/synchronization/lock.h"
-#include "chrome/browser/chromeos/cros/cros_library.h"
-#include "chrome/browser/profiles/profile_manager.h"
-#include "content/browser/browser_thread.h"
-#include "cros/chromeos_libcros_service.h"
-#include "net/base/net_errors.h"
-#include "net/proxy/proxy_service.h"
-#include "net/url_request/url_request_context.h"
-#include "net/url_request/url_request_context_getter.h"
-
-namespace chromeos {
-
-class LibCrosServiceLibraryImpl : public LibCrosServiceLibrary {
- public:
- // Base class for all services of LibCrosService.
- // Each subclass should declare DISABLE_RUNNABLE_METHOD_REFCOUNT to disable
- // refcounting, which is okay since the subclass's object will exist as a
- // scoped_ptr in Singleton LibCrosServiceLibraryImpl, guaranteeing that its
- // lifetime is longer than that of any message loop.
- class ServicingLibrary {
- public:
- explicit ServicingLibrary(LibCrosServiceConnection service_connection);
- virtual ~ServicingLibrary();
-
- // Clears service_connection_ (which is stored as weak pointer) so that it
- // can't be used anymore.
- virtual void ClearServiceConnection();
-
- protected:
- LibCrosServiceConnection service_connection_; // Weak pointer.
- // Lock for data members to synchronize access on multiple threads.
- base::Lock data_lock_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ServicingLibrary);
- };
-
- // Library that provides network proxy service for LibCrosService.
- // For now, it only processes proxy resolution requests for ChromeOS clients.
- class NetworkProxyLibrary : public ServicingLibrary {
- public:
- explicit NetworkProxyLibrary(LibCrosServiceConnection connection);
- virtual ~NetworkProxyLibrary();
-
- private:
- // Data being used in one proxy resolution.
- class Request {
- public:
- explicit Request(const std::string& source_url);
- virtual ~Request() {}
-
- // Callback on IO thread for when net::ProxyService::ResolveProxy
- // completes, synchronously or asynchronously.
- void OnCompletion(int result);
- net::CompletionCallbackImpl<Request> completion_callback_;
-
- std::string source_url_; // URL being resolved.
- int result_; // Result of proxy resolution.
- net::ProxyInfo proxy_info_; // ProxyInfo resolved for source_url_.
- std::string error_; // Error from proxy resolution.
- Task* notify_task_; // Task to notify of resolution result.
-
- private:
- DISALLOW_COPY_AND_ASSIGN(Request);
- };
-
- // Static callback passed to LibCrosService to be invoked when ChromeOS
- // clients send network proxy resolution requests to the service running in
- // chrome executable. Called on UI thread from dbus request.
- static void ResolveProxyHandler(void* object, const char* source_url);
-
- void ResolveProxy(const std::string& source_url,
- scoped_refptr<net::URLRequestContextGetter> getter);
-
- // Wrapper on UI thread to call LibCrosService::NotifyNetworkProxyResolved.
- void NotifyProxyResolved(Request* request);
-
- std::vector<Request*> all_requests_;
-
- DISALLOW_COPY_AND_ASSIGN(NetworkProxyLibrary);
- };
-
- LibCrosServiceLibraryImpl();
- virtual ~LibCrosServiceLibraryImpl();
-
- // LibCrosServiceLibrary implementation.
-
- // Starts LibCrosService running on dbus if not already started.
- virtual void StartService();
-
- private:
- // Connection to LibCrosService.
- LibCrosServiceConnection service_connection_;
-
- // Libraries that form LibCrosService.
- scoped_ptr<NetworkProxyLibrary> network_proxy_lib_;
-
- DISALLOW_COPY_AND_ASSIGN(LibCrosServiceLibraryImpl);
-};
-
-//---------------- LibCrosServiceLibraryImpl: public ---------------------------
-
-LibCrosServiceLibraryImpl::LibCrosServiceLibraryImpl()
- : service_connection_(NULL) {
- if (!CrosLibrary::Get()->EnsureLoaded()) {
- LOG(ERROR) << "Cros library has not been loaded.";
- }
-}
-
-LibCrosServiceLibraryImpl::~LibCrosServiceLibraryImpl() {
- if (service_connection_) {
- // Clear service connections in servicing libraries which held the former
- // as weak pointers.
- if (network_proxy_lib_.get())
- network_proxy_lib_->ClearServiceConnection();
-
- StopLibCrosService(service_connection_);
- VLOG(1) << "LibCrosService stopped.";
- service_connection_ = NULL;
- }
-}
-
-// Called on UI thread to start service for LibCrosService.
-void LibCrosServiceLibraryImpl::StartService() {
- // Make sure we're running on UI thread.
- if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(this,
- &LibCrosServiceLibraryImpl::StartService));
- return;
- }
- if (service_connection_) // Service has already been started.
- return;
- // Starts LibCrosService; the returned connection is used for future
- // interactions with the service.
- service_connection_ = StartLibCrosService();
- if (!service_connection_) {
- LOG(WARNING) << "Error starting LibCrosService";
- return;
- }
- network_proxy_lib_.reset(new NetworkProxyLibrary(service_connection_));
- VLOG(1) << "LibCrosService started.";
-}
-
-//------------- LibCrosServiceLibraryImpl::ServicingLibrary: public ------------
-
-LibCrosServiceLibraryImpl::ServicingLibrary::ServicingLibrary(
- LibCrosServiceConnection connection)
- : service_connection_(connection) {
-}
-
-LibCrosServiceLibraryImpl::ServicingLibrary::~ServicingLibrary() {
- ClearServiceConnection();
-}
-
-void LibCrosServiceLibraryImpl::ServicingLibrary::ClearServiceConnection() {
- base::AutoLock lock(data_lock_);
- service_connection_ = NULL;
-}
-
-//----------- LibCrosServiceLibraryImpl::NetworkProxyLibrary: public -----------
-
-LibCrosServiceLibraryImpl::NetworkProxyLibrary::NetworkProxyLibrary(
- LibCrosServiceConnection connection)
- : ServicingLibrary(connection) {
- // Register callback for LibCrosService::ResolveNetworkProxy.
- SetNetworkProxyResolver(&ResolveProxyHandler, this, service_connection_);
-}
-
-LibCrosServiceLibraryImpl::NetworkProxyLibrary::~NetworkProxyLibrary() {
- base::AutoLock lock(data_lock_);
- while (!all_requests_.empty()) {
- LOG(WARNING) << "Pending request for " << all_requests_.back()->source_url_;
- delete all_requests_.back();
- all_requests_.pop_back();
- }
-}
-
-//----------- LibCrosServiceLibraryImpl::NetworkProxyLibrary: private ----------
-
-// Static, called on UI thread from LibCrosService::ResolveProxy via dbus.
-void LibCrosServiceLibraryImpl::NetworkProxyLibrary::ResolveProxyHandler(
- void* object, const char* source_url) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- NetworkProxyLibrary* lib = static_cast<NetworkProxyLibrary*>(object);
- // parameters of RunnbaleMethod will be freed when this function returns, so
- // make a copy of them.
- std::string url(source_url);
- scoped_refptr<net::URLRequestContextGetter> getter =
- ProfileManager::GetDefaultProfile()->GetRequestContext();
- BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(lib, &NetworkProxyLibrary::ResolveProxy, url, getter));
-}
-
-// Called on IO thread as task posted from ResolveProxyHandler on UI thread.
-void LibCrosServiceLibraryImpl::NetworkProxyLibrary::ResolveProxy(
- const std::string& source_url,
- scoped_refptr<net::URLRequestContextGetter> getter) {
- // Make sure we're running on IO thread.
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- // Create a request slot for this proxy resolution request.
- Request* request = new Request(source_url);
- request->notify_task_ = NewRunnableMethod(this,
- &NetworkProxyLibrary::NotifyProxyResolved, request);
- {
- base::AutoLock lock(data_lock_);
- // Queue request slot.
- all_requests_.push_back(request);
- if (!service_connection_) // Make sure |service_connection_| is valid.
- request->error_ = "LibCrosService not started";
- }
-
- // Retrieve ProxyService from profile's request context.
- net::ProxyService* proxy_service = NULL;
- if (request->error_.empty()) { // No error yet, proceed.
- if (getter)
- proxy_service = getter->GetURLRequestContext()->proxy_service();
- if (!proxy_service) // Make sure proxy_service is valid.
- request->error_ = "No proxy service in chrome";
- }
-
- if (!request->error_.empty()) { // Error string was just set.
- LOG(ERROR) << request->error_;
- request->result_ = net::OK; // Set to OK since error string is set.
- } else {
- VLOG(1) << "Starting networy proxy resolution for " << request->source_url_;
- request->result_ = proxy_service->ResolveProxy(
- GURL(request->source_url_), &request->proxy_info_,
- &request->completion_callback_, NULL, net::BoundNetLog());
- }
- if (request->result_ != net::ERR_IO_PENDING) {
- VLOG(1) << "Network proxy resolution completed synchronously.";
- request->OnCompletion(request->result_);
- }
-}
-
-// Called on UI thread as task posted from Request::OnCompletion on IO thread.
-void LibCrosServiceLibraryImpl::NetworkProxyLibrary::NotifyProxyResolved(
- Request* request) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- base::AutoLock lock(data_lock_);
- if (service_connection_) {
- if (!NotifyNetworkProxyResolved(request->source_url_.c_str(),
- request->proxy_info_.ToPacString().c_str(),
- request->error_.c_str(),
- service_connection_)) {
- LOG(ERROR) << "LibCrosService has error with NotifyNetworkProxyResolved";
- } else {
- VLOG(1) << "LibCrosService has notified proxy resoloution for "
- << request->source_url_;
- }
- }
- std::vector<Request*>::iterator iter =
- std::find(all_requests_.begin(), all_requests_.end(), request);
- if (iter == all_requests_.end()) {
- LOG(ERROR) << "can't find request slot(" << request->source_url_
- << ") in proxy-resolution queue";
- } else {
- all_requests_.erase(iter);
- }
- delete request;
-}
-
-//---------- LibCrosServiceLibraryImpl::NetworkProxyLibrary::Request -----------
-
-LibCrosServiceLibraryImpl::NetworkProxyLibrary::Request::Request(
- const std::string& source_url)
- : ALLOW_THIS_IN_INITIALIZER_LIST(
- completion_callback_(this, &Request::OnCompletion)),
- source_url_(source_url),
- result_(net::ERR_FAILED),
- notify_task_(NULL) {
-}
-
-// Called on IO thread when net::ProxyService::ResolveProxy has completed.
-void LibCrosServiceLibraryImpl::NetworkProxyLibrary::Request::OnCompletion(
- int result) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- result_ = result;
- if (result_ != net::OK)
- error_ = net::ErrorToString(result_);
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, notify_task_);
- notify_task_ = NULL;
-}
-
-//--------------------- LibCrosServiceLibraryStubImpl --------------------------
-
-class LibCrosServiceLibraryStubImpl : public LibCrosServiceLibrary {
- public:
- LibCrosServiceLibraryStubImpl() {}
- virtual ~LibCrosServiceLibraryStubImpl() {}
-
- // LibCrosServiceLibrary overrides.
- virtual void StartService() {}
-
- DISALLOW_COPY_AND_ASSIGN(LibCrosServiceLibraryStubImpl);
-};
-
-//--------------------------- LibCrosServiceLibrary ----------------------------
-
-// Static.
-LibCrosServiceLibrary* LibCrosServiceLibrary::GetImpl(bool stub) {
- if (stub)
- return new LibCrosServiceLibraryStubImpl();
- return new LibCrosServiceLibraryImpl();
-}
-
-} // namespace chromeos
-
-// Allows InvokeLater without adding refcounting. This class is a Singleton and
-// won't be deleted until it's last InvokeLater is run, so are all its
-// scoped_ptred class members.
-DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::LibCrosServiceLibraryImpl);
-DISABLE_RUNNABLE_METHOD_REFCOUNT(
- chromeos::LibCrosServiceLibraryImpl::NetworkProxyLibrary);
diff --git a/chrome/browser/chromeos/cros/libcros_service_library.h b/chrome/browser/chromeos/cros/libcros_service_library.h
deleted file mode 100644
index b409f29..0000000
--- a/chrome/browser/chromeos/cros/libcros_service_library.h
+++ /dev/null
@@ -1,29 +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_BROWSER_CHROMEOS_CROS_LIBCROS_SERVICE_LIBRARY_H_
-#define CHROME_BROWSER_CHROMEOS_CROS_LIBCROS_SERVICE_LIBRARY_H_
-#pragma once
-
-namespace net{
-class ProxyService;
-};
-
-namespace chromeos {
-
-class LibCrosServiceLibrary {
- public:
- virtual ~LibCrosServiceLibrary() {}
-
- // Starts dbus service for LibCrosService.
- virtual void StartService() = 0;
-
- // Factory function, creates a new instance and returns ownership.
- // For normal usage, access the singleton via CrosLibrary::Get().
- static LibCrosServiceLibrary* GetImpl(bool stub);
-};
-
-} // namespace chromeos
-
-#endif // CHROME_BROWSER_CHROMEOS_CROS_LIBCROS_SERVICE_LIBRARY_H_