diff options
23 files changed, 364 insertions, 253 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index f045f1f..03e4b31 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -5297,15 +5297,14 @@ class CapturingProxyResolver : public ProxyResolver { NOTREACHED(); } - const std::vector<GURL>& resolved() const { return resolved_; } - - private: - virtual int SetPacScript(const GURL& /*pac_url*/, - const string16& /*pac_script*/, + virtual int SetPacScript(const scoped_refptr<ProxyResolverScriptData>&, CompletionCallback* /*callback*/) { return OK; } + const std::vector<GURL>& resolved() const { return resolved_; } + + private: std::vector<GURL> resolved_; DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); diff --git a/net/net.gyp b/net/net.gyp index 61c0973..93338f5 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -434,6 +434,8 @@ 'proxy/proxy_resolver_mac.h', 'proxy/proxy_resolver_request_context.h', 'proxy/proxy_resolver_script.h', + 'proxy/proxy_resolver_script_data.cc', + 'proxy/proxy_resolver_script_data.h', 'proxy/proxy_resolver_v8.cc', 'proxy/proxy_resolver_v8.h', 'proxy/proxy_resolver_winhttp.cc', diff --git a/net/proxy/init_proxy_resolver.cc b/net/proxy/init_proxy_resolver.cc index 3817468..04f828b 100644 --- a/net/proxy/init_proxy_resolver.cc +++ b/net/proxy/init_proxy_resolver.cc @@ -63,13 +63,10 @@ int InitProxyResolver::Init(const ProxyConfig& config, InitProxyResolver::UrlList InitProxyResolver::BuildPacUrlsFallbackList( const ProxyConfig& config) const { UrlList pac_urls; - if (config.auto_detect()) { - GURL pac_url = resolver_->expects_pac_bytes() ? - GURL("http://wpad/wpad.dat") : GURL(); - pac_urls.push_back(pac_url); - } + if (config.auto_detect()) + pac_urls.push_back(PacURL(true, GURL())); if (config.has_pac_url()) - pac_urls.push_back(config.pac_url()); + pac_urls.push_back(PacURL(false, config.pac_url())); return pac_urls; } @@ -123,18 +120,24 @@ int InitProxyResolver::DoFetchPacScript() { next_state_ = STATE_FETCH_PAC_SCRIPT_COMPLETE; - const GURL& pac_url = current_pac_url(); + const PacURL& pac_url = current_pac_url(); + + const GURL effective_pac_url = + pac_url.auto_detect ? GURL("http://wpad/wpad.dat") : pac_url.url; net_log_.BeginEvent( NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT, - new NetLogStringParameter("url", pac_url.spec())); + new NetLogStringParameter("url", + effective_pac_url.possibly_invalid_spec())); if (!proxy_script_fetcher_) { net_log_.AddEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_HAS_NO_FETCHER, NULL); return ERR_UNEXPECTED; } - return proxy_script_fetcher_->Fetch(pac_url, &pac_script_, &io_callback_); + return proxy_script_fetcher_->Fetch(effective_pac_url, + &pac_script_, + &io_callback_); } int InitProxyResolver::DoFetchPacScriptComplete(int result) { @@ -156,13 +159,21 @@ int InitProxyResolver::DoFetchPacScriptComplete(int result) { int InitProxyResolver::DoSetPacScript() { net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT, NULL); - const GURL& pac_url = current_pac_url(); + const PacURL& pac_url = current_pac_url(); next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; - return resolver_->expects_pac_bytes() ? - resolver_->SetPacScriptByData(pac_script_, &io_callback_) : - resolver_->SetPacScriptByUrl(pac_url, &io_callback_); + scoped_refptr<ProxyResolverScriptData> script_data; + + if (resolver_->expects_pac_bytes()) { + script_data = ProxyResolverScriptData::FromUTF16(pac_script_); + } else { + script_data = pac_url.auto_detect ? + ProxyResolverScriptData::ForAutoDetect() : + ProxyResolverScriptData::FromURL(pac_url.url); + } + + return resolver_->SetPacScript(script_data, &io_callback_); } int InitProxyResolver::DoSetPacScriptComplete(int result) { @@ -201,7 +212,7 @@ InitProxyResolver::State InitProxyResolver::GetStartState() const { STATE_FETCH_PAC_SCRIPT : STATE_SET_PAC_SCRIPT; } -const GURL& InitProxyResolver::current_pac_url() const { +const InitProxyResolver::PacURL& InitProxyResolver::current_pac_url() const { DCHECK_LT(current_pac_url_index_, pac_urls_.size()); return pac_urls_[current_pac_url_index_]; } diff --git a/net/proxy/init_proxy_resolver.h b/net/proxy/init_proxy_resolver.h index ab1301a..814e932 100644 --- a/net/proxy/init_proxy_resolver.h +++ b/net/proxy/init_proxy_resolver.h @@ -57,7 +57,15 @@ class InitProxyResolver { STATE_SET_PAC_SCRIPT, STATE_SET_PAC_SCRIPT_COMPLETE, }; - typedef std::vector<GURL> UrlList; + + struct PacURL { + PacURL(bool auto_detect, const GURL& url) + : auto_detect(auto_detect), url(url) {} + bool auto_detect; + GURL url; + }; + + typedef std::vector<PacURL> UrlList; // Returns ordered list of PAC urls to try for |config|. UrlList BuildPacUrlsFallbackList(const ProxyConfig& config) const; @@ -83,7 +91,7 @@ class InitProxyResolver { State GetStartState() const; // Returns the current PAC URL we are fetching/testing. - const GURL& current_pac_url() const; + const PacURL& current_pac_url() const; void DidCompleteInit(); void Cancel(); diff --git a/net/proxy/init_proxy_resolver_unittest.cc b/net/proxy/init_proxy_resolver_unittest.cc index 681e12d..458cc53 100644 --- a/net/proxy/init_proxy_resolver_unittest.cc +++ b/net/proxy/init_proxy_resolver_unittest.cc @@ -130,35 +130,37 @@ class RuleBasedProxyResolver : public ProxyResolver { NOTREACHED(); } - virtual int SetPacScript(const GURL& pac_url, - const string16& pac_script, - CompletionCallback* callback) { + virtual int SetPacScript( + const scoped_refptr<ProxyResolverScriptData>& script_data, + CompletionCallback* callback) { + + const GURL url = + script_data->type() == ProxyResolverScriptData::TYPE_SCRIPT_URL ? + script_data->url() : GURL(); + const Rules::Rule& rule = expects_pac_bytes() ? - rules_->GetRuleByText(pac_script) : - rules_->GetRuleByUrl(pac_url); + rules_->GetRuleByText(script_data->utf16()) : + rules_->GetRuleByUrl(url); int rv = rule.set_pac_error; EXPECT_NE(ERR_UNEXPECTED, rv); - if (expects_pac_bytes()) - EXPECT_EQ(rule.text(), pac_script); - else - EXPECT_EQ(rule.url, pac_url); - - if (rv == OK) { - pac_script_ = pac_script; - pac_url_ = pac_url; + if (expects_pac_bytes()) { + EXPECT_EQ(rule.text(), script_data->utf16()); + } else { + EXPECT_EQ(rule.url, url); } + + if (rv == OK) + script_data_ = script_data; return rv; } - const string16& pac_script() const { return pac_script_; } - const GURL& pac_url() const { return pac_url_; } + const ProxyResolverScriptData* script_data() const { return script_data_; } private: const Rules* rules_; - string16 pac_script_; - GURL pac_url_; + scoped_refptr<ProxyResolverScriptData> script_data_; }; // Succeed using custom PAC script. @@ -176,7 +178,7 @@ TEST(InitProxyResolverTest, CustomPacSucceeds) { CapturingNetLog log(CapturingNetLog::kUnbounded); InitProxyResolver init(&resolver, &fetcher, &log); EXPECT_EQ(OK, init.Init(config, &callback)); - EXPECT_EQ(rule.text(), resolver.pac_script()); + EXPECT_EQ(rule.text(), resolver.script_data()->utf16()); // Check the NetLog was filled correctly. EXPECT_EQ(6u, log.entries().size()); @@ -209,7 +211,7 @@ TEST(InitProxyResolverTest, CustomPacFails1) { CapturingNetLog log(CapturingNetLog::kUnbounded); InitProxyResolver init(&resolver, &fetcher, &log); EXPECT_EQ(kFailedDownloading, init.Init(config, &callback)); - EXPECT_EQ(string16(), resolver.pac_script()); + EXPECT_EQ(NULL, resolver.script_data()); // Check the NetLog was filled correctly. EXPECT_EQ(4u, log.entries().size()); @@ -237,7 +239,7 @@ TEST(InitProxyResolverTest, CustomPacFails2) { TestCompletionCallback callback; InitProxyResolver init(&resolver, &fetcher, NULL); EXPECT_EQ(kFailedParsing, init.Init(config, &callback)); - EXPECT_EQ(string16(), resolver.pac_script()); + EXPECT_EQ(NULL, resolver.script_data()); } // Fail downloading the custom PAC script, because the fetcher was NULL. @@ -251,7 +253,7 @@ TEST(InitProxyResolverTest, HasNullProxyScriptFetcher) { TestCompletionCallback callback; InitProxyResolver init(&resolver, NULL, NULL); EXPECT_EQ(ERR_UNEXPECTED, init.Init(config, &callback)); - EXPECT_EQ(string16(), resolver.pac_script()); + EXPECT_EQ(NULL, resolver.script_data()); } // Succeeds in choosing autodetect (wpad). @@ -268,7 +270,7 @@ TEST(InitProxyResolverTest, AutodetectSuccess) { TestCompletionCallback callback; InitProxyResolver init(&resolver, &fetcher, NULL); EXPECT_EQ(OK, init.Init(config, &callback)); - EXPECT_EQ(rule.text(), resolver.pac_script()); + EXPECT_EQ(rule.text(), resolver.script_data()->utf16()); } // Fails at WPAD (downloading), but succeeds in choosing the custom PAC. @@ -287,7 +289,7 @@ TEST(InitProxyResolverTest, AutodetectFailCustomSuccess1) { TestCompletionCallback callback; InitProxyResolver init(&resolver, &fetcher, NULL); EXPECT_EQ(OK, init.Init(config, &callback)); - EXPECT_EQ(rule.text(), resolver.pac_script()); + EXPECT_EQ(rule.text(), resolver.script_data()->utf16()); } // Fails at WPAD (parsing), but succeeds in choosing the custom PAC. @@ -307,7 +309,7 @@ TEST(InitProxyResolverTest, AutodetectFailCustomSuccess2) { CapturingNetLog log(CapturingNetLog::kUnbounded); InitProxyResolver init(&resolver, &fetcher, &log); EXPECT_EQ(OK, init.Init(config, &callback)); - EXPECT_EQ(rule.text(), resolver.pac_script()); + EXPECT_EQ(rule.text(), resolver.script_data()->utf16()); // Check the NetLog was filled correctly. // (Note that the Fetch and Set states are repeated since both WPAD and custom @@ -355,7 +357,7 @@ TEST(InitProxyResolverTest, AutodetectFailCustomFails1) { TestCompletionCallback callback; InitProxyResolver init(&resolver, &fetcher, NULL); EXPECT_EQ(kFailedDownloading, init.Init(config, &callback)); - EXPECT_EQ(string16(), resolver.pac_script()); + EXPECT_EQ(NULL, resolver.script_data()); } // Fails at WPAD (downloading), and fails at custom PAC (parsing). @@ -374,7 +376,7 @@ TEST(InitProxyResolverTest, AutodetectFailCustomFails2) { TestCompletionCallback callback; InitProxyResolver init(&resolver, &fetcher, NULL); EXPECT_EQ(kFailedParsing, init.Init(config, &callback)); - EXPECT_EQ(string16(), resolver.pac_script()); + EXPECT_EQ(NULL, resolver.script_data()); } // Fails at WPAD (parsing), but succeeds in choosing the custom PAC. @@ -395,7 +397,7 @@ TEST(InitProxyResolverTest, AutodetectFailCustomSuccess2_NoFetch) { TestCompletionCallback callback; InitProxyResolver init(&resolver, &fetcher, NULL); EXPECT_EQ(OK, init.Init(config, &callback)); - EXPECT_EQ(rule.url, resolver.pac_url()); + EXPECT_EQ(rule.url, resolver.script_data()->url()); } } // namespace diff --git a/net/proxy/mock_proxy_resolver.h b/net/proxy/mock_proxy_resolver.h index 5087d6c..9babb66 100644 --- a/net/proxy/mock_proxy_resolver.h +++ b/net/proxy/mock_proxy_resolver.h @@ -59,19 +59,17 @@ class MockAsyncProxyResolverBase : public ProxyResolver { class SetPacScriptRequest { public: - SetPacScriptRequest(MockAsyncProxyResolverBase* resolver, - const GURL& pac_url, - const string16& pac_script, - CompletionCallback* callback) + SetPacScriptRequest( + MockAsyncProxyResolverBase* resolver, + const scoped_refptr<ProxyResolverScriptData>& script_data, + CompletionCallback* callback) : resolver_(resolver), - pac_url_(pac_url), - pac_script_(pac_script), + script_data_(script_data), callback_(callback), origin_loop_(MessageLoop::current()) { } - const GURL& pac_url() const { return pac_url_; } - const string16& pac_script() const { return pac_script_; } + const ProxyResolverScriptData* script_data() const { return script_data_; } void CompleteNow(int rv) { CompletionCallback* callback = callback_; @@ -84,8 +82,7 @@ class MockAsyncProxyResolverBase : public ProxyResolver { private: MockAsyncProxyResolverBase* resolver_; - const GURL pac_url_; - const string16 pac_script_; + const scoped_refptr<ProxyResolverScriptData> script_data_; CompletionCallback* callback_; MessageLoop* origin_loop_; }; @@ -114,12 +111,12 @@ class MockAsyncProxyResolverBase : public ProxyResolver { RemovePendingRequest(request); } - virtual int SetPacScript(const GURL& pac_url, - const string16& pac_script, - CompletionCallback* callback) { + virtual int SetPacScript( + const scoped_refptr<ProxyResolverScriptData>& script_data, + CompletionCallback* callback) { DCHECK(!pending_set_pac_script_request_.get()); pending_set_pac_script_request_.reset( - new SetPacScriptRequest(this, pac_url, pac_script, callback)); + new SetPacScriptRequest(this, script_data, callback)); // Finished when user calls SetPacScriptRequest::CompleteNow(). return ERR_IO_PENDING; } diff --git a/net/proxy/multi_threaded_proxy_resolver.cc b/net/proxy/multi_threaded_proxy_resolver.cc index a55fef9..69e9ef7 100644 --- a/net/proxy/multi_threaded_proxy_resolver.cc +++ b/net/proxy/multi_threaded_proxy_resolver.cc @@ -178,21 +178,17 @@ class MultiThreadedProxyResolver::Job class MultiThreadedProxyResolver::SetPacScriptJob : public MultiThreadedProxyResolver::Job { public: - SetPacScriptJob(const GURL& pac_url, - const string16& pac_script, + SetPacScriptJob(const scoped_refptr<ProxyResolverScriptData>& script_data, CompletionCallback* callback) : Job(callback ? TYPE_SET_PAC_SCRIPT : TYPE_SET_PAC_SCRIPT_INTERNAL, callback), - pac_url_(pac_url), - pac_script_(pac_script) { + script_data_(script_data) { } // Runs on the worker thread. virtual void Run(MessageLoop* origin_loop) { ProxyResolver* resolver = executor()->resolver(); - int rv = resolver->expects_pac_bytes() ? - resolver->SetPacScriptByData(pac_script_, NULL) : - resolver->SetPacScriptByUrl(pac_url_, NULL); + int rv = resolver->SetPacScript(script_data_, NULL); DCHECK_NE(rv, ERR_IO_PENDING); origin_loop->PostTask( @@ -210,8 +206,7 @@ class MultiThreadedProxyResolver::SetPacScriptJob OnJobCompleted(); } - const GURL pac_url_; - const string16 pac_script_; + const scoped_refptr<ProxyResolverScriptData> script_data_; }; // MultiThreadedProxyResolver::GetProxyForURLJob ------------------------------ @@ -394,8 +389,7 @@ MultiThreadedProxyResolver::MultiThreadedProxyResolver( size_t max_num_threads) : ProxyResolver(resolver_factory->resolvers_expect_pac_bytes()), resolver_factory_(resolver_factory), - max_num_threads_(max_num_threads), - was_set_pac_script_called_(false) { + max_num_threads_(max_num_threads) { DCHECK_GE(max_num_threads, 1u); } @@ -412,7 +406,7 @@ int MultiThreadedProxyResolver::GetProxyForURL(const GURL& url, const BoundNetLog& net_log) { DCHECK(CalledOnValidThread()); DCHECK(callback); - DCHECK(was_set_pac_script_called_) + DCHECK(current_script_data_.get()) << "Resolver is un-initialized. Must call SetPacScript() first!"; scoped_refptr<GetProxyForURLJob> job = @@ -441,7 +435,7 @@ int MultiThreadedProxyResolver::GetProxyForURL(const GURL& url, if (executors_.size() < max_num_threads_) { executor = AddNewExecutor(); executor->StartJob( - new SetPacScriptJob(current_pac_url_, current_pac_script_, NULL)); + new SetPacScriptJob(current_script_data_, NULL)); } return ERR_IO_PENDING; @@ -476,9 +470,7 @@ void MultiThreadedProxyResolver::CancelSetPacScript() { // Defensively clear some data which shouldn't be getting used // anymore. - was_set_pac_script_called_ = false; - current_pac_url_ = GURL(); - current_pac_script_ = string16(); + current_script_data_ = NULL; ReleaseAllExecutors(); } @@ -493,18 +485,13 @@ void MultiThreadedProxyResolver::PurgeMemory() { } int MultiThreadedProxyResolver::SetPacScript( - const GURL& pac_url, - const string16& pac_script, + const scoped_refptr<ProxyResolverScriptData>& script_data, CompletionCallback* callback) { DCHECK(CalledOnValidThread()); DCHECK(callback); // Save the script details, so we can provision new executors later. - // (We rely on internal reference counting of strings to avoid this memory - // being duplicated by each of the resolver threads). - was_set_pac_script_called_ = true; - current_pac_url_ = pac_url; - current_pac_script_ = pac_script; + current_script_data_ = script_data; // The user should not have any outstanding requests when they call // SetPacScript(). @@ -516,7 +503,7 @@ int MultiThreadedProxyResolver::SetPacScript( // Provision a new executor, and run the SetPacScript request. On completion // notification will be sent through |callback|. Executor* executor = AddNewExecutor(); - executor->StartJob(new SetPacScriptJob(pac_url, pac_script, callback)); + executor->StartJob(new SetPacScriptJob(script_data, callback)); return ERR_IO_PENDING; } diff --git a/net/proxy/multi_threaded_proxy_resolver.h b/net/proxy/multi_threaded_proxy_resolver.h index f3c9003..a69699a 100644 --- a/net/proxy/multi_threaded_proxy_resolver.h +++ b/net/proxy/multi_threaded_proxy_resolver.h @@ -97,6 +97,9 @@ class MultiThreadedProxyResolver : public ProxyResolver, public NonThreadSafe { virtual void CancelRequest(RequestHandle request); virtual void CancelSetPacScript(); virtual void PurgeMemory(); + virtual int SetPacScript( + const scoped_refptr<ProxyResolverScriptData>& script_data, + CompletionCallback* callback); private: class Executor; @@ -108,11 +111,6 @@ class MultiThreadedProxyResolver : public ProxyResolver, public NonThreadSafe { typedef std::deque<scoped_refptr<Job> > PendingJobsQueue; typedef std::vector<scoped_refptr<Executor> > ExecutorList; - // ProxyResolver implementation: - virtual int SetPacScript(const GURL& pac_url, - const string16& pac_script, - CompletionCallback* callback); - // Asserts that there are no outstanding user-initiated jobs on any of the // worker threads. void CheckNoOutstandingUserRequests() const; @@ -134,9 +132,7 @@ class MultiThreadedProxyResolver : public ProxyResolver, public NonThreadSafe { const size_t max_num_threads_; PendingJobsQueue pending_jobs_; ExecutorList executors_; - bool was_set_pac_script_called_; - GURL current_pac_url_; - string16 current_pac_script_; + scoped_refptr<ProxyResolverScriptData> current_script_data_; }; } // namespace net diff --git a/net/proxy/multi_threaded_proxy_resolver_unittest.cc b/net/proxy/multi_threaded_proxy_resolver_unittest.cc index 5873775..1a76d21 100644 --- a/net/proxy/multi_threaded_proxy_resolver_unittest.cc +++ b/net/proxy/multi_threaded_proxy_resolver_unittest.cc @@ -58,11 +58,11 @@ class MockProxyResolver : public ProxyResolver { NOTREACHED(); } - virtual int SetPacScript(const GURL& pac_url, - const string16& text, - CompletionCallback* callback) { + virtual int SetPacScript( + const scoped_refptr<ProxyResolverScriptData>& script_data, + CompletionCallback* callback) { CheckIsOnWorkerThread(); - last_pac_script_ = text; + last_script_data_ = script_data; return OK; } @@ -74,7 +74,9 @@ class MockProxyResolver : public ProxyResolver { int purge_count() const { return purge_count_; } int request_count() const { return request_count_; } - const string16& last_pac_script() const { return last_pac_script_; } + const ProxyResolverScriptData* last_script_data() const { + return last_script_data_; + } void SetResolveLatency(int latency_ms) { resolve_latency_ms_ = latency_ms; @@ -92,7 +94,7 @@ class MockProxyResolver : public ProxyResolver { MessageLoop* wrong_loop_; int request_count_; int purge_count_; - string16 last_pac_script_; + scoped_refptr<ProxyResolverScriptData> last_script_data_; int resolve_latency_ms_; }; @@ -165,13 +167,10 @@ class ForwardingProxyResolver : public ProxyResolver { impl_->CancelRequest(request); } - virtual int SetPacScript(const GURL& pac_url, - const string16& script, - CompletionCallback* callback) { - if (impl_->expects_pac_bytes()) - return impl_->SetPacScriptByData(script, callback); - else - return impl_->SetPacScriptByUrl(pac_url, callback); + virtual int SetPacScript( + const scoped_refptr<ProxyResolverScriptData>& script_data, + CompletionCallback* callback) { + return impl_->SetPacScript(script_data, callback); } virtual void PurgeMemory() { @@ -234,11 +233,13 @@ TEST(MultiThreadedProxyResolverTest, SingleThread_Basic) { // Call SetPacScriptByData() -- verify that it reaches the synchronous // resolver. TestCompletionCallback set_script_callback; - rv = resolver.SetPacScriptByData(ASCIIToUTF16("pac script bytes"), - &set_script_callback); + rv = resolver.SetPacScript( + ProxyResolverScriptData::FromUTF8("pac script bytes"), + &set_script_callback); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(OK, set_script_callback.WaitForResult()); - EXPECT_EQ(ASCIIToUTF16("pac script bytes"), mock->last_pac_script()); + EXPECT_EQ(ASCIIToUTF16("pac script bytes"), + mock->last_script_data()->utf16()); // Start request 0. TestCompletionCallback callback0; @@ -304,7 +305,8 @@ TEST(MultiThreadedProxyResolverTest, SingleThread_Basic) { // we queue up a dummy request after the PurgeMemory() call and wait until it // finishes to ensure PurgeMemory() has had a chance to run. TestCompletionCallback dummy_callback; - rv = resolver.SetPacScriptByData(ASCIIToUTF16("dummy"), &dummy_callback); + rv = resolver.SetPacScript(ProxyResolverScriptData::FromUTF8("dummy"), + &dummy_callback); EXPECT_EQ(OK, dummy_callback.WaitForResult()); EXPECT_EQ(1, mock->purge_count()); } @@ -322,7 +324,8 @@ TEST(MultiThreadedProxyResolverTest, // Initialize the resolver. TestCompletionCallback init_callback; - rv = resolver.SetPacScriptByData(ASCIIToUTF16("foo"), &init_callback); + rv = resolver.SetPacScript(ProxyResolverScriptData::FromUTF8("foo"), + &init_callback); EXPECT_EQ(OK, init_callback.WaitForResult()); // Block the proxy resolver, so no request can complete. @@ -403,7 +406,8 @@ TEST(MultiThreadedProxyResolverTest, SingleThread_CancelRequest) { // Initialize the resolver. TestCompletionCallback init_callback; - rv = resolver.SetPacScriptByData(ASCIIToUTF16("foo"), &init_callback); + rv = resolver.SetPacScript(ProxyResolverScriptData::FromUTF8("foo"), + &init_callback); EXPECT_EQ(OK, init_callback.WaitForResult()); // Block the proxy resolver, so no request can complete. @@ -479,7 +483,8 @@ TEST(MultiThreadedProxyResolverTest, SingleThread_CancelRequestByDeleting) { // Initialize the resolver. TestCompletionCallback init_callback; - rv = resolver->SetPacScriptByData(ASCIIToUTF16("foo"), &init_callback); + rv = resolver->SetPacScript(ProxyResolverScriptData::FromUTF8("foo"), + &init_callback); EXPECT_EQ(OK, init_callback.WaitForResult()); // Block the proxy resolver, so no request can complete. @@ -539,8 +544,8 @@ TEST(MultiThreadedProxyResolverTest, SingleThread_CancelSetPacScript) { int rv; TestCompletionCallback set_pac_script_callback; - rv = resolver.SetPacScriptByData(ASCIIToUTF16("data"), - &set_pac_script_callback); + rv = resolver.SetPacScript(ProxyResolverScriptData::FromUTF8("data"), + &set_pac_script_callback); EXPECT_EQ(ERR_IO_PENDING, rv); // Cancel the SetPacScriptByData request. @@ -548,15 +553,15 @@ TEST(MultiThreadedProxyResolverTest, SingleThread_CancelSetPacScript) { // Start another SetPacScript request TestCompletionCallback set_pac_script_callback2; - rv = resolver.SetPacScriptByData(ASCIIToUTF16("data2"), - &set_pac_script_callback2); + rv = resolver.SetPacScript(ProxyResolverScriptData::FromUTF8("data2"), + &set_pac_script_callback2); EXPECT_EQ(ERR_IO_PENDING, rv); // Wait for the initialization to complete. rv = set_pac_script_callback2.WaitForResult(); EXPECT_EQ(0, rv); - EXPECT_EQ(ASCIIToUTF16("data2"), mock->last_pac_script()); + EXPECT_EQ(ASCIIToUTF16("data2"), mock->last_script_data()->utf16()); // The first SetPacScript callback should never have been completed. EXPECT_FALSE(set_pac_script_callback.have_result()); @@ -576,14 +581,15 @@ TEST(MultiThreadedProxyResolverTest, ThreeThreads_Basic) { // Call SetPacScriptByData() -- verify that it reaches the synchronous // resolver. TestCompletionCallback set_script_callback; - rv = resolver.SetPacScriptByData(ASCIIToUTF16("pac script bytes"), - &set_script_callback); + rv = resolver.SetPacScript( + ProxyResolverScriptData::FromUTF8("pac script bytes"), + &set_script_callback); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(OK, set_script_callback.WaitForResult()); // One thread has been provisioned (i.e. one ProxyResolver was created). ASSERT_EQ(1u, factory->resolvers().size()); EXPECT_EQ(ASCIIToUTF16("pac script bytes"), - factory->resolvers()[0]->last_pac_script()); + factory->resolvers()[0]->last_script_data()->utf16()); const int kNumRequests = 9; TestCompletionCallback callback[kNumRequests]; @@ -644,18 +650,20 @@ TEST(MultiThreadedProxyResolverTest, ThreeThreads_Basic) { // (That way we can test to see the values observed by the synchronous // resolvers in a non-racy manner). TestCompletionCallback set_script_callback2; - rv = resolver.SetPacScriptByData(ASCIIToUTF16("xyz"), &set_script_callback2); + rv = resolver.SetPacScript(ProxyResolverScriptData::FromUTF8("xyz"), + &set_script_callback2); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(OK, set_script_callback2.WaitForResult()); ASSERT_EQ(4u, factory->resolvers().size()); for (int i = 0; i < 3; ++i) { - EXPECT_EQ(ASCIIToUTF16("pac script bytes"), - factory->resolvers()[i]->last_pac_script()) << "i=" << i; + EXPECT_EQ( + ASCIIToUTF16("pac script bytes"), + factory->resolvers()[i]->last_script_data()->utf16()) << "i=" << i; } EXPECT_EQ(ASCIIToUTF16("xyz"), - factory->resolvers()[3]->last_pac_script()); + factory->resolvers()[3]->last_script_data()->utf16()); // We don't know the exact ordering that requests ran on threads with, // but we do know the total count that should have reached the threads. @@ -685,14 +693,15 @@ TEST(MultiThreadedProxyResolverTest, OneThreadBlocked) { // Initialize the resolver. TestCompletionCallback set_script_callback; - rv = resolver.SetPacScriptByData(ASCIIToUTF16("pac script bytes"), - &set_script_callback); + rv = resolver.SetPacScript( + ProxyResolverScriptData::FromUTF8("pac script bytes"), + &set_script_callback); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(OK, set_script_callback.WaitForResult()); // One thread has been provisioned (i.e. one ProxyResolver was created). ASSERT_EQ(1u, factory->resolvers().size()); EXPECT_EQ(ASCIIToUTF16("pac script bytes"), - factory->resolvers()[0]->last_pac_script()); + factory->resolvers()[0]->last_script_data()->utf16()); const int kNumRequests = 4; TestCompletionCallback callback[kNumRequests]; diff --git a/net/proxy/proxy_resolver.h b/net/proxy/proxy_resolver.h index 37b1a3a..003fa84 100644 --- a/net/proxy/proxy_resolver.h +++ b/net/proxy/proxy_resolver.h @@ -6,9 +6,11 @@ #define NET_PROXY_PROXY_RESOLVER_H_ #include "base/logging.h" +#include "base/ref_counted.h" #include "base/string16.h" #include "googleurl/src/gurl.h" #include "net/base/completion_callback.h" +#include "net/proxy/proxy_resolver_script_data.h" namespace net { @@ -47,23 +49,10 @@ class ProxyResolver { // The PAC script backend can be specified to the ProxyResolver either via // URL, or via the javascript text itself. If |expects_pac_bytes| is true, - // then PAC scripts should be specified using SetPacScriptByData(). Otherwise - // they should be specified using SetPacScriptByUrl(). + // then the ProxyResolverScriptData passed to SetPacScript() should + // contain the actual script bytes rather than just the URL. bool expects_pac_bytes() const { return expects_pac_bytes_; } - // Sets the PAC script backend to use for this proxy resolver (by URL). - int SetPacScriptByUrl(const GURL& url, CompletionCallback* callback) { - DCHECK(!expects_pac_bytes()); - return SetPacScript(url, string16(), callback); - } - - // Sets the PAC script backend to use for this proxy resolver (by contents). - int SetPacScriptByData(const string16& script, - CompletionCallback* callback) { - DCHECK(expects_pac_bytes()); - return SetPacScript(GURL(), script, callback); - } - // TODO(eroman): Make this =0. virtual void CancelSetPacScript() { NOTREACHED(); @@ -74,20 +63,18 @@ class ProxyResolver { // no-op implementation. virtual void PurgeMemory() {} + // Called to set the PAC script backend to use. + // Returns ERR_IO_PENDING in the case of asynchronous completion, and notifies + // the result through |callback|. + virtual int SetPacScript( + const scoped_refptr<ProxyResolverScriptData>& pac_script, + CompletionCallback* callback) = 0; + // Optional shutdown code to be run before destruction. This is only used // by the multithreaded runner to signal cleanup from origin thread virtual void Shutdown() {} private: - // Called to set the PAC script backend to use. If |pac_url| is invalid, - // this is a request to use WPAD (auto detect). |pac_script| may be empty if - // the fetch failed, or if the fetch returned no content. - // Returns ERR_IO_PENDING in the case of asynchronous completion, and notifies - // the result through |callback|. - virtual int SetPacScript(const GURL& pac_url, - const string16& pac_script, - CompletionCallback* callback) = 0; - const bool expects_pac_bytes_; DISALLOW_COPY_AND_ASSIGN(ProxyResolver); diff --git a/net/proxy/proxy_resolver_mac.cc b/net/proxy/proxy_resolver_mac.cc index b052d3d..8e8ef20 100644 --- a/net/proxy/proxy_resolver_mac.cc +++ b/net/proxy/proxy_resolver_mac.cc @@ -69,7 +69,9 @@ int ProxyResolverMac::GetProxyForURL(const GURL& query_url, if (!query_url_ref.get()) return ERR_FAILED; scoped_cftyperef<CFStringRef> pac_ref( - base::SysUTF8ToCFStringRef(pac_url_.spec())); + base::SysUTF8ToCFStringRef( + script_data_->type() == ProxyResolverScriptData::TYPE_AUTO_DETECT ? + std::string() : script_data_->url().spec())); scoped_cftyperef<CFURLRef> pac_url_ref( CFURLCreateWithString(kCFAllocatorDefault, pac_ref.get(), diff --git a/net/proxy/proxy_resolver_mac.h b/net/proxy/proxy_resolver_mac.h index 29fb96a..cacf6c8 100644 --- a/net/proxy/proxy_resolver_mac.h +++ b/net/proxy/proxy_resolver_mac.h @@ -30,15 +30,15 @@ class ProxyResolverMac : public ProxyResolver { NOTREACHED(); } - private: - virtual int SetPacScript(const GURL& pac_url, - const string16& /*pac_script*/, - CompletionCallback* /*callback*/) { - pac_url_ = pac_url; + virtual int SetPacScript( + const scoped_refptr<ProxyResolverScriptData>& script_data, + CompletionCallback* /*callback*/) { + script_data_ = script_data_; return OK; } - GURL pac_url_; + private: + scoped_refptr<ProxyResolverScriptData> script_data_; }; } // namespace net diff --git a/net/proxy/proxy_resolver_perftest.cc b/net/proxy/proxy_resolver_perftest.cc index 3dd1f59..0c57955 100644 --- a/net/proxy/proxy_resolver_perftest.cc +++ b/net/proxy/proxy_resolver_perftest.cc @@ -98,7 +98,8 @@ class PacPerfSuiteRunner { InitHttpServer(); GURL pac_url = server_->TestServerPage(std::string("files/") + script_name); - int rv = resolver_->SetPacScriptByUrl(pac_url, NULL); + int rv = resolver_->SetPacScript( + net::ProxyResolverScriptData::FromURL(pac_url), NULL); EXPECT_EQ(net::OK, rv); } else { LoadPacScriptIntoResolver(script_name); @@ -167,7 +168,8 @@ class PacPerfSuiteRunner { ASSERT_TRUE(ok); // Load the PAC script into the ProxyResolver. - int rv = resolver_->SetPacScriptByData(ASCIIToUTF16(file_contents), NULL); + int rv = resolver_->SetPacScript( + net::ProxyResolverScriptData::FromUTF8(file_contents), NULL); EXPECT_EQ(net::OK, rv); } diff --git a/net/proxy/proxy_resolver_script_data.cc b/net/proxy/proxy_resolver_script_data.cc new file mode 100644 index 0000000..fd8c399 --- /dev/null +++ b/net/proxy/proxy_resolver_script_data.cc @@ -0,0 +1,48 @@ +// 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 "net/proxy/proxy_resolver_script_data.h" + +#include "base/logging.h" +#include "base/utf_string_conversions.h" + +namespace net { + +// static +scoped_refptr<ProxyResolverScriptData> ProxyResolverScriptData::FromUTF8( + const std::string& utf8) { + return new ProxyResolverScriptData(TYPE_SCRIPT_CONTENTS, + GURL(), + UTF8ToUTF16(utf8)); +} + +// static +scoped_refptr<ProxyResolverScriptData> ProxyResolverScriptData::FromUTF16( + const string16& utf16) { + return new ProxyResolverScriptData(TYPE_SCRIPT_CONTENTS, GURL(), utf16); +} + +// static +scoped_refptr<ProxyResolverScriptData> ProxyResolverScriptData::FromURL( + const GURL& url) { + return new ProxyResolverScriptData(TYPE_SCRIPT_URL, url, string16()); +} + +// static +scoped_refptr<ProxyResolverScriptData> +ProxyResolverScriptData::ForAutoDetect() { + return new ProxyResolverScriptData(TYPE_AUTO_DETECT, GURL(), string16()); +} + +const string16& ProxyResolverScriptData::utf16() const { + DCHECK_EQ(TYPE_SCRIPT_CONTENTS, type_); + return utf16_; +} + +const GURL& ProxyResolverScriptData::url() const { + DCHECK_EQ(TYPE_SCRIPT_URL, type_); + return url_; +} + +} // namespace net diff --git a/net/proxy/proxy_resolver_script_data.h b/net/proxy/proxy_resolver_script_data.h new file mode 100644 index 0000000..f0bb2ee --- /dev/null +++ b/net/proxy/proxy_resolver_script_data.h @@ -0,0 +1,71 @@ +// 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 NET_PROXY_PROXY_RESOLVER_SCRIPT_DATA_H_ +#define NET_PROXY_PROXY_RESOLVER_SCRIPT_DATA_H_ + +#include "base/ref_counted.h" +#include "base/string16.h" +#include "googleurl/src/gurl.h" + +namespace net { + +// Reference-counted wrapper for passing around a PAC script specification. +// The PAC script can be either specified via a URL, a deferred URL for +// auto-detect, or the actual javascript program text. +// +// This is thread-safe so it can be used by multi-threaded implementations of +// ProxyResolver to share the data between threads. +class ProxyResolverScriptData + : public base::RefCountedThreadSafe<ProxyResolverScriptData> { + public: + enum Type { + TYPE_SCRIPT_CONTENTS, + TYPE_SCRIPT_URL, + TYPE_AUTO_DETECT, + }; + + // Creates a script data given the UTF8 bytes of the content. + static scoped_refptr<ProxyResolverScriptData> FromUTF8( + const std::string& utf8); + + // Creates a script data given the UTF16 bytes of the content. + static scoped_refptr<ProxyResolverScriptData> FromUTF16( + const string16& utf16); + + // Creates a script data given a URL to the PAC script. + static scoped_refptr<ProxyResolverScriptData> FromURL(const GURL& url); + + // Creates a script data for using an automatically detected PAC URL. + static scoped_refptr<ProxyResolverScriptData> ForAutoDetect(); + + Type type() const { + return type_; + } + + // Returns the contents of the script as UTF16. + // (only valid for type() == TYPE_SCRIPT_CONTENTS). + const string16& utf16() const; + + // Returns the URL of the script. + // (only valid for type() == TYPE_SCRIPT_URL). + const GURL& url() const; + + private: + ProxyResolverScriptData(Type type, + const GURL& url, + const string16& utf16) + : type_(type), + url_(url), + utf16_(utf16) { + } + + const Type type_; + const GURL url_; + const string16 utf16_; +}; + +} // namespace net + +#endif // NET_PROXY_PROXY_RESOLVER_SCRIPT_DATA_H_ diff --git a/net/proxy/proxy_resolver_v8.cc b/net/proxy/proxy_resolver_v8.cc index 78906b8..495bbe9 100644 --- a/net/proxy/proxy_resolver_v8.cc +++ b/net/proxy/proxy_resolver_v8.cc @@ -73,22 +73,26 @@ const char kPacResourceName[] = "proxy-pac-script.js"; // Pseudo-name for the PAC utility script. const char kPacUtilityResourceName[] = "proxy-pac-utility-script.js"; -// External string wrapper so V8 can access a string16. -class V8ExternalString16 : public v8::String::ExternalStringResource { +// External string wrapper so V8 can access the UTF16 string wrapped by +// ProxyResolverScriptData. +class V8ExternalStringFromScriptData + : public v8::String::ExternalStringResource { public: - explicit V8ExternalString16(const string16& string) : string_(string) {} + explicit V8ExternalStringFromScriptData( + const scoped_refptr<ProxyResolverScriptData>& script_data) + : script_data_(script_data) {} virtual const uint16_t* data() const { - return reinterpret_cast<const uint16*>(string_.data()); + return reinterpret_cast<const uint16*>(script_data_->utf16().data()); } virtual size_t length() const { - return string_.size(); + return script_data_->utf16().size(); } private: - const string16 string_; - DISALLOW_COPY_AND_ASSIGN(V8ExternalString16); + const scoped_refptr<ProxyResolverScriptData> script_data_; + DISALLOW_COPY_AND_ASSIGN(V8ExternalStringFromScriptData); }; // External string wrapper so V8 can access a string literal. @@ -115,27 +119,6 @@ class V8ExternalASCIILiteral : public v8::String::ExternalAsciiStringResource { DISALLOW_COPY_AND_ASSIGN(V8ExternalASCIILiteral); }; -// External string wrapper so V8 can access a std::string. -class V8ExternalASCIIString : public v8::String::ExternalAsciiStringResource { - public: - explicit V8ExternalASCIIString(const std::string& ascii) - : ascii_(ascii) { - DCHECK(IsStringASCII(ascii)); - } - - virtual const char* data() const { - return ascii_.data(); - } - - virtual size_t length() const { - return ascii_.size(); - } - - private: - const std::string ascii_; - DISALLOW_COPY_AND_ASSIGN(V8ExternalASCIIString); -}; - // When creating a v8::String from a C++ string we have two choices: create // a copy, or create a wrapper that shares the same underlying storage. // For small strings it is better to just make a copy, whereas for large @@ -156,18 +139,19 @@ string16 V8StringToUTF16(v8::Handle<v8::String> s) { // Converts an ASCII std::string to a V8 string. v8::Local<v8::String> ASCIIStringToV8String(const std::string& s) { DCHECK(IsStringASCII(s)); - if (s.size() <= kMaxStringBytesForCopy) - return v8::String::New(s.data(), s.size()); - return v8::String::NewExternal(new V8ExternalASCIIString(s)); + return v8::String::New(s.data(), s.size()); } -// Converts a UTF16 string16 to a V8 string. -v8::Local<v8::String> UTF16StringToV8String(const string16& s) { - if (s.size() * 2 <= kMaxStringBytesForCopy) { +// Converts a UTF16 string16 (warpped by a ProxyResolverScriptData) to a +// V8 string. +v8::Local<v8::String> ScriptDataToV8String( + const scoped_refptr<ProxyResolverScriptData>& s) { + if (s->utf16().size() * 2 <= kMaxStringBytesForCopy) { return v8::String::New( - reinterpret_cast<const uint16_t*>(s.data()), s.size()); + reinterpret_cast<const uint16_t*>(s->utf16().data()), + s->utf16().size()); } - return v8::String::NewExternal(new V8ExternalString16(s)); + return v8::String::NewExternal(new V8ExternalStringFromScriptData(s)); } // Converts an ASCII string literal to a V8 string. @@ -304,7 +288,7 @@ class ProxyResolverV8::Context { return OK; } - int InitV8(const string16& pac_script) { + int InitV8(const scoped_refptr<ProxyResolverScriptData>& pac_script) { v8::Locker locked; v8::HandleScope scope; @@ -356,7 +340,7 @@ class ProxyResolverV8::Context { } // Add the user's PAC code to the environment. - rv = RunScript(UTF16StringToV8String(pac_script), kPacResourceName); + rv = RunScript(ScriptDataToV8String(pac_script), kPacResourceName); if (rv != OK) return rv; @@ -592,16 +576,17 @@ void ProxyResolverV8::Shutdown() { js_bindings_->Shutdown(); } -int ProxyResolverV8::SetPacScript(const GURL& /*url*/, - const string16& pac_script, - CompletionCallback* /*callback*/) { +int ProxyResolverV8::SetPacScript( + const scoped_refptr<ProxyResolverScriptData>& script_data, + CompletionCallback* /*callback*/) { + DCHECK(script_data.get()); context_.reset(); - if (pac_script.empty()) + if (script_data->utf16().empty()) return ERR_PAC_SCRIPT_FAILED; // Try parsing the PAC script. scoped_ptr<Context> context(new Context(js_bindings_.get())); - int rv = context->InitV8(pac_script); + int rv = context->InitV8(script_data); if (rv == OK) context_.reset(context.release()); return rv; diff --git a/net/proxy/proxy_resolver_v8.h b/net/proxy/proxy_resolver_v8.h index 20f31fc..8d7a231 100644 --- a/net/proxy/proxy_resolver_v8.h +++ b/net/proxy/proxy_resolver_v8.h @@ -51,6 +51,9 @@ class ProxyResolverV8 : public ProxyResolver { virtual void CancelRequest(RequestHandle request); virtual void PurgeMemory(); virtual void Shutdown(); + virtual int SetPacScript( + const scoped_refptr<ProxyResolverScriptData>& script_data, + CompletionCallback* /*callback*/); ProxyResolverJSBindings* js_bindings() const { return js_bindings_.get(); } @@ -59,11 +62,6 @@ class ProxyResolverV8 : public ProxyResolver { // script. It corresponds with the data from the last call to // SetPacScript(). class Context; - - // ProxyResolver implementation: - virtual int SetPacScript(const GURL& /*pac_url*/, - const string16& pac_script, - CompletionCallback* /*callback*/); scoped_ptr<Context> context_; scoped_ptr<ProxyResolverJSBindings> js_bindings_; diff --git a/net/proxy/proxy_resolver_v8_unittest.cc b/net/proxy/proxy_resolver_v8_unittest.cc index afe79e3..f0bfa1d 100644 --- a/net/proxy/proxy_resolver_v8_unittest.cc +++ b/net/proxy/proxy_resolver_v8_unittest.cc @@ -111,7 +111,8 @@ class ProxyResolverV8WithMockBindings : public ProxyResolverV8 { } // Load the PAC script into the ProxyResolver. - return SetPacScriptByData(UTF8ToUTF16(file_contents), NULL); + return SetPacScript(ProxyResolverScriptData::FromUTF8(file_contents), + NULL); } }; @@ -368,7 +369,8 @@ TEST(ProxyResolverV8Test, NoSetPacScript) { EXPECT_EQ(OK, result); // Clear it, by initializing with an empty string. - resolver.SetPacScriptByData(string16(), NULL); + resolver.SetPacScript( + ProxyResolverScriptData::FromUTF16(string16()), NULL); // Resolve should fail again now. result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, diff --git a/net/proxy/proxy_resolver_winhttp.cc b/net/proxy/proxy_resolver_winhttp.cc index 9715f02..d7aaae3 100644 --- a/net/proxy/proxy_resolver_winhttp.cc +++ b/net/proxy/proxy_resolver_winhttp.cc @@ -140,10 +140,14 @@ void ProxyResolverWinHttp::CancelRequest(RequestHandle request) { NOTREACHED(); } -int ProxyResolverWinHttp::SetPacScript(const GURL& pac_url, - const string16& /*pac_script*/, - CompletionCallback* /*callback*/) { - pac_url_ = pac_url.is_valid() ? pac_url : GURL("http://wpad/wpad.dat"); +int ProxyResolverWinHttp::SetPacScript( + const scoped_refptr<ProxyResolverScriptData>& script_data, + CompletionCallback* /*callback*/) { + if (script_data->type() == ProxyResolverScriptData::TYPE_AUTO_DETECT) { + pac_url_ = GURL("http://wpad/wpad.dat"); + } else { + pac_url_ = script_data->url(); + } return OK; } diff --git a/net/proxy/proxy_resolver_winhttp.h b/net/proxy/proxy_resolver_winhttp.h index 4eba3f4..7ad40dc 100644 --- a/net/proxy/proxy_resolver_winhttp.h +++ b/net/proxy/proxy_resolver_winhttp.h @@ -28,12 +28,11 @@ class ProxyResolverWinHttp : public ProxyResolver { RequestHandle* /*request*/, const BoundNetLog& /*net_log*/); virtual void CancelRequest(RequestHandle request); + virtual int SetPacScript( + const scoped_refptr<ProxyResolverScriptData>& script_data, + CompletionCallback* /*callback*/); private: - // ProxyResolver implementation: - virtual int SetPacScript(const GURL& pac_url, - const string16& /*pac_script*/, - CompletionCallback* /*callback*/); bool OpenWinHttpSession(); void CloseWinHttpSession(); diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index a613f6a9..8f9d28c 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -70,10 +70,9 @@ class ProxyResolverNull : public ProxyResolver { NOTREACHED(); } - private: - virtual int SetPacScript(const GURL& /*pac_url*/, - const string16& /*pac_script*/, - CompletionCallback* /*callback*/) { + virtual int SetPacScript( + const scoped_refptr<ProxyResolverScriptData>& /*script_data*/, + CompletionCallback* /*callback*/) { return ERR_NOT_IMPLEMENTED; } }; diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc index adad32fb..a69b66e 100644 --- a/net/proxy/proxy_service_unittest.cc +++ b/net/proxy/proxy_service_unittest.cc @@ -131,7 +131,7 @@ TEST(ProxyServiceTest, PAC) { EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(GURL("http://foopy/proxy.pac"), - resolver->pending_set_pac_script_request()->pac_url()); + resolver->pending_set_pac_script_request()->script_data()->url()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -176,7 +176,7 @@ TEST(ProxyServiceTest, PAC_NoIdentityOrHash) { EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(GURL("http://foopy/proxy.pac"), - resolver->pending_set_pac_script_request()->pac_url()); + resolver->pending_set_pac_script_request()->script_data()->url()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -204,7 +204,7 @@ TEST(ProxyServiceTest, PAC_FailoverWithoutDirect) { EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(GURL("http://foopy/proxy.pac"), - resolver->pending_set_pac_script_request()->pac_url()); + resolver->pending_set_pac_script_request()->script_data()->url()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -262,7 +262,7 @@ TEST(ProxyServiceTest, PAC_FailoverAfterDirect) { EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(GURL("http://foopy/proxy.pac"), - resolver->pending_set_pac_script_request()->pac_url()); + resolver->pending_set_pac_script_request()->script_data()->url()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -328,7 +328,7 @@ TEST(ProxyServiceTest, ProxyResolverFails) { EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(GURL("http://foopy/proxy.pac"), - resolver->pending_set_pac_script_request()->pac_url()); + resolver->pending_set_pac_script_request()->script_data()->url()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -382,7 +382,7 @@ TEST(ProxyServiceTest, ProxyFallback) { EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(GURL("http://foopy/proxy.pac"), - resolver->pending_set_pac_script_request()->pac_url()); + resolver->pending_set_pac_script_request()->script_data()->url()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -472,7 +472,7 @@ TEST(ProxyServiceTest, ProxyFallbackToDirect) { EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(GURL("http://foopy/proxy.pac"), - resolver->pending_set_pac_script_request()->pac_url()); + resolver->pending_set_pac_script_request()->script_data()->url()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -535,7 +535,7 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) { EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(GURL("http://foopy/proxy.pac"), - resolver->pending_set_pac_script_request()->pac_url()); + resolver->pending_set_pac_script_request()->script_data()->url()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -561,7 +561,7 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) { EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), - resolver->pending_set_pac_script_request()->pac_url()); + resolver->pending_set_pac_script_request()->script_data()->url()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -593,7 +593,7 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) { EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), - resolver->pending_set_pac_script_request()->pac_url()); + resolver->pending_set_pac_script_request()->script_data()->url()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -627,7 +627,7 @@ TEST(ProxyServiceTest, ProxyFallback_BadConfig) { EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(GURL("http://foopy/proxy.pac"), - resolver->pending_set_pac_script_request()->pac_url()); + resolver->pending_set_pac_script_request()->script_data()->url()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); EXPECT_EQ(url, resolver->pending_requests()[0]->url()); @@ -859,7 +859,7 @@ TEST(ProxyServiceTest, CancelInProgressRequest) { // Successfully initialize the PAC script. EXPECT_EQ(GURL("http://foopy/proxy.pac"), - resolver->pending_set_pac_script_request()->pac_url()); + resolver->pending_set_pac_script_request()->script_data()->url()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -958,7 +958,7 @@ TEST(ProxyServiceTest, InitialPACScriptDownload) { // Now that the PAC script is downloaded, it will have been sent to the proxy // resolver. EXPECT_EQ(ASCIIToUTF16("pac-v1"), - resolver->pending_set_pac_script_request()->pac_script()); + resolver->pending_set_pac_script_request()->script_data()->utf16()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(3u, resolver->pending_requests().size()); @@ -1039,7 +1039,7 @@ TEST(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) { // Now that the PAC script is downloaded, it will have been sent to the proxy // resolver. EXPECT_EQ(ASCIIToUTF16("pac-v1"), - resolver->pending_set_pac_script_request()->pac_script()); + resolver->pending_set_pac_script_request()->script_data()->utf16()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(2u, resolver->pending_requests().size()); @@ -1102,7 +1102,7 @@ TEST(ProxyServiceTest, CancelWhilePACFetching) { // Now that the PAC script is downloaded, it will have been sent to the // proxy resolver. EXPECT_EQ(ASCIIToUTF16("pac-v1"), - resolver->pending_set_pac_script_request()->pac_script()); + resolver->pending_set_pac_script_request()->script_data()->utf16()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -1180,7 +1180,7 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { fetcher->NotifyFetchCompletion(OK, "custom-pac-script"); EXPECT_EQ(ASCIIToUTF16("custom-pac-script"), - resolver->pending_set_pac_script_request()->pac_script()); + resolver->pending_set_pac_script_request()->script_data()->utf16()); resolver->pending_set_pac_script_request()->CompleteNow(OK); // Now finally, the pending requests should have been sent to the resolver @@ -1246,7 +1246,7 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) { // Simulate a parse error. EXPECT_EQ(ASCIIToUTF16("invalid-script-contents"), - resolver->pending_set_pac_script_request()->pac_script()); + resolver->pending_set_pac_script_request()->script_data()->utf16()); resolver->pending_set_pac_script_request()->CompleteNow( ERR_PAC_SCRIPT_FAILED); @@ -1256,7 +1256,7 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) { fetcher->NotifyFetchCompletion(OK, "custom-pac-script"); EXPECT_EQ(ASCIIToUTF16("custom-pac-script"), - resolver->pending_set_pac_script_request()->pac_script()); + resolver->pending_set_pac_script_request()->script_data()->utf16()); resolver->pending_set_pac_script_request()->CompleteNow(OK); // Now finally, the pending requests should have been sent to the resolver @@ -1372,7 +1372,7 @@ TEST(ProxyServiceTest, BypassDoesntApplyToPac) { fetcher->NotifyFetchCompletion(OK, "auto-detect"); EXPECT_EQ(ASCIIToUTF16("auto-detect"), - resolver->pending_set_pac_script_request()->pac_script()); + resolver->pending_set_pac_script_request()->script_data()->utf16()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -1464,7 +1464,7 @@ TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(GURL("http://foopy/proxy.pac"), - resolver->pending_set_pac_script_request()->pac_url()); + resolver->pending_set_pac_script_request()->script_data()->url()); // Delete the ProxyService. service = NULL; @@ -1522,7 +1522,8 @@ TEST(ProxyServiceTest, UpdateConfigAfterFailedAutodetect) { ASSERT_EQ(0u, resolver->pending_requests().size()); // Fail the setting of autodetect script. - EXPECT_EQ(GURL(), resolver->pending_set_pac_script_request()->pac_url()); + EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, + resolver->pending_set_pac_script_request()->script_data()->type()); resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); // Verify that request ran as expected -- should have fallen back to direct. @@ -1568,7 +1569,8 @@ TEST(ProxyServiceTest, UpdateConfigFromPACToDirect) { ASSERT_EQ(0u, resolver->pending_requests().size()); // Successfully set the autodetect script. - EXPECT_EQ(GURL(), resolver->pending_set_pac_script_request()->pac_url()); + EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, + resolver->pending_set_pac_script_request()->script_data()->type()); resolver->pending_set_pac_script_request()->CompleteNow(OK); // Complete the pending request. @@ -1635,7 +1637,7 @@ TEST(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { // Now that the PAC script is downloaded, the request will have been sent to // the proxy resolver. EXPECT_EQ(ASCIIToUTF16("pac-v1"), - resolver->pending_set_pac_script_request()->pac_script()); + resolver->pending_set_pac_script_request()->script_data()->utf16()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -1677,7 +1679,7 @@ TEST(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { // Now that the PAC script is downloaded, the second request will have been // sent to the proxy resolver. EXPECT_EQ(ASCIIToUTF16("pac-v2"), - resolver->pending_set_pac_script_request()->pac_script()); + resolver->pending_set_pac_script_request()->script_data()->utf16()); resolver->pending_set_pac_script_request()->CompleteNow(OK); ASSERT_EQ(1u, resolver->pending_requests().size()); diff --git a/net/proxy/sync_host_resolver_bridge_unittest.cc b/net/proxy/sync_host_resolver_bridge_unittest.cc index 1a5b1337..95ba446 100644 --- a/net/proxy/sync_host_resolver_bridge_unittest.cc +++ b/net/proxy/sync_host_resolver_bridge_unittest.cc @@ -109,13 +109,13 @@ class SyncProxyResolver : public ProxyResolver { host_resolver_->Shutdown(); } - private: - virtual int SetPacScript(const GURL& pac_url, - const string16& pac_script, - CompletionCallback* callback) { + virtual int SetPacScript( + const scoped_refptr<ProxyResolverScriptData>& script_data, + CompletionCallback* callback) { return OK; } + private: scoped_refptr<SyncHostResolverBridge> host_resolver_; }; @@ -165,7 +165,8 @@ class IOThread : public base::Thread { // Initialize the resolver. TestCompletionCallback callback; - proxy_resolver_->SetPacScriptByUrl(GURL(), &callback); + proxy_resolver_->SetPacScript(ProxyResolverScriptData::FromURL(GURL()), + &callback); EXPECT_EQ(OK, callback.WaitForResult()); // Start an asynchronous request to the proxy resolver |