Chromium Code Reviews| Index: chrome/browser/chromeos/drive/drive_protocol_handler.cc |
| diff --git a/chrome/browser/chromeos/drive/drive_protocol_handler.cc b/chrome/browser/chromeos/drive/drive_protocol_handler.cc |
| index be7a67ff950f6f38022692f42f3a6b3154a2a363..1dbe09d4490348dbef32da92b274c07e46679131 100644 |
| --- a/chrome/browser/chromeos/drive/drive_protocol_handler.cc |
| +++ b/chrome/browser/chromeos/drive/drive_protocol_handler.cc |
| @@ -23,7 +23,6 @@ |
| #include "chrome/browser/google_apis/drive_service_interface.h" |
| #include "chrome/browser/google_apis/gdata_errorcode.h" |
| #include "chrome/browser/google_apis/time_util.h" |
| -#include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/common/url_constants.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -92,20 +91,21 @@ bool ParseDriveUrl(const std::string& path, std::string* resource_id) { |
| } |
| // Helper function to get DriveSystemService from Profile. |
| -DriveSystemService* GetSystemService() { |
| +DriveSystemService* GetSystemService(Profile* profile) { |
| return DriveSystemServiceFactory::GetForProfile( |
| - ProfileManager::GetDefaultProfile()); |
| + profile ? profile : ProfileManager::GetDefaultProfile()); |
| } |
| // Helper function to get DriveFileSystem from Profile on UI thread. |
| -DriveFileSystemInterface* GetFileSystemOnUIThread() { |
| - DriveSystemService* system_service = GetSystemService(); |
| +DriveFileSystemInterface* GetFileSystemOnUIThread(Profile* profile) { |
| + DriveSystemService* system_service = GetSystemService(profile); |
| return system_service ? system_service->file_system() : NULL; |
| } |
| // Helper function to cancel Drive download operation on UI thread. |
| -void CancelDriveDownloadOnUIThread(const FilePath& drive_file_path) { |
| - DriveSystemService* system_service = GetSystemService(); |
| +void CancelDriveDownloadOnUIThread( |
| + Profile* profile, const FilePath& drive_file_path) { |
| + DriveSystemService* system_service = GetSystemService(profile); |
| if (system_service) |
| system_service->drive_service()->CancelForFilePath(drive_file_path); |
| } |
| @@ -115,7 +115,8 @@ void CancelDriveDownloadOnUIThread(const FilePath& drive_file_path) { |
| // formatted as drive://<resource-id>. |
| class DriveURLRequestJob : public net::URLRequestJob { |
| public: |
| - DriveURLRequestJob(net::URLRequest* request, |
| + DriveURLRequestJob(Profile* profile, |
| + net::URLRequest* request, |
| net::NetworkDelegate* network_delegate); |
| // net::URLRequestJob overrides: |
| @@ -188,6 +189,9 @@ class DriveURLRequestJob : public net::URLRequestJob { |
| // Helper method to close |stream_|. |
| void CloseFileStream(); |
| + // If |profile_| is NULL, the profile from ProfileManager::GetDefaultProfile() |
| + // will be used. |
| + Profile* profile_; |
| DriveFileSystemInterface* file_system_; |
| bool error_; // True if we've encountered an error. |
| @@ -211,9 +215,11 @@ class DriveURLRequestJob : public net::URLRequestJob { |
| DISALLOW_COPY_AND_ASSIGN(DriveURLRequestJob); |
| }; |
| -DriveURLRequestJob::DriveURLRequestJob(net::URLRequest* request, |
| +DriveURLRequestJob::DriveURLRequestJob(Profile* profile, |
| + net::URLRequest* request, |
| net::NetworkDelegate* network_delegate) |
| : net::URLRequestJob(request, network_delegate), |
| + profile_(profile), |
| file_system_(NULL), |
| error_(false), |
| headers_set_(false), |
| @@ -292,7 +298,7 @@ void DriveURLRequestJob::Start() { |
| BrowserThread::PostTaskAndReplyWithResult( |
| BrowserThread::UI, |
| FROM_HERE, |
| - base::Bind(&GetFileSystemOnUIThread), |
| + base::Bind(&GetFileSystemOnUIThread, profile_), |
| base::Bind(&DriveURLRequestJob::StartAsync, |
| weak_ptr_factory_.GetWeakPtr())); |
| } |
| @@ -321,6 +327,7 @@ void DriveURLRequestJob::Kill() { |
| BrowserThread::UI, |
| FROM_HERE, |
| base::Bind(&CancelDriveDownloadOnUIThread, |
| + profile_, |
| drive_file_path_)); |
| } |
| @@ -909,7 +916,12 @@ void DriveURLRequestJob::HeadersCompleted(int status_code, |
| /////////////////////////////////////////////////////////////////////////////// |
| // DriveProtocolHandler class |
| -DriveProtocolHandler::DriveProtocolHandler() { |
| +DriveProtocolHandler::DriveProtocolHandler() |
|
hashimoto
2013/01/07 05:18:45
How about initializing DriveProtocolHandler with P
Haruki Sato
2013/01/07 06:24:42
Done.
|
| + : profile_(NULL) { |
| +} |
| + |
| +DriveProtocolHandler::DriveProtocolHandler(Profile* profile) |
| + : profile_(profile) { |
| } |
| DriveProtocolHandler::~DriveProtocolHandler() { |
| @@ -918,7 +930,10 @@ DriveProtocolHandler::~DriveProtocolHandler() { |
| net::URLRequestJob* DriveProtocolHandler::MaybeCreateJob( |
| net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
| DVLOG(1) << "Handling url: " << request->url().spec(); |
| - return new DriveURLRequestJob(request, network_delegate); |
| + return new DriveURLRequestJob( |
| + profile_, |
| + request, |
| + network_delegate); |
| } |
| } // namespace drive |