Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: chrome/browser/component_updater/component_updater_interceptor.cc

Issue 11293252: Change Interceptors into URLRequestJobFactory::ProtocolHandlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #include "chrome/browser/component_updater/component_updater_interceptor.h"
5
6 #include "base/file_util.h"
7 #include "base/threading/thread_restrictions.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "net/url_request/url_request.h"
10 #include "net/url_request/url_request_test_job.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 using content::BrowserThread;
14
15 ComponentUpdateInterceptor::ComponentUpdateInterceptor()
16 : hit_count_(0) {
17 net::URLRequest::Deprecated::RegisterRequestInterceptor(this);
18 }
19
20 ComponentUpdateInterceptor::~ComponentUpdateInterceptor() {
21 net::URLRequest::Deprecated::UnregisterRequestInterceptor(this);
22 }
23
24 net::URLRequestJob* ComponentUpdateInterceptor::MaybeIntercept(
25 net::URLRequest* request, net::NetworkDelegate* network_delegate) {
26 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
27 if (request->url().scheme() != "http" ||
28 request->url().host() != "localhost") {
29 return NULL;
30 }
31
32 // It's ok to do a blocking disk access on this thread; this class
33 // is just used for tests.
34 base::ThreadRestrictions::ScopedAllowIO allow_io;
35
36 ResponseMap::iterator it = responses_.find(request->url());
37 if (it == responses_.end()) {
38 return NULL;
39 }
40 const Response& response = it->second;
41 ++hit_count_;
42
43 std::string contents;
44 EXPECT_TRUE(file_util::ReadFileToString(response.data_path, &contents));
45
46 return new net::URLRequestTestJob(request,
47 network_delegate,
48 response.headers,
49 contents,
50 true);
51 }
52
53 void ComponentUpdateInterceptor::SetResponse(const std::string& url,
54 const std::string& headers,
55 const FilePath& path) {
56 // It's ok to do a blocking disk access on this thread; this class
57 // is just used for tests.
58 base::ThreadRestrictions::ScopedAllowIO allow_io;
59 GURL gurl(url);
60 EXPECT_EQ("http", gurl.scheme());
61 EXPECT_EQ("localhost", gurl.host());
62 EXPECT_TRUE(file_util::PathExists(path));
63 Response response = { path, headers };
64 responses_[gurl] = response;
65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698