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

Unified Diff: chrome/browser/chromeos/fileapi/external_file_url_request_job.cc

Issue 580023003: Rename the drive: scheme with the externalfile: scheme. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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: chrome/browser/chromeos/fileapi/external_file_url_request_job.cc
diff --git a/chrome/browser/chromeos/drive/drive_url_request_job.cc b/chrome/browser/chromeos/fileapi/external_file_url_request_job.cc
similarity index 76%
rename from chrome/browser/chromeos/drive/drive_url_request_job.cc
rename to chrome/browser/chromeos/fileapi/external_file_url_request_job.cc
index e615deda09ae6bae4e64e7f30265937a5d14a2e6..19f56a7ccbaa0959a193d2206c914f966267a043 100644
--- a/chrome/browser/chromeos/drive/drive_url_request_job.cc
+++ b/chrome/browser/chromeos/fileapi/external_file_url_request_job.cc
@@ -1,8 +1,8 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/chromeos/drive/drive_url_request_job.h"
+#include "chrome/browser/chromeos/fileapi/external_file_url_request_job.h"
#include <algorithm>
#include <string>
@@ -13,6 +13,7 @@
#include "base/memory/ref_counted.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
+#include "chrome/browser/chromeos/fileapi/external_file_url_util.h"
#include "chrome/browser/extensions/api/file_handlers/mime_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/url_constants.h"
@@ -31,7 +32,7 @@
using content::BrowserThread;
-namespace drive {
+namespace chromeos {
namespace {
struct MimeTypeReplacement {
@@ -40,18 +41,20 @@ struct MimeTypeReplacement {
};
const MimeTypeReplacement kMimeTypeReplacements[] = {
- {"message/rfc822", "multipart/related"} // Fixes MHTML
+ {"message/rfc822", "multipart/related"} // Fixes MHTML
};
// Check if the |url| points a valid location or not.
bool IsValidURL(const storage::FileSystemURL& url) {
switch (url.type()) {
case storage::kFileSystemTypeDrive: {
- const base::FilePath my_drive_path = util::GetDriveMyDriveRootPath();
+ const base::FilePath my_drive_path =
+ drive::util::GetDriveMyDriveRootPath();
const base::FilePath drive_other_path =
- util::GetDriveGrandRootPath().Append(util::kDriveOtherDirName);
+ drive::util::GetDriveGrandRootPath().Append(
+ drive::util::kDriveOtherDirName);
const base::FilePath url_drive_path =
- util::ExtractDrivePathFromFileSystemUrl(url);
+ drive::util::ExtractDrivePathFromFileSystemUrl(url);
return my_drive_path == url_drive_path ||
my_drive_path.IsParent(url_drive_path) ||
drive_other_path.IsParent(url_drive_path);
@@ -68,7 +71,7 @@ class GetFileSystemContextDelegate {
GetFileSystemContextDelegate(
void* profile_id,
const GURL& url,
- const DriveURLRequestJob::DelegateCallback& callback)
+ const ExternalFileURLRequestJob::DelegateCallback& callback)
: profile_id_(profile_id), url_(url), callback_(callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
BrowserThread::PostTask(
@@ -97,7 +100,7 @@ class GetFileSystemContextDelegate {
// Obtain the absolute path in the file system.
base::FilePath path = drive::util::GetDriveMountPointPath(profile);
drive::util::GetDriveGrandRootPath().AppendRelativePath(
- util::DriveURLToFilePath(url_), &path);
+ ExternalFileURLToFilePath(url_), &path);
storage::ExternalFileSystemBackend* const backend =
context->external_backend();
@@ -112,9 +115,10 @@ class GetFileSystemContextDelegate {
// Obtain the file system URL.
// TODO(hirono): After removing MHTML support, stop to use the special
+
// drive: scheme and use filesystem: URL directly. crbug.com/415455
file_system_url_ = context->CreateCrackedFileSystemURL(
- GURL(std::string(chrome::kDriveScheme) + ":"),
+ GURL(std::string(chrome::kExternalFileScheme) + ":"),
storage::kFileSystemTypeExternal,
virtual_path);
if (!IsValidURL(file_system_url_)) {
@@ -146,20 +150,19 @@ class GetFileSystemContextDelegate {
void ReplyResult(net::Error error) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- BrowserThread::PostTask(
- BrowserThread::IO,
- FROM_HERE,
- base::Bind(callback_,
- error,
- file_system_context_,
- file_system_url_,
- mime_type_));
+ BrowserThread::PostTask(BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(callback_,
+ error,
+ file_system_context_,
+ file_system_url_,
+ mime_type_));
delete this;
}
void* const profile_id_;
const GURL url_;
- const DriveURLRequestJob::DelegateCallback callback_;
+ const ExternalFileURLRequestJob::DelegateCallback callback_;
scoped_refptr<storage::FileSystemContext> file_system_context_;
storage::FileSystemURL file_system_url_;
std::string mime_type_;
@@ -169,16 +172,17 @@ class GetFileSystemContextDelegate {
} // namespace
-DriveURLRequestJob::DriveURLRequestJob(void* profile_id,
- net::URLRequest* request,
- net::NetworkDelegate* network_delegate)
+ExternalFileURLRequestJob::ExternalFileURLRequestJob(
+ void* profile_id,
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate)
: net::URLRequestJob(request, network_delegate),
profile_id_(profile_id),
remaining_bytes_(0),
weak_ptr_factory_(this) {
}
-void DriveURLRequestJob::SetExtraRequestHeaders(
+void ExternalFileURLRequestJob::SetExtraRequestHeaders(
const net::HttpRequestHeaders& headers) {
std::string range_header;
if (headers.GetHeader(net::HttpRequestHeaders::kRange, &range_header)) {
@@ -189,29 +193,28 @@ void DriveURLRequestJob::SetExtraRequestHeaders(
byte_range_ = ranges[0];
} else {
// Failed to parse Range: header, so notify the error.
- NotifyDone(
- net::URLRequestStatus(net::URLRequestStatus::FAILED,
- net::ERR_REQUEST_RANGE_NOT_SATISFIABLE));
+ NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED,
+ net::ERR_REQUEST_RANGE_NOT_SATISFIABLE));
}
}
}
-void DriveURLRequestJob::Start() {
+void ExternalFileURLRequestJob::Start() {
DVLOG(1) << "Starting request";
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(!stream_reader_);
// We only support GET request.
if (request()->method() != "GET") {
- LOG(WARNING) << "Failed to start request: "
- << request()->method() << " method is not supported";
+ LOG(WARNING) << "Failed to start request: " << request()->method()
+ << " method is not supported";
NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
net::ERR_METHOD_NOT_SUPPORTED));
return;
}
// Check if the scheme is correct.
- if (!request()->url().SchemeIs(chrome::kDriveScheme)) {
+ if (!request()->url().SchemeIs(chrome::kExternalFileScheme)) {
NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
net::ERR_INVALID_URL));
return;
@@ -221,11 +224,11 @@ void DriveURLRequestJob::Start() {
new GetFileSystemContextDelegate(
profile_id_,
request()->url(),
- base::Bind(&DriveURLRequestJob::OnDelegateResultObtained,
+ base::Bind(&ExternalFileURLRequestJob::OnDelegateResultObtained,
weak_ptr_factory_.GetWeakPtr()));
}
-void DriveURLRequestJob::OnDelegateResultObtained(
+void ExternalFileURLRequestJob::OnDelegateResultObtained(
net::Error error,
const scoped_refptr<storage::FileSystemContext>& file_system_context,
const storage::FileSystemURL& file_system_url,
@@ -233,8 +236,8 @@ void DriveURLRequestJob::OnDelegateResultObtained(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (error != net::OK) {
- NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
- error));
+ NotifyStartError(
+ net::URLRequestStatus(net::URLRequestStatus::FAILED, error));
return;
}
@@ -246,11 +249,12 @@ void DriveURLRequestJob::OnDelegateResultObtained(
// Check if the entry has a redirect URL.
file_system_context_->external_backend()->GetRedirectURLForContents(
file_system_url_,
- base::Bind(&DriveURLRequestJob::OnRedirectURLObtained,
+ base::Bind(&ExternalFileURLRequestJob::OnRedirectURLObtained,
weak_ptr_factory_.GetWeakPtr()));
}
-void DriveURLRequestJob::OnRedirectURLObtained(const GURL& redirect_url) {
+void ExternalFileURLRequestJob::OnRedirectURLObtained(
+ const GURL& redirect_url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
redirect_url_ = redirect_url;
if (!redirect_url_.is_empty()) {
@@ -261,12 +265,13 @@ void DriveURLRequestJob::OnRedirectURLObtained(const GURL& redirect_url) {
// Obtain file system context.
file_system_context_->operation_runner()->GetMetadata(
file_system_url_,
- base::Bind(&DriveURLRequestJob::OnFileInfoObtained,
+ base::Bind(&ExternalFileURLRequestJob::OnFileInfoObtained,
weak_ptr_factory_.GetWeakPtr()));
}
-void DriveURLRequestJob::OnFileInfoObtained(base::File::Error result,
- const base::File::Info& file_info) {
+void ExternalFileURLRequestJob::OnFileInfoObtained(
+ base::File::Error result,
+ const base::File::Info& file_info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (result == base::File::FILE_ERROR_NOT_FOUND) {
@@ -304,7 +309,7 @@ void DriveURLRequestJob::OnFileInfoObtained(base::File::Error result,
NotifyHeadersComplete();
}
-void DriveURLRequestJob::Kill() {
+void ExternalFileURLRequestJob::Kill() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
stream_reader_.reset();
@@ -313,14 +318,14 @@ void DriveURLRequestJob::Kill() {
weak_ptr_factory_.InvalidateWeakPtrs();
}
-bool DriveURLRequestJob::GetMimeType(std::string* mime_type) const {
+bool ExternalFileURLRequestJob::GetMimeType(std::string* mime_type) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
mime_type->assign(mime_type_);
return !mime_type->empty();
}
-bool DriveURLRequestJob::IsRedirectResponse(
- GURL* location, int* http_status_code) {
+bool ExternalFileURLRequestJob::IsRedirectResponse(GURL* location,
+ int* http_status_code) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (redirect_url_.is_empty())
return false;
@@ -332,8 +337,9 @@ bool DriveURLRequestJob::IsRedirectResponse(
return true;
}
-bool DriveURLRequestJob::ReadRawData(
- net::IOBuffer* buf, int buf_size, int* bytes_read) {
+bool ExternalFileURLRequestJob::ReadRawData(net::IOBuffer* buf,
+ int buf_size,
+ int* bytes_read) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(stream_reader_);
@@ -345,7 +351,7 @@ bool DriveURLRequestJob::ReadRawData(
const int result = stream_reader_->Read(
buf,
std::min(static_cast<int64>(buf_size), remaining_bytes_),
- base::Bind(&DriveURLRequestJob::OnReadCompleted,
+ base::Bind(&ExternalFileURLRequestJob::OnReadCompleted,
weak_ptr_factory_.GetWeakPtr()));
if (result == net::ERR_IO_PENDING) {
@@ -365,16 +371,16 @@ bool DriveURLRequestJob::ReadRawData(
return true;
}
-DriveURLRequestJob::~DriveURLRequestJob() {
+ExternalFileURLRequestJob::~ExternalFileURLRequestJob() {
}
-void DriveURLRequestJob::OnReadCompleted(int read_result) {
+void ExternalFileURLRequestJob::OnReadCompleted(int read_result) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (read_result < 0) {
DCHECK_NE(read_result, net::ERR_IO_PENDING);
- NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED,
- read_result));
+ NotifyDone(
+ net::URLRequestStatus(net::URLRequestStatus::FAILED, read_result));
}
remaining_bytes_ -= read_result;
@@ -382,4 +388,4 @@ void DriveURLRequestJob::OnReadCompleted(int read_result) {
NotifyReadComplete(read_result);
}
-} // namespace drive
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698