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

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

Issue 11785018: drive: Add Profile* as a member of DriveProtocolHandler. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add IsValidProfile check in DriveProtocolHandler. Created 7 years, 11 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_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..f8161cbfc55f7fa30657345519d97eb7705ec3c2 100644
--- a/chrome/browser/chromeos/drive/drive_protocol_handler.cc
+++ b/chrome/browser/chromeos/drive/drive_protocol_handler.cc
@@ -23,8 +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"
#include "net/base/escape.h"
@@ -92,20 +90,28 @@ bool ParseDriveUrl(const std::string& path, std::string* resource_id) {
}
// Helper function to get DriveSystemService from Profile.
-DriveSystemService* GetSystemService() {
- return DriveSystemServiceFactory::GetForProfile(
- ProfileManager::GetDefaultProfile());
+DriveSystemService* GetSystemService(Profile* profile) {
hashimoto 2013/01/07 08:22:51 How about moving the IsValidProfile check to this
Haruki Sato 2013/01/07 08:54:49 Good catch! Thanks! Done.
+ return DriveSystemServiceFactory::GetForProfile(profile);
}
// Helper function to get DriveFileSystem from Profile on UI thread.
-DriveFileSystemInterface* GetFileSystemOnUIThread() {
- DriveSystemService* system_service = GetSystemService();
+DriveFileSystemInterface* GetFileSystemOnUIThread(void* profile_id) {
+ Profile* profile = reinterpret_cast<Profile*>(profile_id);
+ if (!g_browser_process->profile_manager()->IsValidProfile(profile))
+ return NULL;
+
+ 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(
+ void* profile_id, const FilePath& drive_file_path) {
+ Profile* profile = reinterpret_cast<Profile*>(profile_id);
+ if (!g_browser_process->profile_manager()->IsValidProfile(profile))
+ return;
+
+ DriveSystemService* system_service = GetSystemService(profile);
if (system_service)
system_service->drive_service()->CancelForFilePath(drive_file_path);
}
@@ -115,7 +121,8 @@ void CancelDriveDownloadOnUIThread(const FilePath& drive_file_path) {
// formatted as drive://<resource-id>.
class DriveURLRequestJob : public net::URLRequestJob {
public:
- DriveURLRequestJob(net::URLRequest* request,
+ DriveURLRequestJob(void* profile_id,
+ net::URLRequest* request,
net::NetworkDelegate* network_delegate);
// net::URLRequestJob overrides:
@@ -188,6 +195,9 @@ class DriveURLRequestJob : public net::URLRequestJob {
// Helper method to close |stream_|.
void CloseFileStream();
+ // The profile for processing Drive accesses. Should not be NULL and needs to
+ // be checked with ProfileManager::IsValidProfile before using it.
+ void* profile_id_;
DriveFileSystemInterface* file_system_;
bool error_; // True if we've encountered an error.
@@ -211,9 +221,11 @@ class DriveURLRequestJob : public net::URLRequestJob {
DISALLOW_COPY_AND_ASSIGN(DriveURLRequestJob);
};
-DriveURLRequestJob::DriveURLRequestJob(net::URLRequest* request,
+DriveURLRequestJob::DriveURLRequestJob(void* profile_id,
+ net::URLRequest* request,
net::NetworkDelegate* network_delegate)
: net::URLRequestJob(request, network_delegate),
+ profile_id_(profile_id),
file_system_(NULL),
error_(false),
headers_set_(false),
@@ -292,7 +304,7 @@ void DriveURLRequestJob::Start() {
BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::UI,
FROM_HERE,
- base::Bind(&GetFileSystemOnUIThread),
+ base::Bind(&GetFileSystemOnUIThread, profile_id_),
base::Bind(&DriveURLRequestJob::StartAsync,
weak_ptr_factory_.GetWeakPtr()));
}
@@ -321,6 +333,7 @@ void DriveURLRequestJob::Kill() {
BrowserThread::UI,
FROM_HERE,
base::Bind(&CancelDriveDownloadOnUIThread,
+ profile_id_,
drive_file_path_));
}
@@ -909,7 +922,8 @@ void DriveURLRequestJob::HeadersCompleted(int status_code,
///////////////////////////////////////////////////////////////////////////////
// DriveProtocolHandler class
-DriveProtocolHandler::DriveProtocolHandler() {
+DriveProtocolHandler::DriveProtocolHandler(void* profile_id)
+ : profile_id_(profile_id) {
}
DriveProtocolHandler::~DriveProtocolHandler() {
@@ -918,7 +932,7 @@ 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_id_, request, network_delegate);
}
} // namespace drive

Powered by Google App Engine
This is Rietveld 408576698