OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/autoupdate_interceptor.h" | 5 #include "chrome/browser/extensions/autoupdate_interceptor.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/thread_restrictions.h" | 8 #include "base/thread_restrictions.h" |
9 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
10 #include "net/url_request/url_request_test_job.h" | 10 #include "net/url_request/url_request_test_job.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 // This is a specialized version of URLRequestTestJob that lets us specify | 13 // This is a specialized version of URLRequestTestJob that lets us specify |
14 // response data and make sure the response code is 200, which the autoupdate | 14 // response data and make sure the response code is 200, which the autoupdate |
15 // code relies on. | 15 // code relies on. |
16 class AutoUpdateTestRequestJob : public URLRequestTestJob { | 16 class AutoUpdateTestRequestJob : public URLRequestTestJob { |
17 public: | 17 public: |
18 AutoUpdateTestRequestJob(URLRequest* request, | 18 AutoUpdateTestRequestJob(net::URLRequest* request, |
19 const std::string& response_data) : URLRequestTestJob( | 19 const std::string& response_data) : URLRequestTestJob( |
20 request, URLRequestTestJob::test_headers(), response_data, true) {} | 20 request, URLRequestTestJob::test_headers(), response_data, true) {} |
21 virtual int GetResponseCode() const { return 200; } | 21 virtual int GetResponseCode() const { return 200; } |
22 | 22 |
23 private: | 23 private: |
24 ~AutoUpdateTestRequestJob() {} | 24 ~AutoUpdateTestRequestJob() {} |
25 }; | 25 }; |
26 | 26 |
27 | 27 |
28 AutoUpdateInterceptor::AutoUpdateInterceptor() { | 28 AutoUpdateInterceptor::AutoUpdateInterceptor() { |
29 URLRequest::RegisterRequestInterceptor(this); | 29 net::URLRequest::RegisterRequestInterceptor(this); |
30 } | 30 } |
31 | 31 |
32 AutoUpdateInterceptor::~AutoUpdateInterceptor() { | 32 AutoUpdateInterceptor::~AutoUpdateInterceptor() { |
33 URLRequest::UnregisterRequestInterceptor(this); | 33 net::URLRequest::UnregisterRequestInterceptor(this); |
34 } | 34 } |
35 | 35 |
36 | 36 URLRequestJob* AutoUpdateInterceptor::MaybeIntercept(net::URLRequest* request) { |
37 URLRequestJob* AutoUpdateInterceptor::MaybeIntercept(URLRequest* request) { | |
38 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 37 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
39 if (request->url().scheme() != "http" || | 38 if (request->url().scheme() != "http" || |
40 request->url().host() != "localhost") { | 39 request->url().host() != "localhost") { |
41 return NULL; | 40 return NULL; |
42 } | 41 } |
43 | 42 |
44 // It's ok to do a blocking disk access on this thread; this class | 43 // It's ok to do a blocking disk access on this thread; this class |
45 // is just used for tests. | 44 // is just used for tests. |
46 base::ThreadRestrictions::ScopedAllowIO allow_io; | 45 base::ThreadRestrictions::ScopedAllowIO allow_io; |
47 | 46 |
(...skipping 28 matching lines...) Expand all Loading... |
76 responses_[gurl] = path; | 75 responses_[gurl] = path; |
77 } | 76 } |
78 | 77 |
79 | 78 |
80 void AutoUpdateInterceptor::SetResponseOnIOThread(const std::string url, | 79 void AutoUpdateInterceptor::SetResponseOnIOThread(const std::string url, |
81 const FilePath& path) { | 80 const FilePath& path) { |
82 BrowserThread::PostTask( | 81 BrowserThread::PostTask( |
83 BrowserThread::IO, FROM_HERE, | 82 BrowserThread::IO, FROM_HERE, |
84 NewRunnableMethod(this, &AutoUpdateInterceptor::SetResponse, url, path)); | 83 NewRunnableMethod(this, &AutoUpdateInterceptor::SetResponse, url, path)); |
85 } | 84 } |
OLD | NEW |