1// Copyright 2013 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/chromeos/extensions/file_manager/private_api_base.h"
6
7#include "base/strings/string_number_conversions.h"
8#include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
9#include "chrome/browser/drive/event_logger.h"
10
11namespace extensions {
12namespace {
13
14const int kSlowOperationThresholdMs = 500;  // In ms.
15
16}  // namespace
17
18LoggedAsyncExtensionFunction::LoggedAsyncExtensionFunction()
19    : log_on_completion_(false) {
20  start_time_  = base::Time::Now();
21}
22
23LoggedAsyncExtensionFunction::~LoggedAsyncExtensionFunction() {
24}
25
26void LoggedAsyncExtensionFunction::SendResponse(bool success) {
27  drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile());
28  if (logger) {
29    int64 elapsed = (base::Time::Now() - start_time_).InMilliseconds();
30    if (log_on_completion_) {
31      logger->Log(logging::LOG_INFO,
32                  "%s[%d] %s. (elapsed time: %sms)",
33                  name().c_str(),
34                  request_id(),
35                  success ? "succeeded" : "failed",
36                  base::Int64ToString(elapsed).c_str());
37    } else if (elapsed >= kSlowOperationThresholdMs) {
38      logger->Log(
39          logging::LOG_WARNING,
40          "PEFORMANCE WARNING: %s[%d] was slow. (elapsed time: %sms)",
41          name().c_str(),
42          request_id(),
43          base::Int64ToString(elapsed).c_str());
44    }
45  }
46  ChromeAsyncExtensionFunction::SendResponse(success);
47}
48
49}  // namespace extensions
50