15c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Copyright 2014 The Chromium Authors. All rights reserved.
25c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Use of this source code is governed by a BSD-style license that can be
35c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// found in the LICENSE file.
45c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
55c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#ifndef CHROME_BROWSER_COMPONENT_UPDATER_CLD_COMPONENT_INSTALLER_H_
65c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define CHROME_BROWSER_COMPONENT_UPDATER_CLD_COMPONENT_INSTALLER_H_
75c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include <stdint.h>
9cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include <string>
10cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include <vector>
11cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "base/files/file_path.h"
13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/gtest_prod_util.h"
141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/macros.h"
1503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/component_updater/default_component_installer.h"
16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)namespace test {
18116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass ComponentCldDataHarness;
19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}  // namespace test
205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
215c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liunamespace component_updater {
225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuclass ComponentUpdateService;
245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Visible for testing. No need to instantiate this class directly.
26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class CldComponentInstallerTraits : public ComponentInstallerTraits {
27cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) public:
28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  CldComponentInstallerTraits();
29cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual ~CldComponentInstallerTraits() {}
30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) private:
32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  friend class CldComponentInstallerTest;  // For access within SetUp()
33116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  friend class test::ComponentCldDataHarness;  // For browser tests only
34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, ComponentReady);
35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, GetBaseDirectory);
36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, GetHash);
37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, GetInstalledPath);
38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, GetName);
39cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, OnCustomInstall);
40cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, SetLatestCldDataFile);
41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CldComponentInstallerTest, VerifyInstallation);
42cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
43cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // The following methods override ComponentInstallerTraits.
44cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual bool CanAutoUpdate() const OVERRIDE;
45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual bool OnCustomInstall(const base::DictionaryValue& manifest,
46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                               const base::FilePath& install_dir) OVERRIDE;
47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual bool VerifyInstallation(
48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const base::FilePath& install_dir) const OVERRIDE;
49cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void ComponentReady(
50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const base::Version& version,
51cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const base::FilePath& path,
52cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      scoped_ptr<base::DictionaryValue> manifest) OVERRIDE;
53cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual base::FilePath GetBaseDirectory() const OVERRIDE;
541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void GetHash(std::vector<uint8_t>* hash) const OVERRIDE;
55cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual std::string GetName() const OVERRIDE;
56cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
57cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  static base::FilePath GetInstalledPath(const base::FilePath& base);
58116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
59116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Sets the path to the CLD data file. Called internally once a valid CLD
60116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // data file has been observed. The implementation of this method is
61116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // responsible for configuring the CLD data source.
62116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // This method is threadsafe.
63cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  static void SetLatestCldDataFile(const base::FilePath& path);
64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Returns the file path that was most recently set in SetLatestCldDataFile.
665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  static base::FilePath GetLatestCldDataFile();
675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
68cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(CldComponentInstallerTraits);
69cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)};
70cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
71cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Call once during startup to make the component update service aware of
72cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// the CLD component.
735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuvoid RegisterCldComponent(ComponentUpdateService* cus);
745c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
755c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu}  // namespace component_updater
765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
775c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#endif  // CHROME_BROWSER_COMPONENT_UPDATER_CLD_COMPONENT_INSTALLER_H_
78