1 // Copyright 2015 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 COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_H_
6 #define COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_H_
12 #include "base/memory/ref_counted.h"
13 #include "base/version.h"
16 class DictionaryValue
;
20 namespace update_client
{
22 // Component specific installers must derive from this class and implement
23 // OnUpdateError() and Install(). A valid instance of this class must be
24 // given to ComponentUpdateService::RegisterComponent().
25 class ComponentInstaller
26 : public base::RefCountedThreadSafe
<ComponentInstaller
> {
28 // Called by the component updater on the main thread when there was a
29 // problem unpacking or verifying the component. |error| is a non-zero
30 // value which is only meaningful to the component updater.
31 virtual void OnUpdateError(int error
) = 0;
33 // Called by the component updater when a component has been unpacked
34 // and is ready to be installed. |manifest| contains the CRX manifest
35 // json dictionary and |unpack_path| contains the temporary directory
36 // with all the unpacked CRX files. This method may be called from
37 // a thread other than the main thread.
38 virtual bool Install(const base::DictionaryValue
& manifest
,
39 const base::FilePath
& unpack_path
) = 0;
41 // Set |installed_file| to the full path to the installed |file|. |file| is
42 // the filename of the file in this component's CRX. Returns false if this is
43 // not possible (the file has been removed or modified, or its current
44 // location is unknown). Otherwise, returns true.
45 virtual bool GetInstalledFile(const std::string
& file
,
46 base::FilePath
* installed_file
) = 0;
48 // Called by the component updater when a component has been unregistered and
49 // all versions should be uninstalled from disk. Returns true if
50 // uninstallation is supported, false otherwise.
51 virtual bool Uninstall() = 0;
54 friend class base::RefCountedThreadSafe
<ComponentInstaller
>;
56 virtual ~ComponentInstaller() {}
59 // Describes a particular component that can be installed or updated. This
60 // structure is required to register a component with the component updater.
61 // |pk_hash| is the SHA256 hash of the component's public key. If the component
62 // is to be installed then version should be "0" or "0.0", else it should be
63 // the current version. |fingerprint|, and |name| are optional.
64 // |allow_background_download| specifies that the component can be background
65 // downloaded in some cases. The default for this value is |true| and the value
66 // can be overriden at the registration time. This is a temporary change until
67 // the issue 340448 is resolved.
69 std::vector
<uint8_t> pk_hash
;
70 scoped_refptr
<ComponentInstaller
> installer
;
72 std::string fingerprint
;
74 bool allow_background_download
;
79 } // namespace update_client
81 #endif // COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_H_