Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_REQUIREMENTS_CHECKER_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_REQUIREMENTS_CHECKER_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "chrome/browser/extensions/extension_service.h" | |
| 14 | |
| 15 class GPUFeatureChecker; | |
| 16 | |
| 17 namespace extensions { | |
| 18 class Extension; | |
| 19 | |
| 20 class RequirementsChecker : public base::SupportsWeakPtr<RequirementsChecker> { | |
| 21 public: | |
| 22 RequirementsChecker(); | |
| 23 ~RequirementsChecker(); | |
| 24 | |
| 25 // The vector passed to the callback are any localized errors describing | |
| 26 // requirement violations. If this vector is non-empty, requirements checking | |
| 27 // failed. This should only be called once. |callback| will be invoked on | |
| 28 // the calling thread. | |
| 29 void Check(scoped_refptr<const Extension> extension, | |
| 30 base::Callback<void(std::vector<std::string>)> callback, | |
| 31 content::BrowserThread::ID callback_thread); | |
|
Aaron Boodman
2012/08/01 03:58:54
Yeah, so I think you can just let this callback on
eaugusti
2012/08/03 01:06:26
Done.
| |
| 32 | |
| 33 // Because of the GPUFeatureChecker, any WeakPtr to RequirementsChecker must | |
| 34 // be bound to the UI thread. Therefore, there is a pitfall if someone does | |
| 35 // something seemingly innocent like this: | |
| 36 // BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 37 // base::Bind(&RequirementsChecker::Check, | |
| 38 // my_requirements_checker_->AsWeakPtr()), | |
| 39 // ...); | |
| 40 // If the caller is not on the UI thread (hence the PostTask()) and this is | |
| 41 // the first call to AsWeakPtr(), then the subsequent WeakPtrs will be bound | |
| 42 // to a thread that is not the UI thread. This will cause problems for the | |
| 43 // GPUFeatureChecker which calls back (and therefore dereferences the | |
| 44 // WeakPtr) from the UI thread. To help avoid this pitfall, AsWeakPtr() is | |
| 45 // overridden and the UI thread is asserted. | |
| 46 virtual base::WeakPtr<RequirementsChecker> AsWeakPtr() OVERRIDE; | |
|
Aaron Boodman
2012/08/01 03:58:54
Nice catch, but do we have a need to call this fro
Yoyo Zhou
2012/08/02 22:23:30
There is also WeakPtrFactory which gives a bit mor
eaugusti
2012/08/03 01:06:26
Done.
| |
| 47 | |
| 48 private: | |
| 49 friend class GPUFeatureChecker; | |
|
Aaron Boodman
2012/08/01 03:58:54
Curiosity: Is this needed so GPUFeatureChecker can
eaugusti
2012/08/03 01:06:26
Yes, but it is totally unnecessary. I must be goin
| |
| 50 | |
| 51 // Callbacks for the GPUFeatureChecker. | |
| 52 void IsWebGLAvailable(bool available); | |
| 53 void IsCSS3DAvailable(bool available); | |
| 54 | |
| 55 void MaybeRunCallback(); | |
| 56 | |
| 57 std::vector<std::string> errors_; | |
| 58 | |
| 59 // Every requirments that needs to be resolved asynchroniously will add to | |
|
Yoyo Zhou
2012/08/02 22:23:30
typo: requirement, asynchronously
eaugusti
2012/08/03 01:06:26
Done.
| |
| 60 // this counter. When the counter is depleted, the callback will be run. | |
| 61 int async_requirement_checks_; | |
| 62 | |
| 63 scoped_refptr<GPUFeatureChecker> webgl_checker_; | |
| 64 scoped_refptr<GPUFeatureChecker> css3d_checker_; | |
| 65 | |
| 66 base::Callback<void(std::vector<std::string>)> callback_; | |
| 67 content::BrowserThread::ID callback_thread_; | |
| 68 }; | |
| 69 | |
| 70 } // namespace extensions | |
| 71 | |
| 72 #endif // CHROME_BROWSER_EXTENSIONS_REQUIREMENTS_CHECKER_H_ | |
| OLD | NEW |