Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_manager / private_api_base.cc
blob68e1246917260baf2023c1e2d9f666bd10d44fc3
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.
5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
9 #include "components/drive/event_logger.h"
11 namespace extensions {
12 namespace {
14 const int kSlowOperationThresholdMs = 500; // In ms.
16 } // namespace
18 LoggedAsyncExtensionFunction::LoggedAsyncExtensionFunction()
19 : log_on_completion_(false) {
20 start_time_ = base::Time::Now();
23 LoggedAsyncExtensionFunction::~LoggedAsyncExtensionFunction() {
26 void 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, "%s[%d] %s. (elapsed time: %sms)", name(),
32 request_id(), success ? "succeeded" : "failed",
33 base::Int64ToString(elapsed).c_str());
34 } else if (elapsed >= kSlowOperationThresholdMs) {
35 logger->Log(logging::LOG_WARNING,
36 "PEFORMANCE WARNING: %s[%d] was slow. (elapsed time: %sms)",
37 name(), request_id(), base::Int64ToString(elapsed).c_str());
40 ChromeAsyncExtensionFunction::SendResponse(success);
43 } // namespace extensions