cld_component_installer.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
1// Copyright 2014 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_CLD_COMPONENT_INSTALLER_H_
6#define CHROME_BROWSER_COMPONENT_UPDATER_CLD_COMPONENT_INSTALLER_H_
7
8#include <string>
9#include <vector>
10
11#include "base/files/file_path.h"
12#include "base/gtest_prod_util.h"
13#include "chrome/browser/component_updater/default_component_installer.h"
14
15namespace test {
16class ComponentCldDataHarness;
17}  // namespace test
18
19namespace component_updater {
20
21class ComponentUpdateService;
22
23// Visible for testing. No need to instantiate this class directly.
24class CldComponentInstallerTraits : public ComponentInstallerTraits {
25 public:
26  CldComponentInstallerTraits();
27  virtual ~CldComponentInstallerTraits() {}
28
29 private:
30  friend class CldComponentInstallerTest;  // For access within SetUp()
31  friend class test::ComponentCldDataHarness;  // For browser tests only
32  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, ComponentReady);
33  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, GetBaseDirectory);
34  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, GetHash);
35  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, GetInstalledPath);
36  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, GetName);
37  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, OnCustomInstall);
38  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, SetLatestCldDataFile);
39  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, VerifyInstallation);
40
41  // The following methods override ComponentInstallerTraits.
42  virtual bool CanAutoUpdate() const OVERRIDE;
43  virtual bool OnCustomInstall(const base::DictionaryValue& manifest,
44                               const base::FilePath& install_dir) OVERRIDE;
45  virtual bool VerifyInstallation(
46      const base::FilePath& install_dir) const OVERRIDE;
47  virtual void ComponentReady(
48      const base::Version& version,
49      const base::FilePath& path,
50      scoped_ptr<base::DictionaryValue> manifest) OVERRIDE;
51  virtual base::FilePath GetBaseDirectory() const OVERRIDE;
52  virtual void GetHash(std::vector<uint8>* hash) const OVERRIDE;
53  virtual std::string GetName() const OVERRIDE;
54
55  static base::FilePath GetInstalledPath(const base::FilePath& base);
56
57  // Sets the path to the CLD data file. Called internally once a valid CLD
58  // data file has been observed. The implementation of this method is
59  // responsible for configuring the CLD data source.
60  // This method is threadsafe.
61  static void SetLatestCldDataFile(const base::FilePath& path);
62
63  // Returns the file path that was most recently set in SetLatestCldDataFile.
64  static base::FilePath GetLatestCldDataFile();
65
66  DISALLOW_COPY_AND_ASSIGN(CldComponentInstallerTraits);
67};
68
69// Call once during startup to make the component update service aware of
70// the CLD component.
71void RegisterCldComponent(ComponentUpdateService* cus);
72
73}  // namespace component_updater
74
75#endif  // CHROME_BROWSER_COMPONENT_UPDATER_CLD_COMPONENT_INSTALLER_H_
76