Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / startup_helper.h
blob68441941da8a40f937afcf6f19b663d482a8771e
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_STARTUP_HELPER_H_
6 #define CHROME_BROWSER_EXTENSIONS_STARTUP_HELPER_H_
8 #include "base/memory/ref_counted.h"
9 #include "chrome/browser/extensions/pack_extension_job.h"
11 class CommandLine;
12 class Profile;
14 namespace extensions {
16 // Initialization helpers for various Extension startup actions.
17 class StartupHelper : public PackExtensionJob::Client {
18 public:
19 StartupHelper();
20 virtual ~StartupHelper();
22 virtual void OnPackSuccess(
23 const base::FilePath& crx_path,
24 const base::FilePath& output_private_key_path) OVERRIDE;
25 virtual void OnPackFailure(const std::string& error_message,
26 ExtensionCreator::ErrorType type) OVERRIDE;
28 // Handle --pack-extension flag from the |cmd_line| by packing the specified
29 // extension. Returns false if the pack job failed.
30 bool PackExtension(const CommandLine& cmd_line);
32 // Validates a crx at the path given by the --validate-extension flag - can
33 // it be installed? Returns true if the crx is valid, or false otherwise.
34 // If the return value is false, a description of the problem may be written
35 // into |error|.
36 bool ValidateCrx(const CommandLine& cmd_line, std::string* error);
38 // Handle --uninstall-extension flag from the |cmd_line| by uninstalling the
39 // specified extension from |profile|. Returns false if the uninstall job
40 // could not be started.
41 bool UninstallExtension(const CommandLine& cmd_line, Profile* profile);
43 // Handle --install-from-webstore flag from |cmd_line| by downloading
44 // metadata from the webstore for the given id, prompting the user to
45 // confirm, and then downloading the crx and installing it.
46 bool InstallFromWebstore(const CommandLine& cmd_line, Profile* profile);
48 // Handle --limited-install-from-webstore flag from |cmd_line| by downloading
49 // metadata from the webstore for the given id, prompting the user to
50 // confirm, and then downloading the crx and installing it.
51 // This whole process is only kicked off by this function and completed
52 // asynchronously unlike InstallFromWebstore which finishes everything before
53 // returning.
54 void LimitedInstallFromWebstore(const CommandLine& cmd_line, Profile* profile,
55 base::Callback<void()> done_callback);
57 // Maps the command line argument to the extension id. Returns an empty string
58 // in the case when there is no mapping.
59 std::string WebStoreIdFromLimitedInstallCmdLine(const CommandLine& cmd_line);
60 private:
61 scoped_refptr<PackExtensionJob> pack_job_;
62 bool pack_job_succeeded_;
64 DISALLOW_COPY_AND_ASSIGN(StartupHelper);
67 } // namespace extensions
69 #endif // CHROME_BROWSER_EXTENSIONS_STARTUP_HELPER_H_