| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/browser_watcher/exit_funnel_win.h" | 5 #include "components/browser_watcher/exit_funnel_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 base::ProcessId pid = base::GetProcId(process_handle); | 24 base::ProcessId pid = base::GetProcId(process_handle); |
| 25 | 25 |
| 26 FILETIME creation_time = {}; | 26 FILETIME creation_time = {}; |
| 27 FILETIME dummy = {}; | 27 FILETIME dummy = {}; |
| 28 if (!::GetProcessTimes(process_handle, &creation_time, | 28 if (!::GetProcessTimes(process_handle, &creation_time, |
| 29 &dummy, &dummy, &dummy)) { | 29 &dummy, &dummy, &dummy)) { |
| 30 LOG(ERROR) << "Invalid process handle, can't get process times."; | 30 LOG(ERROR) << "Invalid process handle, can't get process times."; |
| 31 return false; | 31 return false; |
| 32 } | 32 } |
| 33 | 33 |
| 34 return InitImpl(registry_path, pid, base::Time::FromFileTime(creation_time)); |
| 35 } |
| 36 |
| 37 bool ExitFunnel::InitImpl(const base::char16* registry_path, |
| 38 base::ProcessId pid, |
| 39 base::Time creation_time) { |
| 34 base::string16 key_name = registry_path; | 40 base::string16 key_name = registry_path; |
| 35 base::StringAppendF(&key_name, L"\\%d-%lld", pid, | 41 base::StringAppendF( |
| 36 base::Time::FromFileTime(creation_time).ToInternalValue()); | 42 &key_name, L"\\%d-%lld", pid, creation_time.ToInternalValue()); |
| 37 | 43 |
| 38 LONG res = key_.Create(HKEY_CURRENT_USER, key_name.c_str(), KEY_SET_VALUE); | 44 LONG res = key_.Create(HKEY_CURRENT_USER, key_name.c_str(), KEY_SET_VALUE); |
| 39 if (res != ERROR_SUCCESS) { | 45 if (res != ERROR_SUCCESS) { |
| 40 LOG(ERROR) << "Unable to create key " << key_name << " error " << res; | 46 LOG(ERROR) << "Unable to create key " << key_name << " error " << res; |
| 41 return false; | 47 return false; |
| 42 } | 48 } |
| 43 | 49 |
| 44 return true; | 50 return true; |
| 45 } | 51 } |
| 46 | 52 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 63 const base::char16* event_name) { | 69 const base::char16* event_name) { |
| 64 ExitFunnel funnel; | 70 ExitFunnel funnel; |
| 65 | 71 |
| 66 if (!funnel.Init(registry_path, base::GetCurrentProcessHandle())) | 72 if (!funnel.Init(registry_path, base::GetCurrentProcessHandle())) |
| 67 return false; | 73 return false; |
| 68 | 74 |
| 69 return funnel.RecordEvent(event_name); | 75 return funnel.RecordEvent(event_name); |
| 70 } | 76 } |
| 71 | 77 |
| 72 } // namespace browser_watcher | 78 } // namespace browser_watcher |
| OLD | NEW |