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

Unified Diff: chrome/browser/chromeos/drive/drive_url_request_job.cc

Issue 13401003: chromeos: Replace resource ID in drive URL with path (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: _ Created 7 years, 9 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/drive/drive_url_request_job.cc
diff --git a/chrome/browser/chromeos/drive/drive_url_request_job.cc b/chrome/browser/chromeos/drive/drive_url_request_job.cc
index 6e34cf2fbf85a6030a11e6e36f3a3c23eda82182..5f3b96b1498e7d84142ea9fb9153537d3f32a32e 100644
--- a/chrome/browser/chromeos/drive/drive_url_request_job.cc
+++ b/chrome/browser/chromeos/drive/drive_url_request_job.cc
@@ -69,20 +69,6 @@ std::string FixupMimeType(const std::string& type) {
return type;
}
-// Helper function that extracts and unescapes resource_id from drive urls
-// (drive:<resource_id>).
-bool ParseDriveUrl(const std::string& path, std::string* resource_id) {
- const std::string drive_schema(chrome::kDriveScheme + std::string(":"));
- if (!StartsWithASCII(path, drive_schema, false) ||
- path.size() <= drive_schema.size()) {
- return false;
- }
-
- std::string id = path.substr(drive_schema.size());
- *resource_id = net::UnescapeURLComponent(id, kUrlPathUnescapeMask);
- return resource_id->size();
-}
-
// Helper function to cancel Drive download operation on UI thread.
void CancelDriveDownloadOnUIThread(
const DriveURLRequestJob::DriveFileSystemGetter& file_system_getter,
@@ -109,39 +95,37 @@ void CancelDriveDownload(
file_system_getter, drive_file_path));
}
-// Helper function to call DriveFileSystem::GetEntryInfoByResourceId.
-void GetEntryInfoByResourceIdOnUIThread(
+// Helper function to call DriveFileSystem::GetEntryInfoByPath.
+void GetEntryInfoByPathOnUIThread(
const DriveURLRequestJob::DriveFileSystemGetter& file_system_getter,
- const std::string& resource_id,
- const drive::GetEntryInfoWithFilePathCallback& callback) {
+ const base::FilePath& path,
+ const drive::GetEntryInfoCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DriveFileSystemInterface* file_system = file_system_getter.Run();
if (!file_system) {
- callback.Run(DRIVE_FILE_ERROR_FAILED,
- base::FilePath(),
- scoped_ptr<DriveEntryProto>());
+ callback.Run(DRIVE_FILE_ERROR_FAILED, scoped_ptr<DriveEntryProto>());
return;
}
- file_system->GetEntryInfoByResourceId(resource_id, callback);
+ file_system->GetEntryInfoByPath(path, callback);
}
-// Returns the entry info for the |resource_id| on DriveFileSystem returned by
+// Returns the entry info for the |path| on DriveFileSystem returned by
// |file_system_getter| via |callback|.
// The main task will be done on UI thread, but this method itself is designed
// to be run on IO thread. Also the |callback| will be run on IO thread, too.
-void GetEntryInfoByResourceId(
+void GetEntryInfoByPath(
const DriveURLRequestJob::DriveFileSystemGetter& file_system_getter,
- const std::string& resource_id,
- const drive::GetEntryInfoWithFilePathCallback& callback) {
+ const base::FilePath& path,
+ const drive::GetEntryInfoCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
- base::Bind(&GetEntryInfoByResourceIdOnUIThread,
+ base::Bind(&GetEntryInfoByPathOnUIThread,
file_system_getter,
- resource_id,
+ path,
google_apis::CreateRelayCallback(callback)));
}
@@ -262,19 +246,10 @@ void DriveURLRequestJob::Start() {
net::ERR_METHOD_NOT_SUPPORTED));
return;
}
-
- std::string resource_id;
- if (!ParseDriveUrl(request_->url().spec(), &resource_id)) {
- NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
- net::ERR_INVALID_URL));
- return;
- }
-
- GetEntryInfoByResourceId(
- file_system_getter_,
- resource_id,
- base::Bind(&DriveURLRequestJob::OnGetEntryInfoByResourceId,
- weak_ptr_factory_.GetWeakPtr(), resource_id));
+ GetEntryInfoByPath(file_system_getter_,
+ base::FilePath::FromUTF8Unsafe(request_->url().path()),
+ base::Bind(&DriveURLRequestJob::OnGetEntryInfoByPath,
+ weak_ptr_factory_.GetWeakPtr()));
}
void DriveURLRequestJob::Kill() {
@@ -435,32 +410,32 @@ DriveURLRequestJob::~DriveURLRequestJob() {
//======================= DriveURLRequestJob private methods ===================
-void DriveURLRequestJob::OnGetEntryInfoByResourceId(
- const std::string& resource_id,
+void DriveURLRequestJob::OnGetEntryInfoByPath(
DriveFileError error,
- const base::FilePath& drive_file_path,
scoped_ptr<DriveEntryProto> entry_proto) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (entry_proto.get() && !entry_proto->has_file_specific_info())
error = DRIVE_FILE_ERROR_NOT_FOUND;
- if (error == DRIVE_FILE_OK) {
- DCHECK(entry_proto.get());
- mime_type_ = entry_proto->file_specific_info().content_mime_type();
- drive_file_path_ = drive_file_path;
- initial_file_size_ = entry_proto->file_info().size();
- } else {
+ if (error != DRIVE_FILE_OK) {
mime_type_.clear();
drive_file_path_.clear();
initial_file_size_ = 0;
+ NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
+ net::ERR_FILE_NOT_FOUND));
+ return;
}
+ DCHECK(entry_proto.get());
+ mime_type_ = entry_proto->file_specific_info().content_mime_type();
+ drive_file_path_ = base::FilePath::FromUTF8Unsafe(request_->url().path());
+ initial_file_size_ = entry_proto->file_info().size();
remaining_bytes_ = initial_file_size_;
DVLOG(1) << "Getting file for resource id";
GetFileByResourceId(
file_system_getter_,
- resource_id,
+ entry_proto->resource_id(),
base::Bind(&DriveURLRequestJob::OnGetFileByResourceId,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&DriveURLRequestJob::OnUrlFetchDownloadData,

Powered by Google App Engine
This is Rietveld 408576698