| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/component_updater/component_updater_resource_throttle.h
" | 5 #include "chrome/browser/component_updater/component_updater_resource_throttle.h
" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "components/component_updater/component_updater_service.h" | 9 #include "components/component_updater/component_updater_service.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 typedef std::vector<base::WeakPtr<CUResourceThrottle> > WeakPtrVector; | 42 typedef std::vector<base::WeakPtr<CUResourceThrottle> > WeakPtrVector; |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 enum State { NEW, BLOCKED, UNBLOCKED }; | 45 enum State { NEW, BLOCKED, UNBLOCKED }; |
| 46 | 46 |
| 47 State state_; | 47 State state_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 CUResourceThrottle::CUResourceThrottle() : state_(NEW) { | 50 CUResourceThrottle::CUResourceThrottle() : state_(NEW) { |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 51 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 52 } | 52 } |
| 53 | 53 |
| 54 CUResourceThrottle::~CUResourceThrottle() { | 54 CUResourceThrottle::~CUResourceThrottle() { |
| 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 55 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void CUResourceThrottle::WillStartRequest(bool* defer) { | 58 void CUResourceThrottle::WillStartRequest(bool* defer) { |
| 59 if (state_ != UNBLOCKED) { | 59 if (state_ != UNBLOCKED) { |
| 60 state_ = BLOCKED; | 60 state_ = BLOCKED; |
| 61 *defer = true; | 61 *defer = true; |
| 62 } else { | 62 } else { |
| 63 *defer = false; | 63 *defer = false; |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 void CUResourceThrottle::WillRedirectRequest( | 67 void CUResourceThrottle::WillRedirectRequest( |
| 68 const net::RedirectInfo& redirect_info, bool* defer) { | 68 const net::RedirectInfo& redirect_info, bool* defer) { |
| 69 WillStartRequest(defer); | 69 WillStartRequest(defer); |
| 70 } | 70 } |
| 71 | 71 |
| 72 const char* CUResourceThrottle::GetNameForLogging() const { | 72 const char* CUResourceThrottle::GetNameForLogging() const { |
| 73 return "ComponentUpdateResourceThrottle"; | 73 return "ComponentUpdateResourceThrottle"; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void CUResourceThrottle::Unblock() { | 76 void CUResourceThrottle::Unblock() { |
| 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 77 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 78 if (state_ == BLOCKED) | 78 if (state_ == BLOCKED) |
| 79 controller()->Resume(); | 79 controller()->Resume(); |
| 80 state_ = UNBLOCKED; | 80 state_ = UNBLOCKED; |
| 81 } | 81 } |
| 82 | 82 |
| 83 void UnblockThrottleOnUIThread(base::WeakPtr<CUResourceThrottle> rt) { | 83 void UnblockThrottleOnUIThread(base::WeakPtr<CUResourceThrottle> rt) { |
| 84 BrowserThread::PostTask(BrowserThread::IO, | 84 BrowserThread::PostTask(BrowserThread::IO, |
| 85 FROM_HERE, | 85 FROM_HERE, |
| 86 base::Bind(&CUResourceThrottle::Unblock, rt)); | 86 base::Bind(&CUResourceThrottle::Unblock, rt)); |
| 87 } | 87 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 101 BrowserThread::UI, | 101 BrowserThread::UI, |
| 102 FROM_HERE, | 102 FROM_HERE, |
| 103 base::Bind(&ComponentUpdateService::MaybeThrottle, | 103 base::Bind(&ComponentUpdateService::MaybeThrottle, |
| 104 base::Unretained(cus), | 104 base::Unretained(cus), |
| 105 crx_id, | 105 crx_id, |
| 106 base::Bind(&UnblockThrottleOnUIThread, rt->AsWeakPtr()))); | 106 base::Bind(&UnblockThrottleOnUIThread, rt->AsWeakPtr()))); |
| 107 return rt; | 107 return rt; |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace component_updater | 110 } // namespace component_updater |
| OLD | NEW |