| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/component_updater/caps_installer_win.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 #include <utility> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/bind.h" | |
| 14 #include "base/command_line.h" | |
| 15 #include "base/files/file_path.h" | |
| 16 #include "base/files/file_util.h" | |
| 17 #include "base/macros.h" | |
| 18 #include "base/metrics/histogram.h" | |
| 19 #include "base/path_service.h" | |
| 20 #include "base/process/launch.h" | |
| 21 #include "base/threading/worker_pool.h" | |
| 22 #include "base/time/time.h" | |
| 23 #include "chrome/common/chrome_paths.h" | |
| 24 #include "components/component_updater/component_updater_service.h" | |
| 25 #include "components/component_updater/default_component_installer.h" | |
| 26 | |
| 27 namespace component_updater { | |
| 28 | |
| 29 namespace { | |
| 30 | |
| 31 // The values of the enum cannot be changed and should be mirrored with | |
| 32 // the values of CAPSUpdaterStep in metrics/histograms/histograms.xml. Only | |
| 33 // add new values at the end. | |
| 34 enum CAPSUmaValue { | |
| 35 CAPS_COMPONENT_READY = 0, | |
| 36 CAPS_COMPONENT_MISSING = 1, | |
| 37 CAPS_SERVICE_FAILED_TO_START = 2, | |
| 38 CAPS_SERVICE_STARTED = 3, | |
| 39 CAPS_UMA_MAX | |
| 40 }; | |
| 41 | |
| 42 void ReportUmaStep(CAPSUmaValue value) { | |
| 43 UMA_HISTOGRAM_ENUMERATION("CAPSUpdater.Step", value, CAPS_UMA_MAX); | |
| 44 } | |
| 45 | |
| 46 // CRX hash. The extension id is: bcpgokokgekmnfkohklccmonnakdimfh. | |
| 47 const uint8_t kSha256Hash[] = {0x12, 0xf6, 0xea, 0xea, 0x64, 0xac, 0xd5, 0xae, | |
| 48 0x7a, 0xb2, 0x2c, 0xed, 0xd0, 0xa3, 0x8c, 0x57, | |
| 49 0x49, 0x05, 0x8f, 0x7d, 0x14, 0xa4, 0x22, 0x4d, | |
| 50 0x9b, 0xf6, 0x14, 0x99, 0xdf, 0xf8, 0xc9, 0xb3}; | |
| 51 | |
| 52 const base::FilePath::CharType kCapsBinary[] = | |
| 53 FILE_PATH_LITERAL("chrome_crash_svc.exe"); | |
| 54 | |
| 55 // This function is called from a worker thread to launch crash service. | |
| 56 void LaunchService(const base::FilePath& exe_path) { | |
| 57 base::CommandLine service_cmdline(exe_path); | |
| 58 service_cmdline.AppendSwitch("caps-update"); | |
| 59 base::Process service = | |
| 60 base::LaunchProcess(service_cmdline, base::LaunchOptions()); | |
| 61 CAPSUmaValue uma_step = service.IsValid() ? | |
| 62 CAPS_SERVICE_STARTED : CAPS_SERVICE_FAILED_TO_START; | |
| 63 ReportUmaStep(uma_step); | |
| 64 } | |
| 65 | |
| 66 class CAPSInstallerTraits : public ComponentInstallerTraits { | |
| 67 public: | |
| 68 CAPSInstallerTraits() {} | |
| 69 ~CAPSInstallerTraits() override {} | |
| 70 | |
| 71 bool VerifyInstallation(const base::DictionaryValue& manifest, | |
| 72 const base::FilePath& dir) const override { | |
| 73 bool has_binary = base::PathExists(dir.Append(kCapsBinary)); | |
| 74 ReportUmaStep(has_binary ? CAPS_COMPONENT_READY : CAPS_COMPONENT_MISSING); | |
| 75 return has_binary; | |
| 76 } | |
| 77 | |
| 78 bool SupportsGroupPolicyEnabledComponentUpdates() const override { | |
| 79 return false; | |
| 80 } | |
| 81 | |
| 82 bool RequiresNetworkEncryption() const override { return false; } | |
| 83 | |
| 84 bool OnCustomInstall(const base::DictionaryValue& manifest, | |
| 85 const base::FilePath& install_dir) override { | |
| 86 return true; | |
| 87 } | |
| 88 | |
| 89 void ComponentReady( | |
| 90 const base::Version& version, | |
| 91 const base::FilePath& install_dir, | |
| 92 std::unique_ptr<base::DictionaryValue> manifest) override { | |
| 93 // Can't block here. This is usually the browser UI thread. | |
| 94 base::WorkerPool::PostTask( | |
| 95 FROM_HERE, | |
| 96 base::Bind(&LaunchService, install_dir.Append(kCapsBinary)), | |
| 97 false); | |
| 98 } | |
| 99 | |
| 100 // Directory is usually "%appdata%\Local\Chrome\User Data\Caps". | |
| 101 base::FilePath GetRelativeInstallDir() const override { | |
| 102 return base::FilePath(FILE_PATH_LITERAL("Caps")); | |
| 103 } | |
| 104 | |
| 105 void GetHash(std::vector<uint8_t>* hash) const override { | |
| 106 hash->assign(kSha256Hash, | |
| 107 kSha256Hash + arraysize(kSha256Hash)); | |
| 108 } | |
| 109 | |
| 110 // This string is shown in chrome://components. | |
| 111 std::string GetName() const override { return "Chrome Crash Service"; } | |
| 112 | |
| 113 update_client::InstallerAttributes GetInstallerAttributes() const override { | |
| 114 return update_client::InstallerAttributes(); | |
| 115 } | |
| 116 | |
| 117 std::vector<std::string> GetMimeTypes() const override { | |
| 118 return std::vector<std::string>(); | |
| 119 } | |
| 120 }; | |
| 121 | |
| 122 } // namespace | |
| 123 | |
| 124 void RegisterCAPSComponent(ComponentUpdateService* cus) { | |
| 125 // The component updater takes ownership of |installer|. | |
| 126 std::unique_ptr<ComponentInstallerTraits> traits(new CAPSInstallerTraits()); | |
| 127 DefaultComponentInstaller* installer = | |
| 128 new DefaultComponentInstaller(std::move(traits)); | |
| 129 installer->Register(cus, base::Closure()); | |
| 130 } | |
| 131 | |
| 132 } // namespace component_updater | |
| OLD | NEW |