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

Side by Side Diff: chrome/browser/google_apis/request_registry.cc

Issue 17379020: Get rid of RequestRegistry (part 5): each request cancels itself. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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/google_apis/request_registry.h" 5 #include "chrome/browser/google_apis/request_registry.h"
6 6
7 #include "content/public/browser/browser_thread.h"
8
9 using content::BrowserThread;
10
11 namespace google_apis { 7 namespace google_apis {
12 8
13 RequestProgressStatus::RequestProgressStatus()
14 : request_id(-1),
15 transfer_state(REQUEST_NOT_STARTED) {
16 }
17
18 RequestRegistry::Request::Request(RequestRegistry* registry) 9 RequestRegistry::Request::Request(RequestRegistry* registry)
19 : registry_(registry) { 10 : registry_(registry), id_(-1) {
20 } 11 }
21 12
22 RequestRegistry::Request::~Request() { 13 RequestRegistry::Request::~Request() {
23 } 14 }
24 15
25 void RequestRegistry::Request::Cancel() { 16 void RequestRegistry::Request::NotifyStart() {
26 DoCancel(); 17 registry_->OnRequestStart(this, &id_);
27 NotifyFinish(REQUEST_FAILED);
28 } 18 }
29 19
30 void RequestRegistry::Request::NotifyStart() { 20 void RequestRegistry::Request::NotifyFinish() {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 21 registry_->OnRequestFinish(id_);
32 // Some request_ids may be restarted. Report only the first "start".
33 if (progress_status_.transfer_state == REQUEST_NOT_STARTED) {
34 progress_status_.transfer_state = REQUEST_STARTED;
35 registry_->OnRequestStart(this, &progress_status_.request_id);
36 }
37 }
38
39 void RequestRegistry::Request::NotifyFinish(
40 RequestTransferState status) {
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
42 progress_status_.transfer_state = status;
43 registry_->OnRequestFinish(progress_status().request_id);
44 } 22 }
45 23
46 RequestRegistry::RequestRegistry() { 24 RequestRegistry::RequestRegistry() {
47 in_flight_requests_.set_check_on_null_data(true); 25 in_flight_requests_.set_check_on_null_data(true);
48 } 26 }
49 27
50 RequestRegistry::~RequestRegistry() { 28 RequestRegistry::~RequestRegistry() {
51 } 29 }
52 30
53 void RequestRegistry::CancelRequest(Request* request) {
54 request->Cancel();
55 }
56
57 void RequestRegistry::OnRequestStart( 31 void RequestRegistry::OnRequestStart(
58 RequestRegistry::Request* request, 32 RequestRegistry::Request* request,
59 RequestID* id) { 33 RequestID* id) {
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
61
62 *id = in_flight_requests_.Add(request); 34 *id = in_flight_requests_.Add(request);
63 DVLOG(1) << "Request[" << *id << "] started.";
64 } 35 }
65 36
66 void RequestRegistry::OnRequestFinish(RequestID id) { 37 void RequestRegistry::OnRequestFinish(RequestID id) {
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
68
69 DVLOG(1) << "Request[" << id << "] finished.";
70 if (in_flight_requests_.Lookup(id)) 38 if (in_flight_requests_.Lookup(id))
71 in_flight_requests_.Remove(id); 39 in_flight_requests_.Remove(id);
72 } 40 }
73 41
74 } // namespace google_apis 42 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/request_registry.h ('k') | chrome/browser/google_apis/request_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698