summaryrefslogtreecommitdiffstats
path: root/net/url_request
diff options
context:
space:
mode:
Diffstat (limited to 'net/url_request')
-rw-r--r--net/url_request/url_request_about_job.cc8
-rw-r--r--net/url_request/url_request_about_job.h7
-rw-r--r--net/url_request/url_request_context.cc8
-rw-r--r--net/url_request/url_request_file_dir_job.cc66
-rw-r--r--net/url_request/url_request_file_dir_job.h8
-rw-r--r--net/url_request/url_request_file_job.cc158
-rw-r--r--net/url_request/url_request_file_job.h13
-rw-r--r--net/url_request/url_request_job_manager.cc18
-rw-r--r--net/url_request/url_request_job_manager.h20
9 files changed, 155 insertions, 151 deletions
diff --git a/net/url_request/url_request_about_job.cc b/net/url_request/url_request_about_job.cc
index b8dab1a..f48e72a 100644
--- a/net/url_request/url_request_about_job.cc
+++ b/net/url_request/url_request_about_job.cc
@@ -12,16 +12,16 @@
namespace net {
+URLRequestAboutJob::URLRequestAboutJob(URLRequest* request)
+ : URLRequestJob(request) {
+}
+
// static
URLRequestJob* URLRequestAboutJob::Factory(URLRequest* request,
const std::string& scheme) {
return new URLRequestAboutJob(request);
}
-URLRequestAboutJob::URLRequestAboutJob(URLRequest* request)
- : URLRequestJob(request) {
-}
-
void URLRequestAboutJob::Start() {
// Start reading asynchronously so that all error reporting and data
// callbacks happen as they would for network requests.
diff --git a/net/url_request/url_request_about_job.h b/net/url_request/url_request_about_job.h
index 7617208..4703830 100644
--- a/net/url_request/url_request_about_job.h
+++ b/net/url_request/url_request_about_job.h
@@ -17,13 +17,14 @@ class URLRequestAboutJob : public URLRequestJob {
public:
explicit URLRequestAboutJob(URLRequest* request);
+ static URLRequest::ProtocolFactory Factory;
+
+ // URLRequestJob:
virtual void Start();
virtual bool GetMimeType(std::string* mime_type) const;
- static URLRequest::ProtocolFactory Factory;
-
private:
- ~URLRequestAboutJob();
+ virtual ~URLRequestAboutJob();
void StartAsync();
};
diff --git a/net/url_request/url_request_context.cc b/net/url_request/url_request_context.cc
index 8e0f3bd..6eb075c 100644
--- a/net/url_request/url_request_context.cc
+++ b/net/url_request/url_request_context.cc
@@ -25,6 +25,10 @@ URLRequestContext::URLRequestContext()
is_main_(false) {
}
+void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
+ cookie_store_ = cookie_store;
+}
+
const std::string& URLRequestContext::GetUserAgent(const GURL& url) const {
return EmptyString();
}
@@ -32,8 +36,4 @@ const std::string& URLRequestContext::GetUserAgent(const GURL& url) const {
URLRequestContext::~URLRequestContext() {
}
-void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
- cookie_store_ = cookie_store;
-}
-
} // namespace net
diff --git a/net/url_request/url_request_file_dir_job.cc b/net/url_request/url_request_file_dir_job.cc
index badb6b8..1cc15be 100644
--- a/net/url_request/url_request_file_dir_job.cc
+++ b/net/url_request/url_request_file_dir_job.cc
@@ -33,20 +33,6 @@ URLRequestFileDirJob::URLRequestFileDirJob(URLRequest* request,
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
}
-URLRequestFileDirJob::~URLRequestFileDirJob() {
- DCHECK(read_pending_ == false);
- DCHECK(lister_ == NULL);
-}
-
-void URLRequestFileDirJob::Start() {
- // Start reading asynchronously so that all error reporting and data
- // callbacks happen as they would for network requests.
- MessageLoop::current()->PostTask(
- FROM_HERE,
- method_factory_.NewRunnableMethod(
- &URLRequestFileDirJob::StartAsync));
-}
-
void URLRequestFileDirJob::StartAsync() {
DCHECK(!lister_);
@@ -63,6 +49,15 @@ void URLRequestFileDirJob::StartAsync() {
NotifyHeadersComplete();
}
+void URLRequestFileDirJob::Start() {
+ // Start reading asynchronously so that all error reporting and data
+ // callbacks happen as they would for network requests.
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ method_factory_.NewRunnableMethod(
+ &URLRequestFileDirJob::StartAsync));
+}
+
void URLRequestFileDirJob::Kill() {
if (canceled_)
return;
@@ -174,6 +169,11 @@ void URLRequestFileDirJob::OnListDone(int error) {
Release(); // The Lister is finished; may delete *this*
}
+URLRequestFileDirJob::~URLRequestFileDirJob() {
+ DCHECK(read_pending_ == false);
+ DCHECK(lister_ == NULL);
+}
+
void URLRequestFileDirJob::CloseLister() {
if (lister_) {
lister_->Cancel();
@@ -182,25 +182,6 @@ void URLRequestFileDirJob::CloseLister() {
}
}
-bool URLRequestFileDirJob::FillReadBuffer(char *buf, int buf_size,
- int *bytes_read) {
- DCHECK(bytes_read);
-
- *bytes_read = 0;
-
- int count = std::min(buf_size, static_cast<int>(data_.size()));
- if (count) {
- memcpy(buf, &data_[0], count);
- data_.erase(0, count);
- *bytes_read = count;
- return true;
- } else if (list_complete_) {
- // EOF
- return true;
- }
- return false;
-}
-
void URLRequestFileDirJob::CompleteRead() {
if (read_pending_) {
int bytes_read;
@@ -221,4 +202,23 @@ void URLRequestFileDirJob::CompleteRead() {
}
}
+bool URLRequestFileDirJob::FillReadBuffer(char *buf, int buf_size,
+ int *bytes_read) {
+ DCHECK(bytes_read);
+
+ *bytes_read = 0;
+
+ int count = std::min(buf_size, static_cast<int>(data_.size()));
+ if (count) {
+ memcpy(buf, &data_[0], count);
+ data_.erase(0, count);
+ *bytes_read = count;
+ return true;
+ } else if (list_complete_) {
+ // EOF
+ return true;
+ }
+ return false;
+}
+
} // namespace net
diff --git a/net/url_request/url_request_file_dir_job.h b/net/url_request/url_request_file_dir_job.h
index 2b40a98..f938417 100644
--- a/net/url_request/url_request_file_dir_job.h
+++ b/net/url_request/url_request_file_dir_job.h
@@ -22,9 +22,12 @@ class URLRequestFileDirJob
public:
URLRequestFileDirJob(URLRequest* request, const FilePath& dir_path);
+ bool list_complete() const { return list_complete_; }
+
+ virtual void StartAsync();
+
// Overridden from URLRequestJob:
virtual void Start();
- virtual void StartAsync();
virtual void Kill();
virtual bool ReadRawData(IOBuffer* buf, int buf_size, int *bytes_read);
virtual bool GetMimeType(std::string* mime_type) const;
@@ -35,12 +38,11 @@ class URLRequestFileDirJob
const DirectoryLister::DirectoryListerData& data);
virtual void OnListDone(int error);
- bool list_complete() const { return list_complete_; }
-
private:
virtual ~URLRequestFileDirJob();
void CloseLister();
+
// When we have data and a read has been pending, this function
// will fill the response buffer and notify the request
// appropriately.
diff --git a/net/url_request/url_request_file_job.cc b/net/url_request/url_request_file_job.cc
index 7a1599a..0f4c423 100644
--- a/net/url_request/url_request_file_job.cc
+++ b/net/url_request/url_request_file_job.cc
@@ -82,6 +82,17 @@ class URLRequestFileJob::AsyncResolver
};
#endif
+URLRequestFileJob::URLRequestFileJob(URLRequest* request,
+ const FilePath& file_path)
+ : URLRequestJob(request),
+ file_path_(file_path),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ io_callback_(this, &URLRequestFileJob::DidRead)),
+ is_directory_(false),
+ remaining_bytes_(0),
+ ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
+}
+
// static
URLRequestJob* URLRequestFileJob::Factory(URLRequest* request,
const std::string& scheme) {
@@ -111,22 +122,33 @@ URLRequestJob* URLRequestFileJob::Factory(URLRequest* request,
return new URLRequestFileJob(request, file_path);
}
-URLRequestFileJob::URLRequestFileJob(URLRequest* request,
- const FilePath& file_path)
- : URLRequestJob(request),
- file_path_(file_path),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- io_callback_(this, &URLRequestFileJob::DidRead)),
- is_directory_(false),
- remaining_bytes_(0),
- ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
-}
+#if defined(OS_CHROMEOS)
+static const char* const kLocalAccessWhiteList[] = {
+ "/home/chronos/user/Downloads",
+ "/media",
+ "/mnt/partner_partition",
+ "/usr/share/chromeos-assets",
+ "/tmp",
+ "/var/log",
+};
-URLRequestFileJob::~URLRequestFileJob() {
-#if defined(OS_WIN)
- DCHECK(!async_resolver_);
-#endif
+// static
+bool URLRequestFileJob::AccessDisabled(const FilePath& file_path) {
+ if (URLRequest::IsFileAccessAllowed()) { // for tests.
+ return false;
+ }
+
+ for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
+ const FilePath white_listed_path(kLocalAccessWhiteList[i]);
+ // FilePath::operator== should probably handle trailing seperators.
+ if (white_listed_path == file_path.StripTrailingSeparators() ||
+ white_listed_path.IsParent(file_path)) {
+ return false;
+ }
+ }
+ return true;
}
+#endif
void URLRequestFileJob::Start() {
#if defined(OS_WIN)
@@ -204,6 +226,43 @@ bool URLRequestFileJob::ReadRawData(IOBuffer* dest, int dest_size,
return false;
}
+bool URLRequestFileJob::IsRedirectResponse(GURL* location,
+ int* http_status_code) {
+ if (is_directory_) {
+ // This happens when we discovered the file is a directory, so needs a
+ // slash at the end of the path.
+ std::string new_path = request_->url().path();
+ new_path.push_back('/');
+ GURL::Replacements replacements;
+ replacements.SetPathStr(new_path);
+
+ *location = request_->url().ReplaceComponents(replacements);
+ *http_status_code = 301; // simulate a permanent redirect
+ return true;
+ }
+
+#if defined(OS_WIN)
+ // Follow a Windows shortcut.
+ // We just resolve .lnk file, ignore others.
+ if (!LowerCaseEqualsASCII(file_path_.Extension(), ".lnk"))
+ return false;
+
+ FilePath new_path = file_path_;
+ bool resolved;
+ resolved = file_util::ResolveShortcut(&new_path);
+
+ // If shortcut is not resolved succesfully, do not redirect.
+ if (!resolved)
+ return false;
+
+ *location = FilePathToFileURL(new_path);
+ *http_status_code = 301;
+ return true;
+#else
+ return false;
+#endif
+}
+
bool URLRequestFileJob::GetContentEncodings(
std::vector<Filter::FilterType>* encoding_types) {
DCHECK(encoding_types->empty());
@@ -245,6 +304,12 @@ void URLRequestFileJob::SetExtraRequestHeaders(
}
}
+URLRequestFileJob::~URLRequestFileJob() {
+#if defined(OS_WIN)
+ DCHECK(!async_resolver_);
+#endif
+}
+
void URLRequestFileJob::DidResolve(
bool exists, const base::PlatformFileInfo& file_info) {
#if defined(OS_WIN)
@@ -323,69 +388,4 @@ void URLRequestFileJob::DidRead(int result) {
NotifyReadComplete(result);
}
-bool URLRequestFileJob::IsRedirectResponse(GURL* location,
- int* http_status_code) {
- if (is_directory_) {
- // This happens when we discovered the file is a directory, so needs a
- // slash at the end of the path.
- std::string new_path = request_->url().path();
- new_path.push_back('/');
- GURL::Replacements replacements;
- replacements.SetPathStr(new_path);
-
- *location = request_->url().ReplaceComponents(replacements);
- *http_status_code = 301; // simulate a permanent redirect
- return true;
- }
-
-#if defined(OS_WIN)
- // Follow a Windows shortcut.
- // We just resolve .lnk file, ignore others.
- if (!LowerCaseEqualsASCII(file_path_.Extension(), ".lnk"))
- return false;
-
- FilePath new_path = file_path_;
- bool resolved;
- resolved = file_util::ResolveShortcut(&new_path);
-
- // If shortcut is not resolved succesfully, do not redirect.
- if (!resolved)
- return false;
-
- *location = FilePathToFileURL(new_path);
- *http_status_code = 301;
- return true;
-#else
- return false;
-#endif
-}
-
-#if defined(OS_CHROMEOS)
-static const char* const kLocalAccessWhiteList[] = {
- "/home/chronos/user/Downloads",
- "/media",
- "/mnt/partner_partition",
- "/usr/share/chromeos-assets",
- "/tmp",
- "/var/log",
-};
-
-// static
-bool URLRequestFileJob::AccessDisabled(const FilePath& file_path) {
- if (URLRequest::IsFileAccessAllowed()) { // for tests.
- return false;
- }
-
- for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
- const FilePath white_listed_path(kLocalAccessWhiteList[i]);
- // FilePath::operator== should probably handle trailing seperators.
- if (white_listed_path == file_path.StripTrailingSeparators() ||
- white_listed_path.IsParent(file_path)) {
- return false;
- }
- }
- return true;
-}
-#endif
-
} // namespace net
diff --git a/net/url_request/url_request_file_job.h b/net/url_request/url_request_file_job.h
index 1a09b04..4dbcb0b 100644
--- a/net/url_request/url_request_file_job.h
+++ b/net/url_request/url_request_file_job.h
@@ -28,6 +28,13 @@ class URLRequestFileJob : public URLRequestJob {
public:
URLRequestFileJob(URLRequest* request, const FilePath& file_path);
+ static URLRequest::ProtocolFactory Factory;
+
+#if defined(OS_CHROMEOS)
+ static bool AccessDisabled(const FilePath& file_path);
+#endif
+
+ // URLRequestJob:
virtual void Start();
virtual void Kill();
virtual bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read);
@@ -37,12 +44,6 @@ class URLRequestFileJob : public URLRequestJob {
virtual bool GetMimeType(std::string* mime_type) const;
virtual void SetExtraRequestHeaders(const HttpRequestHeaders& headers);
- static URLRequest::ProtocolFactory Factory;
-
-#if defined(OS_CHROMEOS)
- static bool AccessDisabled(const FilePath& file_path);
-#endif
-
protected:
virtual ~URLRequestFileJob();
diff --git a/net/url_request/url_request_job_manager.cc b/net/url_request/url_request_job_manager.cc
index f311cc4..5fd7be6 100644
--- a/net/url_request/url_request_job_manager.cc
+++ b/net/url_request/url_request_job_manager.cc
@@ -39,15 +39,6 @@ static const SchemeToFactory kBuiltinFactories[] = {
{ "data", URLRequestDataJob::Factory },
};
-URLRequestJobManager::URLRequestJobManager() : enable_file_access_(false) {
-#ifndef NDEBUG
- allowed_thread_ = 0;
- allowed_thread_initialized_ = false;
-#endif
-}
-
-URLRequestJobManager::~URLRequestJobManager() {}
-
// static
URLRequestJobManager* URLRequestJobManager::GetInstance() {
return Singleton<URLRequestJobManager>::get();
@@ -215,4 +206,13 @@ void URLRequestJobManager::UnregisterRequestInterceptor(
interceptors_.erase(i);
}
+URLRequestJobManager::URLRequestJobManager() : enable_file_access_(false) {
+#ifndef NDEBUG
+ allowed_thread_ = 0;
+ allowed_thread_initialized_ = false;
+#endif
+}
+
+URLRequestJobManager::~URLRequestJobManager() {}
+
} // namespace net
diff --git a/net/url_request/url_request_job_manager.h b/net/url_request/url_request_job_manager.h
index e4efcf5..ca9ada9 100644
--- a/net/url_request/url_request_job_manager.h
+++ b/net/url_request/url_request_job_manager.h
@@ -76,17 +76,7 @@ class URLRequestJobManager {
URLRequestJobManager();
~URLRequestJobManager();
- mutable base::Lock lock_;
- FactoryMap factories_;
- InterceptorList interceptors_;
- bool enable_file_access_;
-
#ifndef NDEBUG
- // We use this to assert that CreateJob and the registration functions all
- // run on the same thread.
- mutable base::PlatformThreadId allowed_thread_;
- mutable bool allowed_thread_initialized_;
-
// The first guy to call this function sets the allowed thread. This way we
// avoid needing to define that thread externally. Since we expect all
// callers to be on the same thread, we don't worry about threads racing to
@@ -110,8 +100,18 @@ class URLRequestJobManager {
return true;
#endif
}
+
+ // We use this to assert that CreateJob and the registration functions all
+ // run on the same thread.
+ mutable base::PlatformThreadId allowed_thread_;
+ mutable bool allowed_thread_initialized_;
#endif
+ mutable base::Lock lock_;
+ FactoryMap factories_;
+ InterceptorList interceptors_;
+ bool enable_file_access_;
+
DISALLOW_COPY_AND_ASSIGN(URLRequestJobManager);
};