Home | History | Annotate | Download | only in file_manager
      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/drive/logging.h"
      9 
     10 namespace file_manager {
     11 namespace {
     12 
     13 const int kSlowOperationThresholdMs = 500;  // In ms.
     14 
     15 }  // namespace
     16 
     17 LoggedAsyncExtensionFunction::LoggedAsyncExtensionFunction()
     18     : log_on_completion_(false) {
     19   start_time_  = base::Time::Now();
     20 }
     21 
     22 LoggedAsyncExtensionFunction::~LoggedAsyncExtensionFunction() {
     23 }
     24 
     25 void LoggedAsyncExtensionFunction::SendResponse(bool success) {
     26   int64 elapsed = (base::Time::Now() - start_time_).InMilliseconds();
     27   if (log_on_completion_) {
     28     drive::util::Log(logging::LOG_INFO,
     29                      "%s[%d] %s. (elapsed time: %sms)",
     30                      name().c_str(),
     31                      request_id(),
     32                      success ? "succeeded" : "failed",
     33                      base::Int64ToString(elapsed).c_str());
     34   } else if (elapsed >= kSlowOperationThresholdMs) {
     35     drive::util::Log(
     36         logging::LOG_WARNING,
     37         "PEFORMANCE WARNING: %s[%d] was slow. (elapsed time: %sms)",
     38         name().c_str(),
     39         request_id(),
     40         base::Int64ToString(elapsed).c_str());
     41   }
     42 
     43   AsyncExtensionFunction::SendResponse(success);
     44 }
     45 
     46 }  // namespace file_manager
     47