forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a method for PAC script errors to the network delegate.
Also add a wrapper class to avoid passing around raw NULL pointers, and a bridge so I can invoke the method from other than the IO thread BUG=48930 TEST=net unittests Review URL: http://codereview.chromium.org/6822026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83881 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
jochen@chromium.org
committed
May 3, 2011
1 parent
ef1cef9
commit 82a3767
Showing
20 changed files
with
313 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// 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 "base/message_loop.h" | ||
#include "net/base/net_errors.h" | ||
#include "net/base/network_delegate.h" | ||
#include "net/proxy/network_delegate_error_observer.h" | ||
|
||
namespace net { | ||
|
||
// NetworkDelegateErrorObserver::Core ----------------------------------------- | ||
|
||
class NetworkDelegateErrorObserver::Core | ||
: public base::RefCountedThreadSafe<NetworkDelegateErrorObserver::Core> { | ||
public: | ||
Core(NetworkDelegate* network_delegate, MessageLoop* io_loop); | ||
|
||
void NotifyPACScriptError(int line_number, const string16& error); | ||
|
||
void Shutdown(); | ||
|
||
private: | ||
friend class base::RefCountedThreadSafe<NetworkDelegateErrorObserver::Core>; | ||
|
||
virtual ~Core(); | ||
|
||
NetworkDelegate* network_delegate_; | ||
MessageLoop* const io_loop_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(Core); | ||
}; | ||
|
||
NetworkDelegateErrorObserver::Core::Core(NetworkDelegate* network_delegate, | ||
MessageLoop* io_loop) | ||
: network_delegate_(network_delegate), | ||
io_loop_(io_loop) { | ||
DCHECK(io_loop_); | ||
} | ||
|
||
NetworkDelegateErrorObserver::Core::~Core() {} | ||
|
||
|
||
void NetworkDelegateErrorObserver::Core::NotifyPACScriptError( | ||
int line_number, | ||
const string16& error) { | ||
if (MessageLoop::current() != io_loop_) { | ||
io_loop_->PostTask( | ||
FROM_HERE, | ||
NewRunnableMethod(this, &Core::NotifyPACScriptError, | ||
line_number, error)); | ||
return; | ||
} | ||
if (network_delegate_) | ||
network_delegate_->NotifyPACScriptError(line_number, error); | ||
} | ||
|
||
void NetworkDelegateErrorObserver::Core::Shutdown() { | ||
CHECK_EQ(MessageLoop::current(), io_loop_); | ||
network_delegate_ = NULL; | ||
} | ||
|
||
// NetworkDelegateErrorObserver ----------------------------------------------- | ||
|
||
NetworkDelegateErrorObserver::NetworkDelegateErrorObserver( | ||
NetworkDelegate* network_delegate, | ||
MessageLoop* io_loop) | ||
: core_(new Core(network_delegate, io_loop)) {} | ||
|
||
NetworkDelegateErrorObserver::~NetworkDelegateErrorObserver() { | ||
core_->Shutdown(); | ||
} | ||
|
||
void NetworkDelegateErrorObserver::OnPACScriptError(int line_number, | ||
const string16& error) { | ||
core_->NotifyPACScriptError(line_number, error); | ||
} | ||
|
||
} // namespace net |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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. | ||
|
||
#ifndef NET_PROXY_NETWORK_DELEGATE_ERROR_OBSERVER_H_ | ||
#define NET_PROXY_NETWORK_DELEGATE_ERROR_OBSERVER_H_ | ||
#pragma once | ||
|
||
#include "base/memory/ref_counted.h" | ||
#include "net/proxy/proxy_resolver_error_observer.h" | ||
|
||
class MessageLoop; | ||
|
||
namespace net { | ||
|
||
class NetworkDelegate; | ||
|
||
// An implementation of ProxyResolverErrorObserver that forwards PAC script | ||
// errors to a NetworkDelegate object on the IO thread. | ||
class NetworkDelegateErrorObserver : public ProxyResolverErrorObserver { | ||
public: | ||
NetworkDelegateErrorObserver(NetworkDelegate* network_delegate, | ||
MessageLoop* io_loop); | ||
virtual ~NetworkDelegateErrorObserver(); | ||
|
||
// ProxyResolverErrorObserver implementation. | ||
virtual void OnPACScriptError(int line_number, const string16& error); | ||
|
||
private: | ||
class Core; | ||
|
||
scoped_refptr<Core> core_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(NetworkDelegateErrorObserver); | ||
}; | ||
|
||
} // namespace net | ||
|
||
#endif // NET_PROXY_NETWORK_DELEGATE_ERROR_OBSERVER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// 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 "net/proxy/network_delegate_error_observer.h" | ||
|
||
#include "base/threading/thread.h" | ||
#include "net/base/net_errors.h" | ||
#include "net/base/network_delegate.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
DISABLE_RUNNABLE_METHOD_REFCOUNT(net::NetworkDelegateErrorObserver); | ||
|
||
namespace net { | ||
|
||
namespace { | ||
class TestNetworkDelegate : public net::NetworkDelegate { | ||
public: | ||
TestNetworkDelegate() : got_pac_error_(false) {} | ||
virtual ~TestNetworkDelegate() {} | ||
|
||
bool got_pac_error() const { return got_pac_error_; } | ||
|
||
private: | ||
// net::NetworkDelegate: | ||
virtual int OnBeforeURLRequest(URLRequest* request, | ||
CompletionCallback* callback, | ||
GURL* new_url) { | ||
return net::OK; | ||
} | ||
virtual int OnBeforeSendHeaders(uint64 request_id, | ||
CompletionCallback* callback, | ||
HttpRequestHeaders* headers) { | ||
return net::OK; | ||
} | ||
virtual void OnRequestSent(uint64 request_id, | ||
const HostPortPair& socket_address) {} | ||
virtual void OnBeforeRedirect(URLRequest* request, | ||
const GURL& new_location) {} | ||
virtual void OnResponseStarted(URLRequest* request) {} | ||
virtual void OnCompleted(URLRequest* request) {} | ||
virtual void OnURLRequestDestroyed(URLRequest* request) {} | ||
virtual void OnHttpTransactionDestroyed(uint64 request_id) {} | ||
virtual URLRequestJob* OnMaybeCreateURLRequestJob(URLRequest* request) { | ||
return NULL; | ||
} | ||
virtual void OnPACScriptError(int line_number, const string16& error) { | ||
got_pac_error_ = true; | ||
} | ||
|
||
bool got_pac_error_; | ||
}; | ||
|
||
} // namespace | ||
|
||
// Check that the OnPACScriptError method can be called from an arbitrary | ||
// thread. | ||
TEST(NetworkDelegateErrorObserverTest, CallOnThread) { | ||
base::Thread thread("test_thread"); | ||
thread.Start(); | ||
TestNetworkDelegate network_delegate; | ||
NetworkDelegateErrorObserver | ||
observer(&network_delegate, MessageLoop::current()); | ||
thread.message_loop()->PostTask(FROM_HERE, | ||
NewRunnableMethod(&observer, | ||
&NetworkDelegateErrorObserver::OnPACScriptError, | ||
42, string16())); | ||
thread.Stop(); | ||
MessageLoop::current()->RunAllPending(); | ||
ASSERT_TRUE(network_delegate.got_pac_error()); | ||
} | ||
|
||
// Check that passing a NULL network delegate works. | ||
TEST(NetworkDelegateErrorObserverTest, NoDelegate) { | ||
base::Thread thread("test_thread"); | ||
thread.Start(); | ||
NetworkDelegateErrorObserver observer(NULL, MessageLoop::current()); | ||
thread.message_loop()->PostTask(FROM_HERE, | ||
NewRunnableMethod(&observer, | ||
&NetworkDelegateErrorObserver::OnPACScriptError, | ||
42, string16())); | ||
thread.Stop(); | ||
MessageLoop::current()->RunAllPending(); | ||
// Shouldn't have crashed until here... | ||
} | ||
|
||
} // namespace net |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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. | ||
|
||
#ifndef NET_PROXY_PROXY_RESOLVER_ERROR_OBSERVER_H_ | ||
#define NET_PROXY_PROXY_RESOLVER_ERROR_OBSERVER_H_ | ||
#pragma once | ||
|
||
#include "base/string16.h" | ||
|
||
namespace net { | ||
|
||
// Interface for observing JavaScript error messages from PAC scripts. | ||
class ProxyResolverErrorObserver { | ||
public: | ||
ProxyResolverErrorObserver() {} | ||
virtual ~ProxyResolverErrorObserver() {} | ||
|
||
virtual void OnPACScriptError(int line_number, const string16& error) = 0; | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(ProxyResolverErrorObserver); | ||
}; | ||
|
||
} // namespace net | ||
|
||
#endif // NET_PROXY_PROXY_RESOLVER_ERROR_OBSERVER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.