diff options
author | tmdiep@chromium.org <tmdiep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-21 01:19:03 +0000 |
---|---|---|
committer | tmdiep@chromium.org <tmdiep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-21 01:19:03 +0000 |
commit | 9c7b3096df0dfcf50d28741187d0bc1d3b99e801 (patch) | |
tree | 29b38860e6be07b4115df13397d1b3f443654926 /chrome/browser/extensions/extension_install_checker.h | |
parent | 6964f56488be2517eea4303502d2ea0e4a6358d5 (diff) | |
download | chromium_src-9c7b3096df0dfcf50d28741187d0bc1d3b99e801.zip chromium_src-9c7b3096df0dfcf50d28741187d0bc1d3b99e801.tar.gz chromium_src-9c7b3096df0dfcf50d28741187d0bc1d3b99e801.tar.bz2 |
Update the EphemeralAppLauncher for use by the webstorePrivate API
- The WebstoreStandaloneInstaller now supports error codes to allow
translation to API error codes.
- The EphemeralAppLauncher now also returns error codes and performs
more checks before installing an ephemeral app or enabling an
installed app.
- Introduces the ExtensionInstallChecker, which checks blacklist
state, requirement errors and management policies for a given
extension.
BUG=380980
TEST=browser_tests (EphemeralAppLauncherTest.*)
unit_tests (ExtensionInstallCheckerTest.*)
Review URL: https://codereview.chromium.org/339103002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278890 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_install_checker.h')
-rw-r--r-- | chrome/browser/extensions/extension_install_checker.h | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_install_checker.h b/chrome/browser/extensions/extension_install_checker.h new file mode 100644 index 0000000..2841e83 --- /dev/null +++ b/chrome/browser/extensions/extension_install_checker.h @@ -0,0 +1,133 @@ +// Copyright 2014 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_EXTENSION_INSTALL_CHECKER_H_ +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ + +#include <string> +#include <vector> + +#include "base/callback.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "base/strings/string16.h" +#include "extensions/browser/blacklist_state.h" +#include "extensions/common/extension.h" + +class Profile; + +namespace extensions { + +class RequirementsChecker; + +// Performs common checks for an extension. Extensions that violate these checks +// would be disabled or not even installed. +class ExtensionInstallChecker { + public: + // Called when checks are complete. The returned value is a bitmask of + // failed checks. + typedef base::Callback<void(int)> Callback; + + enum CheckType { + // Check the blacklist state of the extension. + CHECK_BLACKLIST = 1 << 0, + // Check whether the extension has requirement errors. + CHECK_REQUIREMENTS = 1 << 1, + // Check whether the extension can be installed and loaded, according to + // management policies. + CHECK_MANAGEMENT_POLICY = 1 << 2, + // Perform all checks. + CHECK_ALL = (1 << 3) - 1 + }; + + explicit ExtensionInstallChecker(Profile* profile); + virtual ~ExtensionInstallChecker(); + + // Start a set of checks. |enabled_checks| is a bitmask of CheckTypes to run. + // If |fail_fast| is true, the callback will be invoked once any check fails. + // Otherwise it will be invoked when all checks have completed. |callback| + // will only be called once. + // This function must be called on the UI thread. The callback also occurs on + // the UI thread. Checks may run asynchronously in parallel. + // If checks are currently running, the caller must wait for the callback to + // be invoked before starting another set of checks. + void Start(int enabled_checks, bool fail_fast, const Callback& callback); + + Profile* profile() const { return profile_; } + + scoped_refptr<const Extension> extension() { return extension_; } + void set_extension(const Extension* extension) { extension_ = extension; } + + // Returns true if any checks are currently running. + bool is_running() const { return running_checks_ != 0; } + + // Returns the requirement violations. A non-empty list is considered to be + // a check failure. + const std::vector<std::string>& requirement_errors() const { + return requirement_errors_; + } + + // Returns the blacklist state of the extension. A blacklist state of + // BLACKLISTED_MALWARE is considered to be a check failure. + BlacklistState blacklist_state() const { return blacklist_state_; } + + // Returns whether management policy permits installation of the extension. + bool policy_allows_load() const { return policy_allows_load_; } + const std::string& policy_error() const { return policy_error_; } + + protected: + virtual void CheckManagementPolicy(); + void OnManagementPolicyCheckDone(bool allows_load, const std::string& error); + + virtual void CheckRequirements(); + void OnRequirementsCheckDone(int sequence_number, + std::vector<std::string> errors); + + virtual void CheckBlacklistState(); + void OnBlacklistStateCheckDone(int sequence_number, BlacklistState state); + + virtual void ResetResults(); + int current_sequence_number() const { return current_sequence_number_; } + + private: + void MaybeInvokeCallback(); + + scoped_ptr<RequirementsChecker> requirements_checker_; + + // The Profile where the extension is being installed in. + Profile* profile_; + + // The extension to run checks for. + scoped_refptr<const Extension> extension_; + + // Requirement violations. + std::vector<std::string> requirement_errors_; + + // Result of the blacklist state check. + BlacklistState blacklist_state_; + + // Whether the extension can be installed, according to management policies. + bool policy_allows_load_; + std::string policy_error_; + + // The sequence number of the currently running checks. + int current_sequence_number_; + + // Bitmask of currently running checks. + int running_checks_; + + // If true, the callback is invoked when the first check fails. + bool fail_fast_; + + // The callback to invoke when checks are complete. + Callback callback_; + + base::WeakPtrFactory<ExtensionInstallChecker> weak_ptr_factory_; + + DISALLOW_COPY_AND_ASSIGN(ExtensionInstallChecker); +}; + +} // namespace extensions + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_CHECKER_H_ |