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