summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-02 10:41:02 +0000
committerkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-02 10:41:02 +0000
commit7b8ec00b230223fea12d2009b5530975cc4d9fde (patch)
tree7b39f261cab1669c365417496efe8cc2b3c1c4a6
parent3f05803ebce3d202fa7bac2af49d26f5ad89f22e (diff)
downloadchromium_src-7b8ec00b230223fea12d2009b5530975cc4d9fde.zip
chromium_src-7b8ec00b230223fea12d2009b5530975cc4d9fde.tar.gz
chromium_src-7b8ec00b230223fea12d2009b5530975cc4d9fde.tar.bz2
Make TaskRunner injectable in {GDataWapi,DriveAPI}Service.
The purposes of this patch are twofold: * These task runners are planned to be passed to lower layers in order to remove dependency to content::BrowserThread in c/b/google_apis. (Hence I'm adding the change to GDataWapiService which itself not using blocking pool.) * It will enable finer-grained control over threads in tests. BUG=256112 Review URL: https://chromiumcodereview.appspot.com/18150004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209663 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/drive/drive_integration_service.cc2
-rw-r--r--chrome/browser/drive/drive_api_service.cc31
-rw-r--r--chrome/browser/drive/drive_api_service.h5
-rw-r--r--chrome/browser/drive/gdata_wapi_service.cc2
-rw-r--r--chrome/browser/drive/gdata_wapi_service.h5
-rw-r--r--chrome/browser/sync_file_system/drive_backend/api_util.cc2
6 files changed, 38 insertions, 9 deletions
diff --git a/chrome/browser/chromeos/drive/drive_integration_service.cc b/chrome/browser/chromeos/drive/drive_integration_service.cc
index 4cf28a4..7978b72 100644
--- a/chrome/browser/chromeos/drive/drive_integration_service.cc
+++ b/chrome/browser/chromeos/drive/drive_integration_service.cc
@@ -157,12 +157,14 @@ DriveIntegrationService::DriveIntegrationService(
} else if (util::IsDriveV2ApiEnabled()) {
drive_service_.reset(new DriveAPIService(
g_browser_process->system_request_context(),
+ blocking_task_runner_,
GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction),
GURL(google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction),
GetDriveUserAgent()));
} else {
drive_service_.reset(new GDataWapiService(
g_browser_process->system_request_context(),
+ blocking_task_runner_,
GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction),
GURL(google_apis::GDataWapiUrlGenerator::kBaseDownloadUrlForProduction),
GetDriveUserAgent()));
diff --git a/chrome/browser/drive/drive_api_service.cc b/chrome/browser/drive/drive_api_service.cc
index eceac4d..b061366 100644
--- a/chrome/browser/drive/drive_api_service.cc
+++ b/chrome/browser/drive/drive_api_service.cc
@@ -8,10 +8,8 @@
#include <vector>
#include "base/bind.h"
-#include "base/message_loop/message_loop_proxy.h"
#include "base/strings/stringprintf.h"
#include "base/task_runner_util.h"
-#include "base/threading/sequenced_worker_pool.h"
#include "base/values.h"
#include "chrome/browser/drive/drive_api_util.h"
#include "chrome/browser/google_apis/auth_service.h"
@@ -131,6 +129,7 @@ void DidParseResourceListOnBlockingPool(
// Sends a task to parse the JSON value into ResourceList on blocking pool,
// with a callback which is called when the task is done.
void ParseResourceListOnBlockingPoolAndRun(
+ scoped_refptr<base::TaskRunner> blocking_task_runner,
const GetResourceListCallback& callback,
GDataErrorCode error,
scoped_ptr<base::Value> value) {
@@ -144,7 +143,7 @@ void ParseResourceListOnBlockingPoolAndRun(
}
PostTaskAndReplyWithResult(
- BrowserThread::GetBlockingPool(),
+ blocking_task_runner.get(),
FROM_HERE,
base::Bind(&ParseResourceListOnBlockingPool, base::Passed(&value)),
base::Bind(&DidParseResourceListOnBlockingPool, callback));
@@ -261,10 +260,12 @@ const char kDriveApiRootDirectoryResourceId[] = "root";
DriveAPIService::DriveAPIService(
net::URLRequestContextGetter* url_request_context_getter,
+ base::TaskRunner* blocking_task_runner,
const GURL& base_url,
const GURL& base_download_url,
const std::string& custom_user_agent)
: url_request_context_getter_(url_request_context_getter),
+ blocking_task_runner_(blocking_task_runner),
profile_(NULL),
url_generator_(base_url, base_download_url),
custom_user_agent_(custom_user_agent) {
@@ -332,7 +333,9 @@ CancelCallback DriveAPIService::GetAllResourceList(
false, // include deleted
0,
kMaxNumFilesResourcePerRequest,
- base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
+ base::Bind(&ParseResourceListOnBlockingPoolAndRun,
+ blocking_task_runner_,
+ callback)));
}
CancelCallback DriveAPIService::GetResourceListInDirectory(
@@ -358,7 +361,9 @@ CancelCallback DriveAPIService::GetResourceListInDirectory(
drive::util::EscapeQueryStringValue(
directory_resource_id).c_str()),
kMaxNumFilesResourcePerRequest,
- base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
+ base::Bind(&ParseResourceListOnBlockingPoolAndRun,
+ blocking_task_runner_,
+ callback)));
}
CancelCallback DriveAPIService::Search(
@@ -374,7 +379,9 @@ CancelCallback DriveAPIService::Search(
url_generator_,
drive::util::TranslateQuery(search_query),
kMaxNumFilesResourcePerRequestForSearch,
- base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
+ base::Bind(&ParseResourceListOnBlockingPoolAndRun,
+ blocking_task_runner_,
+ callback)));
}
CancelCallback DriveAPIService::SearchByTitle(
@@ -401,7 +408,9 @@ CancelCallback DriveAPIService::SearchByTitle(
url_generator_,
query,
kMaxNumFilesResourcePerRequest,
- base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
+ base::Bind(&ParseResourceListOnBlockingPoolAndRun,
+ blocking_task_runner_,
+ callback)));
}
CancelCallback DriveAPIService::GetChangeList(
@@ -417,7 +426,9 @@ CancelCallback DriveAPIService::GetChangeList(
true, // include deleted
start_changestamp,
kMaxNumFilesResourcePerRequest,
- base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
+ base::Bind(&ParseResourceListOnBlockingPoolAndRun,
+ blocking_task_runner_,
+ callback)));
}
CancelCallback DriveAPIService::ContinueGetResourceList(
@@ -430,7 +441,9 @@ CancelCallback DriveAPIService::ContinueGetResourceList(
new ContinueGetFileListRequest(
sender_.get(),
override_url,
- base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
+ base::Bind(&ParseResourceListOnBlockingPoolAndRun,
+ blocking_task_runner_,
+ callback)));
}
CancelCallback DriveAPIService::GetResourceEntry(
diff --git a/chrome/browser/drive/drive_api_service.h b/chrome/browser/drive/drive_api_service.h
index a704359..85a51e8 100644
--- a/chrome/browser/drive/drive_api_service.h
+++ b/chrome/browser/drive/drive_api_service.h
@@ -7,6 +7,7 @@
#include <string>
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "chrome/browser/drive/drive_service_interface.h"
@@ -18,6 +19,7 @@ class Profile;
namespace base {
class FilePath;
+class TaskRunner;
}
namespace google_apis {
@@ -37,6 +39,7 @@ class DriveAPIService : public DriveServiceInterface,
public google_apis::AuthServiceObserver {
public:
// |url_request_context_getter| is used to initialize URLFetcher.
+ // |blocking_task_runner| is used to run blocking tasks (like parsing JSON).
// |base_url| is used to generate URLs for communication with the drive API.
// |base_download_url| is used to generate URLs for downloading file from the
// drive API.
@@ -44,6 +47,7 @@ class DriveAPIService : public DriveServiceInterface,
// requests issues through the service if the value is not empty.
DriveAPIService(
net::URLRequestContextGetter* url_request_context_getter,
+ base::TaskRunner* blocking_task_runner,
const GURL& base_url,
const GURL& base_download_url,
const std::string& custom_user_agent);
@@ -161,6 +165,7 @@ class DriveAPIService : public DriveServiceInterface,
virtual void OnOAuth2RefreshTokenChanged() OVERRIDE;
net::URLRequestContextGetter* url_request_context_getter_;
+ scoped_refptr<base::TaskRunner> blocking_task_runner_;
Profile* profile_;
scoped_ptr<google_apis::RequestSender> sender_;
ObserverList<DriveServiceObserver> observers_;
diff --git a/chrome/browser/drive/gdata_wapi_service.cc b/chrome/browser/drive/gdata_wapi_service.cc
index 7198edb..582a980 100644
--- a/chrome/browser/drive/gdata_wapi_service.cc
+++ b/chrome/browser/drive/gdata_wapi_service.cc
@@ -129,10 +129,12 @@ void ParseAppListAndRun(
GDataWapiService::GDataWapiService(
net::URLRequestContextGetter* url_request_context_getter,
+ base::TaskRunner* blocking_task_runner,
const GURL& base_url,
const GURL& base_download_url,
const std::string& custom_user_agent)
: url_request_context_getter_(url_request_context_getter),
+ blocking_task_runner_(blocking_task_runner),
url_generator_(base_url, base_download_url),
custom_user_agent_(custom_user_agent) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
diff --git a/chrome/browser/drive/gdata_wapi_service.h b/chrome/browser/drive/gdata_wapi_service.h
index 3427601..2baeefc 100644
--- a/chrome/browser/drive/gdata_wapi_service.h
+++ b/chrome/browser/drive/gdata_wapi_service.h
@@ -7,6 +7,7 @@
#include <string>
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
@@ -20,6 +21,7 @@ class Profile;
namespace base {
class FilePath;
+class TaskRunner;
}
namespace google_apis {
@@ -41,11 +43,13 @@ class GDataWapiService : public DriveServiceInterface,
public google_apis::AuthServiceObserver {
public:
// |url_request_context_getter| is used to initialize URLFetcher.
+ // |blocking_task_runner| is used to run blocking tasks (like parsing JSON).
// |base_url| is used to generate URLs for communicating with the WAPI
// |base_download_url| is used to generate URLs for downloading file with WAPI
// |custom_user_agent| is used for the User-Agent header in HTTP
// requests issued through the service if the value is not empty.
GDataWapiService(net::URLRequestContextGetter* url_request_context_getter,
+ base::TaskRunner* blocking_task_runner,
const GURL& base_url,
const GURL& base_download_url,
const std::string& custom_user_agent);
@@ -165,6 +169,7 @@ class GDataWapiService : public DriveServiceInterface,
virtual void OnOAuth2RefreshTokenChanged() OVERRIDE;
net::URLRequestContextGetter* url_request_context_getter_; // Not owned.
+ scoped_refptr<base::TaskRunner> blocking_task_runner_;
scoped_ptr<google_apis::RequestSender> sender_;
ObserverList<DriveServiceObserver> observers_;
// Request objects should hold a copy of this, rather than a const
diff --git a/chrome/browser/sync_file_system/drive_backend/api_util.cc b/chrome/browser/sync_file_system/drive_backend/api_util.cc
index 4fe4783..ea4070f 100644
--- a/chrome/browser/sync_file_system/drive_backend/api_util.cc
+++ b/chrome/browser/sync_file_system/drive_backend/api_util.cc
@@ -152,12 +152,14 @@ APIUtil::APIUtil(Profile* profile)
if (IsDriveAPIDisabled()) {
drive_service_.reset(new drive::GDataWapiService(
profile->GetRequestContext(),
+ content::BrowserThread::GetBlockingPool(),
GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction),
GURL(google_apis::GDataWapiUrlGenerator::kBaseDownloadUrlForProduction),
std::string() /* custom_user_agent */));
} else {
drive_service_.reset(new drive::DriveAPIService(
profile->GetRequestContext(),
+ content::BrowserThread::GetBlockingPool(),
GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction),
GURL(google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction),
std::string() /* custom_user_agent */));