| OLD | NEW |
| 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" | 7 #include "content/public/browser/browser_thread.h" |
| 8 | 8 |
| 9 using content::BrowserThread; | 9 using content::BrowserThread; |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 DCHECK(status == REQUEST_COMPLETED || status == REQUEST_FAILED); | 53 DCHECK(status == REQUEST_COMPLETED || status == REQUEST_FAILED); |
| 54 progress_status_.transfer_state = status; | 54 progress_status_.transfer_state = status; |
| 55 registry_->OnRequestFinish(progress_status().request_id); | 55 registry_->OnRequestFinish(progress_status().request_id); |
| 56 } | 56 } |
| 57 | 57 |
| 58 RequestRegistry::RequestRegistry() { | 58 RequestRegistry::RequestRegistry() { |
| 59 in_flight_requests_.set_check_on_null_data(true); | 59 in_flight_requests_.set_check_on_null_data(true); |
| 60 } | 60 } |
| 61 | 61 |
| 62 RequestRegistry::~RequestRegistry() { | 62 RequestRegistry::~RequestRegistry() { |
| 63 DCHECK(in_flight_requests_.IsEmpty()); | |
| 64 } | |
| 65 | |
| 66 void RequestRegistry::CancelAll() { | |
| 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 68 | |
| 69 for (RequestIDMap::iterator iter(&in_flight_requests_); | |
| 70 !iter.IsAtEnd(); | |
| 71 iter.Advance()) { | |
| 72 Request* request = iter.GetCurrentValue(); | |
| 73 CancelRequest(request); | |
| 74 // CancelRequest may immediately trigger OnRequestFinish and remove the | |
| 75 // request from the map, but IDMap is designed to be safe on such remove | |
| 76 // while iteration. | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 bool RequestRegistry::CancelForFilePath(const base::FilePath& file_path) { | |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 82 | |
| 83 for (RequestIDMap::iterator iter(&in_flight_requests_); | |
| 84 !iter.IsAtEnd(); | |
| 85 iter.Advance()) { | |
| 86 Request* request = iter.GetCurrentValue(); | |
| 87 if (request->progress_status().file_path == file_path) { | |
| 88 CancelRequest(request); | |
| 89 return true; | |
| 90 } | |
| 91 } | |
| 92 return false; | |
| 93 } | 63 } |
| 94 | 64 |
| 95 void RequestRegistry::CancelRequest(Request* request) { | 65 void RequestRegistry::CancelRequest(Request* request) { |
| 96 request->Cancel(); | 66 request->Cancel(); |
| 97 } | 67 } |
| 98 | 68 |
| 99 void RequestRegistry::OnRequestStart( | 69 void RequestRegistry::OnRequestStart( |
| 100 RequestRegistry::Request* request, | 70 RequestRegistry::Request* request, |
| 101 RequestID* id) { | 71 RequestID* id) { |
| 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 103 | 73 |
| 104 *id = in_flight_requests_.Add(request); | 74 *id = in_flight_requests_.Add(request); |
| 105 DVLOG(1) << "Request[" << *id << "] started."; | 75 DVLOG(1) << "Request[" << *id << "] started."; |
| 106 } | 76 } |
| 107 | 77 |
| 108 void RequestRegistry::OnRequestFinish(RequestID id) { | 78 void RequestRegistry::OnRequestFinish(RequestID id) { |
| 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 110 | 80 |
| 111 Request* request = in_flight_requests_.Lookup(id); | 81 Request* request = in_flight_requests_.Lookup(id); |
| 112 DCHECK(request); | 82 DCHECK(request); |
| 113 | 83 |
| 114 DVLOG(1) << "Request[" << id << "] finished."; | 84 DVLOG(1) << "Request[" << id << "] finished."; |
| 115 in_flight_requests_.Remove(id); | 85 in_flight_requests_.Remove(id); |
| 116 } | 86 } |
| 117 | 87 |
| 118 } // namespace google_apis | 88 } // namespace google_apis |
| OLD | NEW |