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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_protocol_handler.cc

Issue 10538071: gdata: Convert FindEntryByResourceIdSync() to asynchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix spelling error of 'completion' and a few unnecessary newlines. Created 8 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chromeos/gdata/gdata_protocol_handler.h" 5 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // GDataFileSystem::GetFileByResourceId(). 142 // GDataFileSystem::GetFileByResourceId().
143 void OnGetFileByResourceId(base::PlatformFileError error, 143 void OnGetFileByResourceId(base::PlatformFileError error,
144 const FilePath& local_file_path, 144 const FilePath& local_file_path,
145 const std::string& mime_type, 145 const std::string& mime_type,
146 GDataFileType file_type); 146 GDataFileType file_type);
147 147
148 // Helper callback for GetFileSizeOnBlockingPool that sets |remaining_bytes_| 148 // Helper callback for GetFileSizeOnBlockingPool that sets |remaining_bytes_|
149 // to |file_size|, and notifies result for Start(). 149 // to |file_size|, and notifies result for Start().
150 void OnGetFileSize(int64 *file_size); 150 void OnGetFileSize(int64 *file_size);
151 151
152 // Helper callback for FindEntryByResourceId invoked by StartAsync.
153 void OnFindEntryByResourceId(const std::string& resource_id,
154 base::PlatformFileError error,
155 GDataEntry* entry);
156
152 // Helper methods for ReadRawData to open file and read from its corresponding 157 // Helper methods for ReadRawData to open file and read from its corresponding
153 // stream in a streaming fashion. 158 // stream in a streaming fashion.
154 bool ContinueReadFromFile(int* bytes_read); 159 bool ContinueReadFromFile(int* bytes_read);
155 void ReadFromFile(); 160 void ReadFromFile();
156 void ReadFileStream(int bytes_to_read); 161 void ReadFileStream(int bytes_to_read);
157 162
158 // Helper callback for handling async responses from FileStream::Open(). 163 // Helper callback for handling async responses from FileStream::Open().
159 void OnFileOpen(int bytes_to_read, int open_result); 164 void OnFileOpen(int bytes_to_read, int open_result);
160 165
161 // Helper callback for handling async responses from FileStream::Read(). 166 // Helper callback for handling async responses from FileStream::Read().
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 base::Bind(&CancelGDataDownloadOnUIThread, 318 base::Bind(&CancelGDataDownloadOnUIThread,
314 gdata_file_path_)); 319 gdata_file_path_));
315 } 320 }
316 321
317 net::URLRequestJob::Kill(); 322 net::URLRequestJob::Kill();
318 weak_ptr_factory_->InvalidateWeakPtrs(); 323 weak_ptr_factory_->InvalidateWeakPtrs();
319 } 324 }
320 325
321 bool GDataURLRequestJob::GetMimeType(std::string* mime_type) const { 326 bool GDataURLRequestJob::GetMimeType(std::string* mime_type) const {
322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
323 328 mime_type->assign(mime_type_);
324 if (!file_system_)
325 return false;
326
327 std::string resource_id;
328 std::string unused_file_name;
329 if (!ParseDriveUrl(request_->url().spec(), &resource_id)) {
330 return false;
331 }
332
333 GDataEntry* entry = NULL;
334 file_system_->FindEntryByResourceIdSync(
335 resource_id, base::Bind(&ReadOnlyFindEntryCallback, &entry));
336 if (!entry || !entry->AsGDataFile())
337 return false;
338 mime_type->assign(entry->AsGDataFile()->content_mime_type());
339 return !mime_type->empty(); 329 return !mime_type->empty();
340 } 330 }
341 331
342 void GDataURLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) { 332 void GDataURLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) {
343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
344 if (response_info_.get()) 334 if (response_info_.get())
345 *info = *response_info_; 335 *info = *response_info_;
346 } 336 }
347 337
348 int GDataURLRequestJob::GetResponseCode() const { 338 int GDataURLRequestJob::GetResponseCode() const {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 return; 467 return;
478 } 468 }
479 469
480 std::string resource_id; 470 std::string resource_id;
481 if (!ParseDriveUrl(request_->url().spec(), &resource_id)) { 471 if (!ParseDriveUrl(request_->url().spec(), &resource_id)) {
482 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, 472 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
483 net::ERR_INVALID_URL)); 473 net::ERR_INVALID_URL));
484 return; 474 return;
485 } 475 }
486 476
487 // First, check if file metadata is matching our expectations. 477 file_system_->FindEntryByResourceId(
488 GDataEntry* entry = NULL; 478 resource_id,
489 file_system_->FindEntryByResourceIdSync( 479 base::Bind(&GDataURLRequestJob::OnFindEntryByResourceId,
490 resource_id, base::Bind(&ReadOnlyFindEntryCallback, &entry)); 480 weak_ptr_factory_->GetWeakPtr(),
491 if (entry && entry->AsGDataFile()) { 481 resource_id));
482 }
483
484 void GDataURLRequestJob::OnFindEntryByResourceId(
485 const std::string& resource_id,
486 base::PlatformFileError error,
487 GDataEntry* entry) {
488 if (error == base::PLATFORM_FILE_OK && entry && entry->AsGDataFile()) {
achuithb 2012/06/11 21:48:41 So this is on the UI thread now? Is it safe for me
hshi1 2012/06/11 22:42:21 No, this callback is run on the caller thread. See
492 mime_type_ = entry->AsGDataFile()->content_mime_type(); 489 mime_type_ = entry->AsGDataFile()->content_mime_type();
493 gdata_file_path_ = entry->GetFilePath(); 490 gdata_file_path_ = entry->GetFilePath();
494 initial_file_size_ = entry->file_info().size; 491 initial_file_size_ = entry->file_info().size;
495 } else { 492 } else {
496 mime_type_.clear(); 493 mime_type_.clear();
497 gdata_file_path_.clear(); 494 gdata_file_path_.clear();
498 initial_file_size_ = 0; 495 initial_file_size_ = 0;
499 } 496 }
500 remaining_bytes_ = initial_file_size_; 497 remaining_bytes_ = initial_file_size_;
501 498
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 GDataProtocolHandler::~GDataProtocolHandler() { 903 GDataProtocolHandler::~GDataProtocolHandler() {
907 } 904 }
908 905
909 net::URLRequestJob* GDataProtocolHandler::MaybeCreateJob( 906 net::URLRequestJob* GDataProtocolHandler::MaybeCreateJob(
910 net::URLRequest* request) const { 907 net::URLRequest* request) const {
911 DVLOG(1) << "Handling url: " << request->url().spec(); 908 DVLOG(1) << "Handling url: " << request->url().spec();
912 return new GDataURLRequestJob(request); 909 return new GDataURLRequestJob(request);
913 } 910 }
914 911
915 } // namespace gdata 912 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698