configuration.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/mini_installer/configuration.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <windows.h> 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <shellapi.h> // NOLINT 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/installer/mini_installer/appid.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace mini_installer { 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Configuration::Configuration() : args_(NULL) { 151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci Clear(); 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Configuration::~Configuration() { 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Clear(); 20} 21 22const wchar_t* Configuration::program() const { 23 return args_ == NULL || argument_count_ < 1 ? NULL : args_[0]; 24} 25 26void Configuration::Clear() { 27 if (args_ != NULL) { 28 ::LocalFree(args_); 29 args_ = NULL; 30 } 31 chrome_app_guid_ = google_update::kAppGuid; 32 command_line_ = NULL; 33 operation_ = INSTALL_PRODUCT; 34 argument_count_ = 0; 35 has_chrome_ = false; 36 has_chrome_frame_ = false; 37 has_app_host_ = false; 38 is_multi_install_ = false; 39 is_system_level_ = false; 40} 41 42bool Configuration::Initialize() { 43 return InitializeFromCommandLine(::GetCommandLine()); 44} 45 46// This is its own function so that unit tests can provide their own command 47// lines. |command_line| is shared with this instance in the sense that this 48// instance may refer to it at will throughout its lifetime, yet it will 49// not release it. 50bool Configuration::InitializeFromCommandLine(const wchar_t* command_line) { 51 Clear(); 52 53 command_line_ = command_line; 54 args_ = ::CommandLineToArgvW(command_line_, &argument_count_); 55 if (args_ != NULL) { 56 for (int i = 1; i < argument_count_; ++i) { 57 if (0 == ::lstrcmpi(args_[i], L"--chrome-sxs")) 58 chrome_app_guid_ = google_update::kSxSAppGuid; 59 else if (0 == ::lstrcmpi(args_[i], L"--chrome")) 60 has_chrome_ = true; 61 else if (0 == ::lstrcmpi(args_[i], L"--chrome-frame")) 62 has_chrome_frame_ = true; 63 else if ((0 == ::lstrcmpi(args_[i], L"--app-host")) || 64 (0 == ::lstrcmpi(args_[i], L"--app-launcher"))) 65 has_app_host_ = true; 66 else if (0 == ::lstrcmpi(args_[i], L"--multi-install")) 67 is_multi_install_ = true; 68 else if (0 == ::lstrcmpi(args_[i], L"--system-level")) 69 is_system_level_ = true; 70 else if (0 == ::lstrcmpi(args_[i], L"--cleanup")) 71 operation_ = CLEANUP; 72 } 73 74 // Single-install defaults to Chrome. 75 if (!is_multi_install_) 76 has_chrome_ = !(has_chrome_frame_ || has_app_host_); 77 } 78 return args_ != NULL; 79} 80 81} // namespace mini_installer 82