Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / first_run / upgrade_util_linux.cc
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 #include "chrome/browser/first_run/upgrade_util.h"
6
7 #include "base/base_paths.h"
8 #include "base/command_line.h"
9 #include "base/file_util.h"
10 #include "base/files/file_path.h"
11 #include "base/logging.h"
12 #include "base/path_service.h"
13 #include "base/platform_file.h"
14 #include "base/process/launch.h"
15 #include "chrome/browser/first_run/upgrade_util_linux.h"
16
17 namespace {
18
19 double saved_last_modified_time_of_exe = 0;
20
21 }  // namespace
22
23 namespace upgrade_util {
24
25 bool RelaunchChromeBrowser(const CommandLine& command_line) {
26   base::LaunchOptions options;
27   // Don't set NO_NEW_PRIVS on the relaunched browser process.
28   options.allow_new_privs = true;
29   return base::LaunchProcess(command_line, options, NULL);
30 }
31
32 bool IsUpdatePendingRestart() {
33   return saved_last_modified_time_of_exe != GetLastModifiedTimeOfExe();
34 }
35
36 void SaveLastModifiedTimeOfExe() {
37   saved_last_modified_time_of_exe = GetLastModifiedTimeOfExe();
38 }
39
40 double GetLastModifiedTimeOfExe() {
41   base::FilePath exe_file_path;
42   if (!PathService::Get(base::FILE_EXE, &exe_file_path)) {
43     LOG(WARNING) << "Failed to get base::FilePath object for FILE_EXE.";
44     return saved_last_modified_time_of_exe;
45   }
46   base::File::Info exe_file_info;
47   if (!base::GetFileInfo(exe_file_path, &exe_file_info)) {
48     LOG(WARNING) << "Failed to get FileInfo object for FILE_EXE - "
49                  << exe_file_path.value();
50     return saved_last_modified_time_of_exe;
51   }
52   return exe_file_info.last_modified.ToDoubleT();
53 }
54
55 }  // namespace upgrade_util