OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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/extensions/app_host/binaries_installer.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/threading/platform_thread.h" |
| 9 #include "base/win/scoped_bstr.h" |
| 10 #include "base/win/scoped_com_initializer.h" |
| 11 #include "base/win/scoped_comptr.h" |
| 12 #include "chrome/browser/extensions/app_host/binaries_installer_internal.h" |
| 13 #include "google_update/google_update_idl.h" |
| 14 |
| 15 using base::win::ScopedBstr; |
| 16 using base::win::ScopedComPtr; |
| 17 |
| 18 namespace app_host { |
| 19 |
| 20 namespace { |
| 21 const int kInstallationPollingIntervalMs = 50; |
| 22 } // namespace |
| 23 |
| 24 // Attempts to install the Chrome Binaries using the IGoogleUpdate3 interface. |
| 25 // Blocks until the installation process completes, without message pumping. |
| 26 HRESULT InstallBinaries() { |
| 27 base::win::ScopedCOMInitializer initialize_com; |
| 28 |
| 29 HRESULT hr = S_OK; |
| 30 if (!initialize_com.succeeded()) { |
| 31 LOG(ERROR) << "COM initialization failed"; |
| 32 hr = E_FAIL; |
| 33 } |
| 34 |
| 35 ScopedComPtr<IGoogleUpdate3> update3; |
| 36 if (SUCCEEDED(hr)) { |
| 37 hr = internal::CreateGoogleUpdate3(update3.Receive()); |
| 38 } |
| 39 |
| 40 ScopedBstr ap_value; |
| 41 if (SUCCEEDED(hr)) { |
| 42 hr = internal::SelectBinariesApValue(update3, ap_value.Receive()); |
| 43 } |
| 44 |
| 45 ScopedComPtr<IAppBundle> app_bundle; |
| 46 if (SUCCEEDED(hr)) { |
| 47 hr = internal::CreateAppBundle(update3, app_bundle.Receive()); |
| 48 } |
| 49 |
| 50 ScopedComPtr<IApp> app; |
| 51 if (SUCCEEDED(hr)) { |
| 52 hr = internal::CreateBinariesIApp(app_bundle, ap_value, app.Receive()); |
| 53 } |
| 54 |
| 55 if (SUCCEEDED(hr)) { |
| 56 hr = app_bundle->checkForUpdate(); |
| 57 if (FAILED(hr)) { |
| 58 LOG(ERROR) << "Failed to initiate update check: " << hr; |
| 59 } |
| 60 } |
| 61 |
| 62 if (SUCCEEDED(hr)) { |
| 63 // We rely upon Omaha to eventually time out and transition to a failure |
| 64 // state. |
| 65 while (!internal::CheckIfDone(app_bundle, app, &hr)) { |
| 66 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( |
| 67 kInstallationPollingIntervalMs)); |
| 68 } |
| 69 } |
| 70 |
| 71 return hr; |
| 72 } |
| 73 |
| 74 } // namespace app_host |
OLD | NEW |