1 // Copyright (c) 2011 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_INSTALLER_UTIL_LOGGING_INSTALLER_H_ 6 #define CHROME_INSTALLER_UTIL_LOGGING_INSTALLER_H_ 7 8 #include "base/basictypes.h" 9 10 namespace base { 11 class FilePath; 12 } 13 14 namespace installer { 15 16 class MasterPreferences; 17 18 // Verbose installer runs clock in at around 50K, non-verbose much less than 19 // that. Some installer operations span multiple setup.exe runs, so we try 20 // to keep enough for at least 10 runs or so at any given time. 21 const int kMaxInstallerLogFileSize = 1024 * 1024; 22 23 // Truncate the file down to half of the max, such that we don't incur 24 // truncation on every update. 25 const int kTruncatedInstallerLogFileSize = kMaxInstallerLogFileSize / 2; 26 27 COMPILE_ASSERT(kTruncatedInstallerLogFileSize < kMaxInstallerLogFileSize, 28 kTruncatedInstallerLogFileSize_not_lt_kMaxInstallerLogFileSize); 29 30 enum TruncateResult { 31 LOGFILE_UNTOUCHED, 32 LOGFILE_TRUNCATED, 33 LOGFILE_DELETED, 34 }; 35 36 // Cuts off the _beginning_ of the file at |log_file| down to 37 // kTruncatedInstallerLogFileSize if it exceeds kMaxInstallerLogFileSize bytes. 38 // 39 // If the file is not changed, returns LOGFILE_UNTOUCHED. 40 // If the file is successfully truncated, returns LOGFILE_TRUNCATED. 41 // If the file needed truncation, but the truncation failed, the file will be 42 // deleted and the function returns LOGFILE_DELETED. This is done to prevent 43 // run-away log files and guard against full disks. 44 TruncateResult TruncateLogFileIfNeeded(const base::FilePath& log_file); 45 46 // Call to initialize logging for Chrome installer. 47 void InitInstallerLogging(const installer::MasterPreferences& prefs); 48 49 // Call when done using logging for Chrome installer. 50 void EndInstallerLogging(); 51 52 // Returns the full path of the log file. 53 base::FilePath GetLogFilePath(const installer::MasterPreferences& prefs); 54 55 } // namespace installer 56 57 #endif // CHROME_INSTALLER_UTIL_LOGGING_INSTALLER_H_ 58