Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / components / update_client / update_client.h
blob35b3cca3429ba2d94edd2dd9281356a9c79ad1c4
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_
8 #include <stdint.h>
9 #include <string>
10 #include <vector>
12 #include "base/memory/ref_counted.h"
13 #include "base/version.h"
15 namespace base {
16 class DictionaryValue;
17 class FilePath;
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> {
27 public:
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;
53 protected:
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.
68 struct CrxComponent {
69 std::vector<uint8_t> pk_hash;
70 scoped_refptr<ComponentInstaller> installer;
71 Version version;
72 std::string fingerprint;
73 std::string name;
74 bool allow_background_download;
75 CrxComponent();
76 ~CrxComponent();
79 } // namespace update_client
81 #endif // COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_H_