Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / component_updater / default_component_installer.h
blob3c9f52df5a3d9e88ad55e78a4f4706def2966c78
1 // Copyright 2013 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_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_
8 #include <string>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/version.h"
14 #include "chrome/browser/component_updater/component_updater_service.h"
16 namespace base {
17 class DictionaryValue;
18 class FilePath;
19 } // namespace base
21 namespace component_updater {
23 // Components should use a DefaultComponentInstaller by defining a class that
24 // implements the members of ComponentInstallerTraits, and then registering a
25 // DefaultComponentInstaller that has been constructed with an instance of that
26 // class.
27 class ComponentInstallerTraits {
28 public:
29 virtual ~ComponentInstallerTraits();
31 // Verifies that a working installation resides within the directory specified
32 // by |dir|. |dir| is of the form <base directory>/<version>.
33 // Called only from a thread belonging to a blocking thread pool.
34 // The implementation of this function must be efficient since the function
35 // can be called when Chrome starts.
36 virtual bool VerifyInstallation(const base::FilePath& dir) const = 0;
38 // Returns true if the component can be automatically updated. Called once
39 // during component registration from the UI thread.
40 virtual bool CanAutoUpdate() const = 0;
42 // OnCustomInstall is called during the installation process. Components that
43 // require custom installation operations should implement them here.
44 // Returns false if a custom operation failed, and true otherwise.
45 // Called only from a thread belonging to a blocking thread pool.
46 virtual bool OnCustomInstall(const base::DictionaryValue& manifest,
47 const base::FilePath& install_dir) = 0;
49 // ComponentReady is called in two cases:
50 // 1) After an installation is successfully completed.
51 // 2) During component registration if the component is already installed.
52 // In both cases the install is verified before this is called. This method
53 // is guaranteed to be called before any observers of the component are
54 // notified of a successful install, and is meant to support follow-on work
55 // such as updating paths elsewhere in Chrome. Called on the UI thread.
56 // |version| is the version of the component.
57 // |install_dir| is the path to the install directory for this version.
58 // |manifest| is the manifest for this version of the component.
59 virtual void ComponentReady(
60 const base::Version& version,
61 const base::FilePath& install_dir,
62 scoped_ptr<base::DictionaryValue> manifest) = 0;
64 // Returns the directory that the installer will place versioned installs of
65 // the component into.
66 virtual base::FilePath GetBaseDirectory() const = 0;
68 // Returns the component's SHA2 hash as raw bytes.
69 virtual void GetHash(std::vector<uint8>* hash) const = 0;
71 // Returns the human-readable name of the component.
72 virtual std::string GetName() const = 0;
75 // A DefaultComponentInstaller is intended to be final, and not derived from.
76 // Customization must be provided by passing a ComponentInstallerTraits object
77 // to the constructor.
78 class DefaultComponentInstaller : public ComponentInstaller {
79 public:
80 explicit DefaultComponentInstaller(
81 scoped_ptr<ComponentInstallerTraits> installer_traits);
83 // Registers the component for update checks and installs.
84 void Register(ComponentUpdateService* cus);
86 // Overridden from ComponentInstaller:
87 virtual void OnUpdateError(int error) OVERRIDE;
88 virtual bool Install(const base::DictionaryValue& manifest,
89 const base::FilePath& unpack_path) OVERRIDE;
90 virtual bool GetInstalledFile(const std::string& file,
91 base::FilePath* installed_file) OVERRIDE;
93 virtual ~DefaultComponentInstaller();
95 private:
96 base::FilePath GetInstallDirectory();
97 bool InstallHelper(const base::DictionaryValue& manifest,
98 const base::FilePath& unpack_path,
99 const base::FilePath& install_path);
100 void StartRegistration(ComponentUpdateService* cus);
101 void FinishRegistration(ComponentUpdateService* cus);
103 base::Version current_version_;
104 std::string current_fingerprint_;
105 scoped_ptr<base::DictionaryValue> current_manifest_;
106 scoped_ptr<ComponentInstallerTraits> installer_traits_;
108 DISALLOW_COPY_AND_ASSIGN(DefaultComponentInstaller);
111 } // namespace component_updater
113 #endif // CHROME_BROWSER_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_