15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 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)#ifndef CHROME_INSTALLER_UTIL_LOGGING_INSTALLER_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_INSTALLER_UTIL_LOGGING_INSTALLER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace base { 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FilePath; 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace installer { 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MasterPreferences; 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Verbose installer runs clock in at around 50K, non-verbose much less than 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// that. Some installer operations span multiple setup.exe runs, so we try 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to keep enough for at least 10 runs or so at any given time. 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kMaxInstallerLogFileSize = 1024 * 1024; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Truncate the file down to half of the max, such that we don't incur 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// truncation on every update. 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kTruncatedInstallerLogFileSize = kMaxInstallerLogFileSize / 2; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)COMPILE_ASSERT(kTruncatedInstallerLogFileSize < kMaxInstallerLogFileSize, 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) kTruncatedInstallerLogFileSize_not_lt_kMaxInstallerLogFileSize); 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum TruncateResult { 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOGFILE_UNTOUCHED, 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOGFILE_TRUNCATED, 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOGFILE_DELETED, 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Cuts off the _beginning_ of the file at |log_file| down to 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// kTruncatedInstallerLogFileSize if it exceeds kMaxInstallerLogFileSize bytes. 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If the file is not changed, returns LOGFILE_UNTOUCHED. 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If the file is successfully truncated, returns LOGFILE_TRUNCATED. 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If the file needed truncation, but the truncation failed, the file will be 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// deleted and the function returns LOGFILE_DELETED. This is done to prevent 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// run-away log files and guard against full disks. 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TruncateResult TruncateLogFileIfNeeded(const base::FilePath& log_file); 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Call to initialize logging for Chrome installer. 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void InitInstallerLogging(const installer::MasterPreferences& prefs); 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Call when done using logging for Chrome installer. 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void EndInstallerLogging(); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the full path of the log file. 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)base::FilePath GetLogFilePath(const installer::MasterPreferences& prefs); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace installer 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_INSTALLER_UTIL_LOGGING_INSTALLER_H_ 58