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

Side by Side Diff: chrome/browser/net/url_request_mock_http_job.cc

Issue 3983005: Revert 63600 - Thread IO safety: annotate file_util, and block IO thread from... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 2 months 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
« no previous file with comments | « chrome/browser/io_thread.cc ('k') | chrome/browser/net/url_request_mock_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/net/url_request_mock_http_job.h" 5 #include "chrome/browser/net/url_request_mock_http_job.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/thread_restrictions.h"
11 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
12 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
13 #include "net/base/net_util.h" 12 #include "net/base/net_util.h"
14 #include "net/http/http_response_headers.h" 13 #include "net/http/http_response_headers.h"
15 #include "net/url_request/url_request_filter.h" 14 #include "net/url_request/url_request_filter.h"
16 15
17 static const char kMockHostname[] = "mock.http"; 16 static const char kMockHostname[] = "mock.http";
18 static const FilePath::CharType kMockHeaderFileSuffix[] = 17 static const FilePath::CharType kMockHeaderFileSuffix[] =
19 FILE_PATH_LITERAL(".mock-http-headers"); 18 FILE_PATH_LITERAL(".mock-http-headers");
20 19
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 bool URLRequestMockHTTPJob::IsRedirectResponse(GURL* location, 80 bool URLRequestMockHTTPJob::IsRedirectResponse(GURL* location,
82 int* http_status_code) { 81 int* http_status_code) {
83 // Override the URLRequestFileJob implementation to invoke the default one 82 // Override the URLRequestFileJob implementation to invoke the default one
84 // based on HttpResponseInfo. 83 // based on HttpResponseInfo.
85 return URLRequestJob::IsRedirectResponse(location, http_status_code); 84 return URLRequestJob::IsRedirectResponse(location, http_status_code);
86 } 85 }
87 86
88 // Private const version. 87 // Private const version.
89 void URLRequestMockHTTPJob::GetResponseInfoConst( 88 void URLRequestMockHTTPJob::GetResponseInfoConst(
90 net::HttpResponseInfo* info) const { 89 net::HttpResponseInfo* info) const {
91 // We have to load our headers from disk, but we only use this class
92 // from tests, so allow these IO operations to happen on any thread.
93 base::ThreadRestrictions::ScopedAllowIO allow_io;
94
95 FilePath header_file = FilePath(file_path_.value() + kMockHeaderFileSuffix); 90 FilePath header_file = FilePath(file_path_.value() + kMockHeaderFileSuffix);
96 std::string raw_headers; 91 std::string raw_headers;
97 if (!file_util::ReadFileToString(header_file, &raw_headers)) 92 if (!file_util::ReadFileToString(header_file, &raw_headers))
98 return; 93 return;
99 94
100 // ParseRawHeaders expects \0 to end each header line. 95 // ParseRawHeaders expects \0 to end each header line.
101 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); 96 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1));
102 info->headers = new net::HttpResponseHeaders(raw_headers); 97 info->headers = new net::HttpResponseHeaders(raw_headers);
103 } 98 }
104 99
105 bool URLRequestMockHTTPJob::GetMimeType(std::string* mime_type) const { 100 bool URLRequestMockHTTPJob::GetMimeType(std::string* mime_type) const {
106 net::HttpResponseInfo info; 101 net::HttpResponseInfo info;
107 GetResponseInfoConst(&info); 102 GetResponseInfoConst(&info);
108 return info.headers && info.headers->GetMimeType(mime_type); 103 return info.headers && info.headers->GetMimeType(mime_type);
109 } 104 }
110 105
111 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) { 106 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) {
112 net::HttpResponseInfo info; 107 net::HttpResponseInfo info;
113 GetResponseInfo(&info); 108 GetResponseInfo(&info);
114 return info.headers && info.headers->GetCharset(charset); 109 return info.headers && info.headers->GetCharset(charset);
115 } 110 }
OLDNEW
« no previous file with comments | « chrome/browser/io_thread.cc ('k') | chrome/browser/net/url_request_mock_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698