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

Unified Diff: chrome/browser/extensions/requirements_checker.h

Issue 10689097: Enforce the 'requirements' field in manifests. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/requirements_checker.h
diff --git a/chrome/browser/extensions/requirements_checker.h b/chrome/browser/extensions/requirements_checker.h
new file mode 100644
index 0000000000000000000000000000000000000000..c45b10736aa6b8a0a1ad794cdb2917a5e32e8434
--- /dev/null
+++ b/chrome/browser/extensions/requirements_checker.h
@@ -0,0 +1,72 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_REQUIREMENTS_CHECKER_H_
+#define CHROME_BROWSER_EXTENSIONS_REQUIREMENTS_CHECKER_H_
+
+#include <vector>
+
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "chrome/browser/extensions/extension_service.h"
+
+class GPUFeatureChecker;
+
+namespace extensions {
+class Extension;
+
+class RequirementsChecker : public base::SupportsWeakPtr<RequirementsChecker> {
+ public:
+ RequirementsChecker();
+ ~RequirementsChecker();
+
+ // The vector passed to the callback are any localized errors describing
+ // requirement violations. If this vector is non-empty, requirements checking
+ // failed. This should only be called once. |callback| will be invoked on
+ // the calling thread.
+ void Check(scoped_refptr<const Extension> extension,
+ base::Callback<void(std::vector<std::string>)> callback,
+ 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.
+
+ // Because of the GPUFeatureChecker, any WeakPtr to RequirementsChecker must
+ // be bound to the UI thread. Therefore, there is a pitfall if someone does
+ // something seemingly innocent like this:
+ // BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ // base::Bind(&RequirementsChecker::Check,
+ // my_requirements_checker_->AsWeakPtr()),
+ // ...);
+ // If the caller is not on the UI thread (hence the PostTask()) and this is
+ // the first call to AsWeakPtr(), then the subsequent WeakPtrs will be bound
+ // to a thread that is not the UI thread. This will cause problems for the
+ // GPUFeatureChecker which calls back (and therefore dereferences the
+ // WeakPtr) from the UI thread. To help avoid this pitfall, AsWeakPtr() is
+ // overridden and the UI thread is asserted.
+ 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.
+
+ private:
+ 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
+
+ // Callbacks for the GPUFeatureChecker.
+ void IsWebGLAvailable(bool available);
+ void IsCSS3DAvailable(bool available);
+
+ void MaybeRunCallback();
+
+ std::vector<std::string> errors_;
+
+ // 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.
+ // this counter. When the counter is depleted, the callback will be run.
+ int async_requirement_checks_;
+
+ scoped_refptr<GPUFeatureChecker> webgl_checker_;
+ scoped_refptr<GPUFeatureChecker> css3d_checker_;
+
+ base::Callback<void(std::vector<std::string>)> callback_;
+ content::BrowserThread::ID callback_thread_;
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_REQUIREMENTS_CHECKER_H_

Powered by Google App Engine
This is Rietveld 408576698