Commit da525210 authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Migrate drive file manager APIs to UIThreadExtensionFunction.

Clean up all remaining uses of ChromeAsyncExtensionFunction.

BUG=934541

Change-Id: Ifaac83b48a5b09ae765d7bbc46d7ab99406abb9e
Reviewed-on: https://chromium-review.googlesource.com/c/1482273
Commit-Queue: Anand Mistry <amistry@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635387}
parent b0d924b3
......@@ -18,32 +18,6 @@ const int kSlowOperationThresholdMs = 500; // In ms.
} // namespace
LoggedAsyncExtensionFunction::LoggedAsyncExtensionFunction()
: log_on_completion_(false) {
start_time_ = base::Time::Now();
}
LoggedAsyncExtensionFunction::~LoggedAsyncExtensionFunction() = default;
void LoggedAsyncExtensionFunction::OnResponded() {
drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile());
if (logger) {
int64_t elapsed = (base::Time::Now() - start_time_).InMilliseconds();
DCHECK(response_type());
bool success = *response_type() == SUCCEEDED;
if (log_on_completion_) {
logger->Log(logging::LOG_INFO, "%s[%d] %s. (elapsed time: %sms)", name(),
request_id(), success ? "succeeded" : "failed",
base::NumberToString(elapsed).c_str());
} else if (elapsed >= kSlowOperationThresholdMs) {
logger->Log(logging::LOG_WARNING,
"PEFORMANCE WARNING: %s[%d] was slow. (elapsed time: %sms)",
name(), request_id(), base::NumberToString(elapsed).c_str());
}
}
ChromeAsyncExtensionFunction::OnResponded();
}
LoggedUIThreadExtensionFunction::LoggedUIThreadExtensionFunction()
: log_on_completion_(false) {
start_time_ = base::Time::Now();
......
......@@ -8,43 +8,18 @@
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_BASE_H_
#include "base/time/time.h"
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "extensions/browser/extension_function.h"
namespace extensions {
// This class adds a logging feature to ChromeAsyncExtensionFunction. Logging is
// This class adds a logging feature to UIThreadExtensionFunction. Logging is
// done when sending the response to JavaScript, using drive::util::Log().
// Async API functions of fileManagerPrivate should inherit this class.
// API functions of fileManagerPrivate should inherit this class.
//
// By default, logging is turned off, hence sub classes should call
// set_log_on_completion(true) to enable it, if they want. However, even if
// the logging is turned off, a warning is emitted when a function call is
// very slow. See the implementation of OnResponded() for details.
// TODO(crbug.com/934541): Remove this once all extension functions have been
// migrated to LoggedUIThreadExtensionFunction.
class LoggedAsyncExtensionFunction : public ChromeAsyncExtensionFunction {
public:
LoggedAsyncExtensionFunction();
protected:
~LoggedAsyncExtensionFunction() override;
// ChromeAsyncExtensionFunction overrides.
void OnResponded() override;
// Sets the logging on completion flag. By default, logging is turned off.
void set_log_on_completion(bool log_on_completion) {
log_on_completion_ = log_on_completion;
}
private:
base::Time start_time_;
bool log_on_completion_;
};
// This is the same class as above, but inheriting directly from
// UIThreadExtensionFunction instead.
class LoggedUIThreadExtensionFunction : public UIThreadExtensionFunction {
public:
LoggedUIThreadExtensionFunction();
......
......@@ -39,7 +39,7 @@ struct EntryProperties;
// Implements the chrome.fileManagerPrivate.ensureFileDownloaded method.
class FileManagerPrivateInternalEnsureFileDownloadedFunction
: public LoggedAsyncExtensionFunction {
: public LoggedUIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.ensureFileDownloaded",
FILEMANAGERPRIVATE_ENSUREFILEDOWNLOADED)
......@@ -47,11 +47,11 @@ class FileManagerPrivateInternalEnsureFileDownloadedFunction
protected:
~FileManagerPrivateInternalEnsureFileDownloadedFunction() override = default;
// AsyncExtensionFunction overrides.
bool RunAsync() override;
// ExtensionFunction overrides.
ResponseAction Run() override;
private:
// Callback for RunAsync().
// Callback for Run().
void OnDownloadFinished(drive::FileError error,
const base::FilePath& file_path,
std::unique_ptr<drive::ResourceEntry> entry);
......@@ -61,7 +61,7 @@ class FileManagerPrivateInternalEnsureFileDownloadedFunction
// On error, returns a dictionary with the key "error" set to the error number
// (base::File::Error).
class FileManagerPrivateInternalGetEntryPropertiesFunction
: public LoggedAsyncExtensionFunction {
: public LoggedUIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getEntryProperties",
FILEMANAGERPRIVATEINTERNAL_GETENTRYPROPERTIES)
......@@ -71,8 +71,8 @@ class FileManagerPrivateInternalGetEntryPropertiesFunction
protected:
~FileManagerPrivateInternalGetEntryPropertiesFunction() override;
// ChromeAsyncExtensionFunction overrides.
bool RunAsync() override;
// ExtensionFunction overrides.
ResponseAction Run() override;
private:
void CompleteGetEntryProperties(
......@@ -87,7 +87,7 @@ class FileManagerPrivateInternalGetEntryPropertiesFunction
// Implements the chrome.fileManagerPrivate.pinDriveFile method.
class FileManagerPrivateInternalPinDriveFileFunction
: public LoggedAsyncExtensionFunction {
: public LoggedUIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.pinDriveFile",
FILEMANAGERPRIVATEINTERNAL_PINDRIVEFILE)
......@@ -95,13 +95,14 @@ class FileManagerPrivateInternalPinDriveFileFunction
protected:
~FileManagerPrivateInternalPinDriveFileFunction() override = default;
// ChromeAsyncExtensionFunction overrides.
bool RunAsync() override;
// ExtensionFunction overrides.
ResponseAction Run() override;
private:
bool RunAsyncForDrive(const GURL& url, bool pin);
bool RunAsyncForDriveFs(const storage::FileSystemURL& file_system_url,
bool pin);
ResponseAction RunAsyncForDrive(const GURL& url, bool pin);
ResponseAction RunAsyncForDriveFs(
const storage::FileSystemURL& file_system_url,
bool pin);
// Callback for RunAsyncForDrive() and RunAsyncForDriveFs.
void OnPinStateSet(drive::FileError error);
......@@ -109,7 +110,7 @@ class FileManagerPrivateInternalPinDriveFileFunction
// Implements the chrome.fileManagerPrivate.cancelFileTransfers method.
class FileManagerPrivateInternalCancelFileTransfersFunction
: public LoggedAsyncExtensionFunction {
: public LoggedUIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.cancelFileTransfers",
FILEMANAGERPRIVATEINTERNAL_CANCELFILETRANSFERS)
......@@ -117,12 +118,12 @@ class FileManagerPrivateInternalCancelFileTransfersFunction
protected:
~FileManagerPrivateInternalCancelFileTransfersFunction() override = default;
// ChromeAsyncExtensionFunction overrides.
bool RunAsync() override;
// ExtensionFunction overrides.
ResponseAction Run() override;
};
class FileManagerPrivateSearchDriveFunction
: public LoggedAsyncExtensionFunction {
: public LoggedUIThreadExtensionFunction {
public:
typedef std::vector<drive::SearchResultInfo> SearchResultInfoList;
......@@ -132,7 +133,7 @@ class FileManagerPrivateSearchDriveFunction
protected:
~FileManagerPrivateSearchDriveFunction() override = default;
bool RunAsync() override;
ResponseAction Run() override;
private:
// Callback for Search().
......@@ -158,7 +159,7 @@ class FileManagerPrivateSearchDriveFunction
// Similar to FileManagerPrivateSearchDriveFunction but this one is used for
// searching drive metadata which is stored locally.
class FileManagerPrivateSearchDriveMetadataFunction
: public LoggedAsyncExtensionFunction {
: public LoggedUIThreadExtensionFunction {
public:
enum class SearchType {
kText,
......@@ -172,7 +173,7 @@ class FileManagerPrivateSearchDriveMetadataFunction
protected:
~FileManagerPrivateSearchDriveMetadataFunction() override = default;
bool RunAsync() override;
ResponseAction Run() override;
private:
// Callback for SearchMetadata();
......@@ -211,7 +212,7 @@ class FileManagerPrivateGetDriveConnectionStateFunction
// Implements the chrome.fileManagerPrivate.requestAccessToken method.
class FileManagerPrivateRequestAccessTokenFunction
: public LoggedAsyncExtensionFunction {
: public LoggedUIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestAccessToken",
FILEMANAGERPRIVATE_REQUESTACCESSTOKEN)
......@@ -219,8 +220,8 @@ class FileManagerPrivateRequestAccessTokenFunction
protected:
~FileManagerPrivateRequestAccessTokenFunction() override = default;
// ChromeAsyncExtensionFunction overrides.
bool RunAsync() override;
// ExtensionFunction overrides.
ResponseAction Run() override;
// Callback with a cached auth token (if available) or a fetched one.
void OnAccessTokenFetched(google_apis::DriveApiErrorCode code,
......@@ -229,14 +230,14 @@ class FileManagerPrivateRequestAccessTokenFunction
// Implements the chrome.fileManagerPrivate.requestDriveShare method.
class FileManagerPrivateInternalRequestDriveShareFunction
: public LoggedAsyncExtensionFunction {
: public LoggedUIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.requestDriveShare",
FILEMANAGERPRIVATEINTERNAL_REQUESTDRIVESHARE)
protected:
~FileManagerPrivateInternalRequestDriveShareFunction() override = default;
bool RunAsync() override;
ResponseAction Run() override;
private:
// Called back after the drive file system operation is finished.
......@@ -245,7 +246,7 @@ class FileManagerPrivateInternalRequestDriveShareFunction
// Implements the chrome.fileManagerPrivate.getDownloadUrl method.
class FileManagerPrivateInternalGetDownloadUrlFunction
: public LoggedAsyncExtensionFunction {
: public LoggedUIThreadExtensionFunction {
public:
FileManagerPrivateInternalGetDownloadUrlFunction();
......@@ -255,11 +256,11 @@ class FileManagerPrivateInternalGetDownloadUrlFunction
protected:
~FileManagerPrivateInternalGetDownloadUrlFunction() override;
// ChromeAsyncExtensionFunction overrides.
bool RunAsync() override;
// ExtensionFunction overrides.
ResponseAction Run() override;
private:
bool RunAsyncForDrive(const GURL& url);
ResponseAction RunAsyncForDrive(const GURL& url);
void OnGetResourceEntry(drive::FileError error,
std::unique_ptr<drive::ResourceEntry> entry);
......@@ -271,7 +272,8 @@ class FileManagerPrivateInternalGetDownloadUrlFunction
void OnTokenFetched(google_apis::DriveApiErrorCode code,
const std::string& access_token);
bool RunAsyncForDriveFs(const storage::FileSystemURL& file_system_url);
ResponseAction RunAsyncForDriveFs(
const storage::FileSystemURL& file_system_url);
void OnGotMetadata(drive::FileError error,
drivefs::mojom::FileMetadataPtr metadata);
......@@ -281,7 +283,7 @@ class FileManagerPrivateInternalGetDownloadUrlFunction
};
class FileManagerPrivateInternalGetThumbnailFunction
: public LoggedAsyncExtensionFunction {
: public LoggedUIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getThumbnail",
FILEMANAGERPRIVATEINTERNAL_GETTHUMBNAIL)
......@@ -291,8 +293,8 @@ class FileManagerPrivateInternalGetThumbnailFunction
protected:
~FileManagerPrivateInternalGetThumbnailFunction() override;
// ChromeAsyncExtensionFunction overrides.
bool RunAsync() override;
// ExtensionFunction overrides.
ResponseAction Run() override;
private:
void GotThumbnail(const base::Optional<std::vector<uint8_t>>& data);
......
......@@ -7,7 +7,7 @@
#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_STRINGS_H_
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_STRINGS_H_
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "extensions/browser/extension_function.h"
namespace extensions {
......
......@@ -14,6 +14,7 @@
#include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
#include "chrome/browser/chromeos/file_manager/file_tasks.h"
#include "chrome/browser/extensions/chrome_extension_function_details.h"
namespace base {
class FilePath;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment