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. ...@@ -18,32 +18,6 @@ const int kSlowOperationThresholdMs = 500; // In ms.
} // namespace } // 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() LoggedUIThreadExtensionFunction::LoggedUIThreadExtensionFunction()
: log_on_completion_(false) { : log_on_completion_(false) {
start_time_ = base::Time::Now(); start_time_ = base::Time::Now();
......
...@@ -8,43 +8,18 @@ ...@@ -8,43 +8,18 @@
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_BASE_H_ #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_BASE_H_
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "extensions/browser/extension_function.h" #include "extensions/browser/extension_function.h"
namespace extensions { 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(). // 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 // 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 // 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 // the logging is turned off, a warning is emitted when a function call is
// very slow. See the implementation of OnResponded() for details. // 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 { class LoggedUIThreadExtensionFunction : public UIThreadExtensionFunction {
public: public:
LoggedUIThreadExtensionFunction(); LoggedUIThreadExtensionFunction();
......
...@@ -39,7 +39,7 @@ struct EntryProperties; ...@@ -39,7 +39,7 @@ struct EntryProperties;
// Implements the chrome.fileManagerPrivate.ensureFileDownloaded method. // Implements the chrome.fileManagerPrivate.ensureFileDownloaded method.
class FileManagerPrivateInternalEnsureFileDownloadedFunction class FileManagerPrivateInternalEnsureFileDownloadedFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.ensureFileDownloaded", DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.ensureFileDownloaded",
FILEMANAGERPRIVATE_ENSUREFILEDOWNLOADED) FILEMANAGERPRIVATE_ENSUREFILEDOWNLOADED)
...@@ -47,11 +47,11 @@ class FileManagerPrivateInternalEnsureFileDownloadedFunction ...@@ -47,11 +47,11 @@ class FileManagerPrivateInternalEnsureFileDownloadedFunction
protected: protected:
~FileManagerPrivateInternalEnsureFileDownloadedFunction() override = default; ~FileManagerPrivateInternalEnsureFileDownloadedFunction() override = default;
// AsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() override;
private: private:
// Callback for RunAsync(). // Callback for Run().
void OnDownloadFinished(drive::FileError error, void OnDownloadFinished(drive::FileError error,
const base::FilePath& file_path, const base::FilePath& file_path,
std::unique_ptr<drive::ResourceEntry> entry); std::unique_ptr<drive::ResourceEntry> entry);
...@@ -61,7 +61,7 @@ class FileManagerPrivateInternalEnsureFileDownloadedFunction ...@@ -61,7 +61,7 @@ class FileManagerPrivateInternalEnsureFileDownloadedFunction
// On error, returns a dictionary with the key "error" set to the error number // On error, returns a dictionary with the key "error" set to the error number
// (base::File::Error). // (base::File::Error).
class FileManagerPrivateInternalGetEntryPropertiesFunction class FileManagerPrivateInternalGetEntryPropertiesFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getEntryProperties", DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getEntryProperties",
FILEMANAGERPRIVATEINTERNAL_GETENTRYPROPERTIES) FILEMANAGERPRIVATEINTERNAL_GETENTRYPROPERTIES)
...@@ -71,8 +71,8 @@ class FileManagerPrivateInternalGetEntryPropertiesFunction ...@@ -71,8 +71,8 @@ class FileManagerPrivateInternalGetEntryPropertiesFunction
protected: protected:
~FileManagerPrivateInternalGetEntryPropertiesFunction() override; ~FileManagerPrivateInternalGetEntryPropertiesFunction() override;
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() override;
private: private:
void CompleteGetEntryProperties( void CompleteGetEntryProperties(
...@@ -87,7 +87,7 @@ class FileManagerPrivateInternalGetEntryPropertiesFunction ...@@ -87,7 +87,7 @@ class FileManagerPrivateInternalGetEntryPropertiesFunction
// Implements the chrome.fileManagerPrivate.pinDriveFile method. // Implements the chrome.fileManagerPrivate.pinDriveFile method.
class FileManagerPrivateInternalPinDriveFileFunction class FileManagerPrivateInternalPinDriveFileFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.pinDriveFile", DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.pinDriveFile",
FILEMANAGERPRIVATEINTERNAL_PINDRIVEFILE) FILEMANAGERPRIVATEINTERNAL_PINDRIVEFILE)
...@@ -95,12 +95,13 @@ class FileManagerPrivateInternalPinDriveFileFunction ...@@ -95,12 +95,13 @@ class FileManagerPrivateInternalPinDriveFileFunction
protected: protected:
~FileManagerPrivateInternalPinDriveFileFunction() override = default; ~FileManagerPrivateInternalPinDriveFileFunction() override = default;
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() override;
private: private:
bool RunAsyncForDrive(const GURL& url, bool pin); ResponseAction RunAsyncForDrive(const GURL& url, bool pin);
bool RunAsyncForDriveFs(const storage::FileSystemURL& file_system_url, ResponseAction RunAsyncForDriveFs(
const storage::FileSystemURL& file_system_url,
bool pin); bool pin);
// Callback for RunAsyncForDrive() and RunAsyncForDriveFs. // Callback for RunAsyncForDrive() and RunAsyncForDriveFs.
...@@ -109,7 +110,7 @@ class FileManagerPrivateInternalPinDriveFileFunction ...@@ -109,7 +110,7 @@ class FileManagerPrivateInternalPinDriveFileFunction
// Implements the chrome.fileManagerPrivate.cancelFileTransfers method. // Implements the chrome.fileManagerPrivate.cancelFileTransfers method.
class FileManagerPrivateInternalCancelFileTransfersFunction class FileManagerPrivateInternalCancelFileTransfersFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.cancelFileTransfers", DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.cancelFileTransfers",
FILEMANAGERPRIVATEINTERNAL_CANCELFILETRANSFERS) FILEMANAGERPRIVATEINTERNAL_CANCELFILETRANSFERS)
...@@ -117,12 +118,12 @@ class FileManagerPrivateInternalCancelFileTransfersFunction ...@@ -117,12 +118,12 @@ class FileManagerPrivateInternalCancelFileTransfersFunction
protected: protected:
~FileManagerPrivateInternalCancelFileTransfersFunction() override = default; ~FileManagerPrivateInternalCancelFileTransfersFunction() override = default;
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() override;
}; };
class FileManagerPrivateSearchDriveFunction class FileManagerPrivateSearchDriveFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
typedef std::vector<drive::SearchResultInfo> SearchResultInfoList; typedef std::vector<drive::SearchResultInfo> SearchResultInfoList;
...@@ -132,7 +133,7 @@ class FileManagerPrivateSearchDriveFunction ...@@ -132,7 +133,7 @@ class FileManagerPrivateSearchDriveFunction
protected: protected:
~FileManagerPrivateSearchDriveFunction() override = default; ~FileManagerPrivateSearchDriveFunction() override = default;
bool RunAsync() override; ResponseAction Run() override;
private: private:
// Callback for Search(). // Callback for Search().
...@@ -158,7 +159,7 @@ class FileManagerPrivateSearchDriveFunction ...@@ -158,7 +159,7 @@ class FileManagerPrivateSearchDriveFunction
// Similar to FileManagerPrivateSearchDriveFunction but this one is used for // Similar to FileManagerPrivateSearchDriveFunction but this one is used for
// searching drive metadata which is stored locally. // searching drive metadata which is stored locally.
class FileManagerPrivateSearchDriveMetadataFunction class FileManagerPrivateSearchDriveMetadataFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
enum class SearchType { enum class SearchType {
kText, kText,
...@@ -172,7 +173,7 @@ class FileManagerPrivateSearchDriveMetadataFunction ...@@ -172,7 +173,7 @@ class FileManagerPrivateSearchDriveMetadataFunction
protected: protected:
~FileManagerPrivateSearchDriveMetadataFunction() override = default; ~FileManagerPrivateSearchDriveMetadataFunction() override = default;
bool RunAsync() override; ResponseAction Run() override;
private: private:
// Callback for SearchMetadata(); // Callback for SearchMetadata();
...@@ -211,7 +212,7 @@ class FileManagerPrivateGetDriveConnectionStateFunction ...@@ -211,7 +212,7 @@ class FileManagerPrivateGetDriveConnectionStateFunction
// Implements the chrome.fileManagerPrivate.requestAccessToken method. // Implements the chrome.fileManagerPrivate.requestAccessToken method.
class FileManagerPrivateRequestAccessTokenFunction class FileManagerPrivateRequestAccessTokenFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestAccessToken", DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestAccessToken",
FILEMANAGERPRIVATE_REQUESTACCESSTOKEN) FILEMANAGERPRIVATE_REQUESTACCESSTOKEN)
...@@ -219,8 +220,8 @@ class FileManagerPrivateRequestAccessTokenFunction ...@@ -219,8 +220,8 @@ class FileManagerPrivateRequestAccessTokenFunction
protected: protected:
~FileManagerPrivateRequestAccessTokenFunction() override = default; ~FileManagerPrivateRequestAccessTokenFunction() override = default;
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() override;
// Callback with a cached auth token (if available) or a fetched one. // Callback with a cached auth token (if available) or a fetched one.
void OnAccessTokenFetched(google_apis::DriveApiErrorCode code, void OnAccessTokenFetched(google_apis::DriveApiErrorCode code,
...@@ -229,14 +230,14 @@ class FileManagerPrivateRequestAccessTokenFunction ...@@ -229,14 +230,14 @@ class FileManagerPrivateRequestAccessTokenFunction
// Implements the chrome.fileManagerPrivate.requestDriveShare method. // Implements the chrome.fileManagerPrivate.requestDriveShare method.
class FileManagerPrivateInternalRequestDriveShareFunction class FileManagerPrivateInternalRequestDriveShareFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.requestDriveShare", DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.requestDriveShare",
FILEMANAGERPRIVATEINTERNAL_REQUESTDRIVESHARE) FILEMANAGERPRIVATEINTERNAL_REQUESTDRIVESHARE)
protected: protected:
~FileManagerPrivateInternalRequestDriveShareFunction() override = default; ~FileManagerPrivateInternalRequestDriveShareFunction() override = default;
bool RunAsync() override; ResponseAction Run() override;
private: private:
// Called back after the drive file system operation is finished. // Called back after the drive file system operation is finished.
...@@ -245,7 +246,7 @@ class FileManagerPrivateInternalRequestDriveShareFunction ...@@ -245,7 +246,7 @@ class FileManagerPrivateInternalRequestDriveShareFunction
// Implements the chrome.fileManagerPrivate.getDownloadUrl method. // Implements the chrome.fileManagerPrivate.getDownloadUrl method.
class FileManagerPrivateInternalGetDownloadUrlFunction class FileManagerPrivateInternalGetDownloadUrlFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
FileManagerPrivateInternalGetDownloadUrlFunction(); FileManagerPrivateInternalGetDownloadUrlFunction();
...@@ -255,11 +256,11 @@ class FileManagerPrivateInternalGetDownloadUrlFunction ...@@ -255,11 +256,11 @@ class FileManagerPrivateInternalGetDownloadUrlFunction
protected: protected:
~FileManagerPrivateInternalGetDownloadUrlFunction() override; ~FileManagerPrivateInternalGetDownloadUrlFunction() override;
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() override;
private: private:
bool RunAsyncForDrive(const GURL& url); ResponseAction RunAsyncForDrive(const GURL& url);
void OnGetResourceEntry(drive::FileError error, void OnGetResourceEntry(drive::FileError error,
std::unique_ptr<drive::ResourceEntry> entry); std::unique_ptr<drive::ResourceEntry> entry);
...@@ -271,7 +272,8 @@ class FileManagerPrivateInternalGetDownloadUrlFunction ...@@ -271,7 +272,8 @@ class FileManagerPrivateInternalGetDownloadUrlFunction
void OnTokenFetched(google_apis::DriveApiErrorCode code, void OnTokenFetched(google_apis::DriveApiErrorCode code,
const std::string& access_token); 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, void OnGotMetadata(drive::FileError error,
drivefs::mojom::FileMetadataPtr metadata); drivefs::mojom::FileMetadataPtr metadata);
...@@ -281,7 +283,7 @@ class FileManagerPrivateInternalGetDownloadUrlFunction ...@@ -281,7 +283,7 @@ class FileManagerPrivateInternalGetDownloadUrlFunction
}; };
class FileManagerPrivateInternalGetThumbnailFunction class FileManagerPrivateInternalGetThumbnailFunction
: public LoggedAsyncExtensionFunction { : public LoggedUIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getThumbnail", DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getThumbnail",
FILEMANAGERPRIVATEINTERNAL_GETTHUMBNAIL) FILEMANAGERPRIVATEINTERNAL_GETTHUMBNAIL)
...@@ -291,8 +293,8 @@ class FileManagerPrivateInternalGetThumbnailFunction ...@@ -291,8 +293,8 @@ class FileManagerPrivateInternalGetThumbnailFunction
protected: protected:
~FileManagerPrivateInternalGetThumbnailFunction() override; ~FileManagerPrivateInternalGetThumbnailFunction() override;
// ChromeAsyncExtensionFunction overrides. // ExtensionFunction overrides.
bool RunAsync() override; ResponseAction Run() override;
private: private:
void GotThumbnail(const base::Optional<std::vector<uint8_t>>& data); void GotThumbnail(const base::Optional<std::vector<uint8_t>>& data);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_STRINGS_H_ #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_STRINGS_H_
#define 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 { namespace extensions {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h" #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
#include "chrome/browser/chromeos/file_manager/file_tasks.h" #include "chrome/browser/chromeos/file_manager/file_tasks.h"
#include "chrome/browser/extensions/chrome_extension_function_details.h"
namespace base { namespace base {
class FilePath; 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