| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // CancelableRequestProviders and Consumers work together to make requests that | 5 // CancelableRequestProviders and Consumers work together to make requests that |
| 6 // execute on a background thread in the provider and return data to the | 6 // execute on a background thread in the provider and return data to the |
| 7 // consumer. These class collaborate to keep a list of open requests and to | 7 // consumer. These class collaborate to keep a list of open requests and to |
| 8 // make sure that requests to not outlive either of the objects involved in the | 8 // make sure that requests to not outlive either of the objects involved in the |
| 9 // transaction. | 9 // transaction. |
| 10 // | 10 // |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 #ifndef CHROME_BROWSER_CANCELABLE_REQUEST_H__ | 86 #ifndef CHROME_BROWSER_CANCELABLE_REQUEST_H__ |
| 87 #define CHROME_BROWSER_CANCELABLE_REQUEST_H__ | 87 #define CHROME_BROWSER_CANCELABLE_REQUEST_H__ |
| 88 #pragma once | 88 #pragma once |
| 89 | 89 |
| 90 #include <map> | 90 #include <map> |
| 91 #include <vector> | 91 #include <vector> |
| 92 | 92 |
| 93 #include "base/basictypes.h" | 93 #include "base/basictypes.h" |
| 94 #include "base/callback.h" | 94 #include "base/callback.h" |
| 95 #include "base/cancellation_flag.h" | |
| 96 #include "base/lock.h" | 95 #include "base/lock.h" |
| 97 #include "base/logging.h" | 96 #include "base/logging.h" |
| 98 #include "base/message_loop.h" | 97 #include "base/message_loop.h" |
| 99 #include "base/ref_counted.h" | 98 #include "base/ref_counted.h" |
| 100 #include "base/scoped_ptr.h" | 99 #include "base/scoped_ptr.h" |
| 100 #include "base/synchronization/cancellation_flag.h" |
| 101 #include "base/task.h" | 101 #include "base/task.h" |
| 102 #include "build/build_config.h" | 102 #include "build/build_config.h" |
| 103 | 103 |
| 104 class CancelableRequestBase; | 104 class CancelableRequestBase; |
| 105 class CancelableRequestConsumerBase; | 105 class CancelableRequestConsumerBase; |
| 106 | 106 |
| 107 // CancelableRequestProvider -------------------------------------------------- | 107 // CancelableRequestProvider -------------------------------------------------- |
| 108 // | 108 // |
| 109 // This class is threadsafe. Requests may be added or canceled from any thread, | 109 // This class is threadsafe. Requests may be added or canceled from any thread, |
| 110 // but a task must only be canceled from the same thread it was initially run | 110 // but a task must only be canceled from the same thread it was initially run |
| (...skipping 30 matching lines...) Expand all Loading... |
| 141 | 141 |
| 142 private: | 142 private: |
| 143 typedef std::map<Handle, scoped_refptr<CancelableRequestBase> > | 143 typedef std::map<Handle, scoped_refptr<CancelableRequestBase> > |
| 144 CancelableRequestMap; | 144 CancelableRequestMap; |
| 145 | 145 |
| 146 // Only call this when you already have acquired pending_request_lock_. | 146 // Only call this when you already have acquired pending_request_lock_. |
| 147 void CancelRequestLocked(const CancelableRequestMap::iterator& item); | 147 void CancelRequestLocked(const CancelableRequestMap::iterator& item); |
| 148 | 148 |
| 149 friend class CancelableRequestBase; | 149 friend class CancelableRequestBase; |
| 150 | 150 |
| 151 Lock pending_request_lock_; | 151 base::Lock pending_request_lock_; |
| 152 | 152 |
| 153 // Lists all outstanding requests. Protected by the |lock_|. | 153 // Lists all outstanding requests. Protected by the |lock_|. |
| 154 CancelableRequestMap pending_requests_; | 154 CancelableRequestMap pending_requests_; |
| 155 | 155 |
| 156 // The next handle value we will return. Protected by the |lock_|. | 156 // The next handle value we will return. Protected by the |lock_|. |
| 157 int next_handle_; | 157 int next_handle_; |
| 158 | 158 |
| 159 DISALLOW_COPY_AND_ASSIGN(CancelableRequestProvider); | 159 DISALLOW_COPY_AND_ASSIGN(CancelableRequestProvider); |
| 160 }; | 160 }; |
| 161 | 161 |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 } | 695 } |
| 696 | 696 |
| 697 // The value. | 697 // The value. |
| 698 Type value; | 698 Type value; |
| 699 | 699 |
| 700 protected: | 700 protected: |
| 701 virtual ~CancelableRequest1() {} | 701 virtual ~CancelableRequest1() {} |
| 702 }; | 702 }; |
| 703 | 703 |
| 704 #endif // CHROME_BROWSER_CANCELABLE_REQUEST_H__ | 704 #endif // CHROME_BROWSER_CANCELABLE_REQUEST_H__ |
| OLD | NEW |