diff options
author | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-21 16:10:38 +0000 |
---|---|---|
committer | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-21 16:10:38 +0000 |
commit | fce8c970259a917e0209d4c12c50f10c5a5d669b (patch) | |
tree | 350c8cad6b6f71db4c367a0f84740362d277333c | |
parent | c376629e03f3fce413e23971168f3ee1bc597d1f (diff) | |
download | chromium_src-fce8c970259a917e0209d4c12c50f10c5a5d669b.zip chromium_src-fce8c970259a917e0209d4c12c50f10c5a5d669b.tar.gz chromium_src-fce8c970259a917e0209d4c12c50f10c5a5d669b.tar.bz2 |
Get rid of RequestRegistry (part 5): each request cancels itself.
There should be no behavior change. It's just moving code
out of RequestRegistry.
BUG=164098
Review URL: https://chromiumcodereview.appspot.com/17379020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207847 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/google_apis/base_requests.cc | 11 | ||||
-rw-r--r-- | chrome/browser/google_apis/base_requests.h | 14 | ||||
-rw-r--r-- | chrome/browser/google_apis/request_registry.cc | 40 | ||||
-rw-r--r-- | chrome/browser/google_apis/request_registry.h | 43 | ||||
-rw-r--r-- | chrome/browser/google_apis/request_sender.cc | 2 |
5 files changed, 16 insertions, 94 deletions
diff --git a/chrome/browser/google_apis/base_requests.cc b/chrome/browser/google_apis/base_requests.cc index 52dce30..3c11531 100644 --- a/chrome/browser/google_apis/base_requests.cc +++ b/chrome/browser/google_apis/base_requests.cc @@ -218,9 +218,10 @@ bool UrlFetchRequestBase::GetContentFile(base::FilePath* local_file_path, return false; } -void UrlFetchRequestBase::DoCancel() { +void UrlFetchRequestBase::Cancel() { url_fetcher_.reset(NULL); RunCallbackOnPrematureFailure(GDATA_CANCELLED); + NotifyFinish(); } // static @@ -239,7 +240,7 @@ GDataErrorCode UrlFetchRequestBase::GetErrorCode(const URLFetcher* source) { } void UrlFetchRequestBase::OnProcessURLFetchResultsComplete(bool result) { - NotifyFinish(result ? REQUEST_COMPLETED : REQUEST_FAILED); + NotifyFinish(); } void UrlFetchRequestBase::OnURLFetchComplete(const URLFetcher* source) { @@ -274,11 +275,7 @@ void UrlFetchRequestBase::OnAuthFailed(GDataErrorCode code) { // Note: NotifyFinish() must be invoked at the end, after all other callbacks // and notifications. Once NotifyFinish() is called, the current instance of // request will be deleted from the RequestRegistry and become invalid. - NotifyFinish(REQUEST_FAILED); -} - -RequestRegistry::Request* UrlFetchRequestBase::AsRequestRegistryRequest() { - return this; + NotifyFinish(); } base::WeakPtr<AuthenticatedRequestInterface> diff --git a/chrome/browser/google_apis/base_requests.h b/chrome/browser/google_apis/base_requests.h index 356eefc..ff71dab 100644 --- a/chrome/browser/google_apis/base_requests.h +++ b/chrome/browser/google_apis/base_requests.h @@ -12,6 +12,7 @@ #include <vector> #include "base/callback.h" +#include "base/files/file_path.h" #include "base/memory/weak_ptr.h" #include "chrome/browser/google_apis/gdata_errorcode.h" #include "chrome/browser/google_apis/request_registry.h" @@ -77,10 +78,9 @@ class AuthenticatedRequestInterface { // using weak pointers, while deprecating RequestRegistry. virtual base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() = 0; - // TODO(kinaba): crbug.com/{164089, 231209} This is temporarily added during - // migration of cancellation from RequestRegistry to JobScheduler. It should - // go away *very soon*. - virtual RequestRegistry::Request* AsRequestRegistryRequest() = 0; + // Cancels the request. It will invoke the callback object passed in + // each request's constructor with error code GDATA_CANCELLED. + virtual void Cancel() = 0; }; //============================ UrlFetchRequestBase =========================== @@ -95,6 +95,7 @@ class UrlFetchRequestBase : public AuthenticatedRequestInterface, const std::string& custom_user_agent, const ReAuthenticateCallback& callback) OVERRIDE; virtual base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() OVERRIDE; + virtual void Cancel() OVERRIDE; protected: UrlFetchRequestBase(RequestSender* runner, @@ -159,15 +160,11 @@ class UrlFetchRequestBase : public AuthenticatedRequestInterface, } private: - // RequestRegistry::Request overrides. - virtual void DoCancel() OVERRIDE; - // URLFetcherDelegate overrides. virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; // AuthenticatedRequestInterface overrides. virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; - virtual RequestRegistry::Request* AsRequestRegistryRequest() OVERRIDE; net::URLRequestContextGetter* url_request_context_getter_; ReAuthenticateCallback re_authenticate_callback_; @@ -178,7 +175,6 @@ class UrlFetchRequestBase : public AuthenticatedRequestInterface, bool save_temp_file_; base::FilePath output_file_path_; - // WeakPtrFactory bound to the UI thread. // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. base::WeakPtrFactory<UrlFetchRequestBase> weak_ptr_factory_; diff --git a/chrome/browser/google_apis/request_registry.cc b/chrome/browser/google_apis/request_registry.cc index 9c247c5..cc9fb03 100644 --- a/chrome/browser/google_apis/request_registry.cc +++ b/chrome/browser/google_apis/request_registry.cc @@ -4,43 +4,21 @@ #include "chrome/browser/google_apis/request_registry.h" -#include "content/public/browser/browser_thread.h" - -using content::BrowserThread; - namespace google_apis { -RequestProgressStatus::RequestProgressStatus() - : request_id(-1), - transfer_state(REQUEST_NOT_STARTED) { -} - RequestRegistry::Request::Request(RequestRegistry* registry) - : registry_(registry) { + : registry_(registry), id_(-1) { } RequestRegistry::Request::~Request() { } -void RequestRegistry::Request::Cancel() { - DoCancel(); - NotifyFinish(REQUEST_FAILED); -} - void RequestRegistry::Request::NotifyStart() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - // Some request_ids may be restarted. Report only the first "start". - if (progress_status_.transfer_state == REQUEST_NOT_STARTED) { - progress_status_.transfer_state = REQUEST_STARTED; - registry_->OnRequestStart(this, &progress_status_.request_id); - } + registry_->OnRequestStart(this, &id_); } -void RequestRegistry::Request::NotifyFinish( - RequestTransferState status) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - progress_status_.transfer_state = status; - registry_->OnRequestFinish(progress_status().request_id); +void RequestRegistry::Request::NotifyFinish() { + registry_->OnRequestFinish(id_); } RequestRegistry::RequestRegistry() { @@ -50,23 +28,13 @@ RequestRegistry::RequestRegistry() { RequestRegistry::~RequestRegistry() { } -void RequestRegistry::CancelRequest(Request* request) { - request->Cancel(); -} - void RequestRegistry::OnRequestStart( RequestRegistry::Request* request, RequestID* id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - *id = in_flight_requests_.Add(request); - DVLOG(1) << "Request[" << *id << "] started."; } void RequestRegistry::OnRequestFinish(RequestID id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - DVLOG(1) << "Request[" << id << "] finished."; if (in_flight_requests_.Lookup(id)) in_flight_requests_.Remove(id); } diff --git a/chrome/browser/google_apis/request_registry.h b/chrome/browser/google_apis/request_registry.h index 9374baa..1331f91 100644 --- a/chrome/browser/google_apis/request_registry.h +++ b/chrome/browser/google_apis/request_registry.h @@ -6,37 +6,13 @@ #define CHROME_BROWSER_GOOGLE_APIS_REQUEST_REGISTRY_H_ #include "base/basictypes.h" -#include "base/files/file_path.h" #include "base/id_map.h" -#include "chrome/browser/google_apis/gdata_errorcode.h" namespace google_apis { // Unique ID to identify each request. typedef int32 RequestID; -// Enumeration type for indicating the state of the transfer. -enum RequestTransferState { - REQUEST_NOT_STARTED, - REQUEST_STARTED, - REQUEST_IN_PROGRESS, - REQUEST_COMPLETED, - REQUEST_FAILED, -}; - -// Returns string representations of the request state. -std::string RequestTransferStateToString(RequestTransferState state); - -// Structure that packs progress information of each request. -struct RequestProgressStatus { - RequestProgressStatus(); - - RequestID request_id; - - // Current state of the transfer; - RequestTransferState transfer_state; -}; - // This class tracks all the in-flight Google API requests and manage // their lifetime. class RequestRegistry { @@ -53,31 +29,16 @@ class RequestRegistry { explicit Request(RequestRegistry* registry); virtual ~Request(); - // Cancels the ongoing request. NotifyFinish() is called and the Request - // object is deleted once the cancellation is done in DoCancel(). - void Cancel(); - - // Retrieves the current progress status of the request. - const RequestProgressStatus& progress_status() const { - return progress_status_; - } - protected: // Notifies the registry about current status. void NotifyStart(); - void NotifyFinish(RequestTransferState status); + void NotifyFinish(); private: - // Does the cancellation. - virtual void DoCancel() = 0; - RequestRegistry* const registry_; - RequestProgressStatus progress_status_; + RequestID id_; }; - // Cancels the specified request. - void CancelRequest(Request* request); - private: // Handlers for notifications from Requests. friend class Request; diff --git a/chrome/browser/google_apis/request_sender.cc b/chrome/browser/google_apis/request_sender.cc index 63a1a38..a5c268b 100644 --- a/chrome/browser/google_apis/request_sender.cc +++ b/chrome/browser/google_apis/request_sender.cc @@ -93,7 +93,7 @@ void RequestSender::CancelRequest( // Do nothing if the request is already finished. if (!request.get()) return; - request_registry_->CancelRequest(request->AsRequestRegistryRequest()); + request->Cancel(); } } // namespace google_apis |