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

Unified Diff: content/browser/net/url_request_mock_http_job.cc

Issue 6973052: When the download folder does not exist, change the download folder to a user's "Downloads" (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Added URLRequestMockHTTPJob.test_dir_ and URLRequestMockHTTPJob.temp_dir_ Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/net/url_request_mock_http_job.cc
diff --git a/content/browser/net/url_request_mock_http_job.cc b/content/browser/net/url_request_mock_http_job.cc
index 2691e2fa353b1b5ec6e3497ed1a39778357c60bc..18d4de4b55672d9d14676a1577e376c84db2af7e 100644
--- a/content/browser/net/url_request_mock_http_job.cc
+++ b/content/browser/net/url_request_mock_http_job.cc
@@ -15,21 +15,30 @@
#include "net/url_request/url_request_filter.h"
static const char kMockHostname[] = "mock.http";
+static const char kMockHostnameOfTempDir[] = "mock.temp.http";
static const FilePath::CharType kMockHeaderFileSuffix[] =
FILE_PATH_LITERAL(".mock-http-headers");
-FilePath URLRequestMockHTTPJob::base_path_;
+FilePath URLRequestMockHTTPJob::test_dir_;
+FilePath URLRequestMockHTTPJob::temp_dir_;
// static
net::URLRequestJob* URLRequestMockHTTPJob::Factory(net::URLRequest* request,
const std::string& scheme) {
return new URLRequestMockHTTPJob(request,
- GetOnDiskPath(base_path_, request, scheme));
+ GetOnDiskPath(test_dir_, request, scheme));
}
// static
-void URLRequestMockHTTPJob::AddUrlHandler(const FilePath& base_path) {
- base_path_ = base_path;
+net::URLRequestJob* URLRequestMockHTTPJob::FactoryForMockUrlOfTempDir(
+ net::URLRequest* request, const std::string& scheme) {
+ return new URLRequestMockHTTPJob(request,
+ GetOnDiskPath(temp_dir_, request, scheme));
+}
+
+// static
+void URLRequestMockHTTPJob::AddUrlHandler(const FilePath& test_dir) {
+ test_dir_ = test_dir;
// Add kMockHostname to net::URLRequestFilter.
net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance();
@@ -37,6 +46,16 @@ void URLRequestMockHTTPJob::AddUrlHandler(const FilePath& base_path) {
URLRequestMockHTTPJob::Factory);
}
+// static
+void URLRequestMockHTTPJob::AddUrlOfTempDirHandler(const FilePath& temp_dir) {
+ temp_dir_ = temp_dir;
+
+ // Add kMockHostnameOfTempDir to net::URLRequestFilter.
+ net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance();
+ filter->AddHostnameHandler("http", kMockHostnameOfTempDir,
+ URLRequestMockHTTPJob::FactoryForMockUrlOfTempDir);
+}
+
/* static */
GURL URLRequestMockHTTPJob::GetMockUrl(const FilePath& path) {
std::string url = "http://";
@@ -49,6 +68,17 @@ GURL URLRequestMockHTTPJob::GetMockUrl(const FilePath& path) {
}
/* static */
+GURL URLRequestMockHTTPJob::GetMockUrlOfTempDir(const FilePath& path) {
+ std::string url = "http://";
+ url.append(kMockHostnameOfTempDir);
+ url.append("/");
eroman 2011/08/04 20:09:44 note you can also use GURL::ReplaceComponents() to
haraken1 2011/08/08 06:18:53 Thanks, but now this routine is moved into browser
+ std::string path_str = path.MaybeAsASCII();
+ DCHECK(!path_str.empty()); // We only expect ASCII paths in tests.
+ url.append(path_str);
+ return GURL(url);
+}
+
+/* static */
GURL URLRequestMockHTTPJob::GetMockViewSourceUrl(const FilePath& path) {
std::string url = chrome::kViewSourceScheme;
url.append(":");

Powered by Google App Engine
This is Rietveld 408576698