Skip to content

Commit

Permalink
Change Results::Create() return type in json_schema_compiler.
Browse files Browse the repository at this point in the history
Return std::vector<base::Value> instead of
std::unique_ptr<base::ListValue>. Then update affected extensions code
to either switch to std::vector<base::Value>, or add adaptor calls.

Bug: 1139221
Change-Id: Ib37969dda8d84fb71663d7ed213ee02a3900a160
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2496181
Reviewed-by: Luke Halliwell <halliwell@chromium.org>
Reviewed-by: Devlin <rdevlin.cronin@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#884057}
  • Loading branch information
leizleiz authored and Chromium LUCI CQ committed May 18, 2021
1 parent 33de34b commit d380dd2
Show file tree
Hide file tree
Showing 58 changed files with 274 additions and 278 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void MediaGalleriesEventRouter::DispatchEventToExtension(
const std::string& extension_id,
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> event_args) {
std::vector<base::Value> event_args) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);

extensions::EventRouter* router = extensions::EventRouter::Get(profile_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class MediaGalleriesEventRouter : public extensions::BrowserContextKeyedAPI,
const std::string& extension_id,
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> event_args);
std::vector<base::Value> event_args);

explicit MediaGalleriesEventRouter(content::BrowserContext* context);
~MediaGalleriesEventRouter() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,23 @@ void ExtensionSyncEventObserver::OnFileSynced(
::sync_file_system::SyncFileStatus status,
::sync_file_system::SyncAction action,
::sync_file_system::SyncDirection direction) {
std::unique_ptr<base::ListValue> params(new base::ListValue());
std::vector<base::Value> params;

std::unique_ptr<base::DictionaryValue> entry =
CreateDictionaryValueForFileSystemEntry(url, file_type);
if (!entry)
return;
params->Append(std::move(entry));
params.push_back(base::Value::FromUniquePtrValue(std::move(entry)));

// Status, SyncAction and any optional notes to go here.
sync_file_system::FileStatus status_enum =
SyncFileStatusToExtensionEnum(status);
sync_file_system::SyncAction action_enum = SyncActionToExtensionEnum(action);
sync_file_system::SyncDirection direction_enum =
SyncDirectionToExtensionEnum(direction);
params->AppendString(sync_file_system::ToString(status_enum));
params->AppendString(sync_file_system::ToString(action_enum));
params->AppendString(sync_file_system::ToString(direction_enum));
params.push_back(base::Value(sync_file_system::ToString(status_enum)));
params.push_back(base::Value(sync_file_system::ToString(action_enum)));
params.push_back(base::Value(sync_file_system::ToString(direction_enum)));

BroadcastOrDispatchEvent(
url.origin().GetURL(),
Expand All @@ -120,7 +120,7 @@ void ExtensionSyncEventObserver::BroadcastOrDispatchEvent(
const GURL& app_origin,
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> values) {
std::vector<base::Value> values) {
// Check to see whether the event should be broadcasted to all listening
// extensions or sent to a specific extension ID.
bool broadcast_mode = app_origin.is_empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#ifndef CHROME_BROWSER_APPS_PLATFORM_APPS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_OBSERVER_H_
#define CHROME_BROWSER_APPS_PLATFORM_APPS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_OBSERVER_H_

#include <memory>
#include <string>
#include <vector>

#include "base/compiler_specific.h"
#include "base/values.h"
Expand Down Expand Up @@ -76,7 +76,7 @@ class ExtensionSyncEventObserver : public sync_file_system::SyncEventObserver,
const GURL& app_origin,
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> value);
std::vector<base::Value> value);
};

} // namespace api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void Operation::SetDispatchEventImplForTesting(
bool Operation::SendEvent(int request_id,
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> event_args) {
std::vector<base::Value> event_args) {
return dispatch_event_impl_.Run(std::make_unique<extensions::Event>(
histogram_value, event_name, std::move(event_args)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@

#include <memory>
#include <string>
#include <vector>

#include "base/files/file.h"
#include "base/macros.h"
#include "base/values.h"
#include "chrome/browser/ash/file_system_provider/provided_file_system_info.h"
#include "chrome/browser/ash/file_system_provider/request_manager.h"
#include "extensions/browser/extension_event_histogram_value.h"
#include "storage/browser/file_system/async_file_util.h"

namespace base {
class ListValue;
} // namespace base

namespace extensions {
struct Event;
class EventRouter;
Expand Down Expand Up @@ -57,7 +55,7 @@ class Operation : public RequestManager::HandlerInterface {
bool SendEvent(int request_id,
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> event_args);
std::vector<base::Value> event_args);

ProvidedFileSystemInfo file_system_info_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ bool WriteFile::Execute(int request_id) {
"data",
base::Value(base::as_bytes(base::make_span(buffer_->data(), length_))));

base::Value event_args(base::Value::Type::LIST);
event_args.Append(std::move(options_as_value));
std::vector<base::Value> event_args;
event_args.push_back(std::move(options_as_value));

return SendEvent(
request_id,
extensions::events::FILE_SYSTEM_PROVIDER_ON_WRITE_FILE_REQUESTED,
extensions::api::file_system_provider::OnWriteFileRequested::kEventName,
base::ListValue::From(
base::Value::ToUniquePtrValue(std::move(event_args))));
std::move(event_args));
}

void WriteFile::OnSuccess(int /* request_id */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_DRIVEFS_EVENT_ROUTER_H_

#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>

#include "base/macros.h"
#include "base/values.h"
#include "chromeos/components/drivefs/drivefs_host_observer.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "extensions/browser/extension_event_histogram_value.h"
#include "url/gurl.h"

namespace base {
class FilePath;
class ListValue;
}

namespace extensions {
Expand Down Expand Up @@ -99,7 +98,7 @@ class DriveFsEventRouter : public drivefs::DriveFsHostObserver {
const std::string& extension_id,
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> event_args) = 0;
std::vector<base::Value> event_args) = 0;

static extensions::api::file_manager_private::FileTransferStatus
CreateFileTransferStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ using testing::_;

namespace {

class ListValueMatcher
: public testing::MatcherInterface<const base::ListValue&> {
class ValueMatcher : public testing::MatcherInterface<const base::Value&> {
public:
explicit ListValueMatcher(base::ListValue expected)
explicit ValueMatcher(base::Value expected)
: expected_(std::move(expected)) {}

bool MatchAndExplain(const base::ListValue& actual,
bool MatchAndExplain(const base::Value& actual,
testing::MatchResultListener* listener) const override {
*listener << actual;
return actual == expected_;
Expand All @@ -44,10 +43,10 @@ class ListValueMatcher
void DescribeTo(::std::ostream* os) const override { *os << expected_; }

private:
base::ListValue expected_;
base::Value expected_;
};

testing::Matcher<const base::ListValue&> MatchFileTransferStatus(
testing::Matcher<const base::Value&> MatchFileTransferStatus(
std::string file_url,
file_manager_private::TransferState transfer_state,
double processed,
Expand All @@ -60,14 +59,14 @@ testing::Matcher<const base::ListValue&> MatchFileTransferStatus(
status.total = total;
status.num_total_jobs = num_total_jobs;
status.hide_when_zero_jobs = true;
return testing::MakeMatcher(new ListValueMatcher(std::move(
*file_manager_private::OnFileTransfersUpdated::Create(status))));
return testing::MakeMatcher(new ValueMatcher(base::Value(
file_manager_private::OnFileTransfersUpdated::Create(status))));
}

testing::Matcher<const base::ListValue&> MatchFileWatchEvent(
testing::Matcher<const base::Value&> MatchFileWatchEvent(
const FileWatchEvent& event) {
return testing::MakeMatcher(new ListValueMatcher(
std::move(*file_manager_private::OnDirectoryChanged::Create(event))));
return testing::MakeMatcher(new ValueMatcher(
base::Value(file_manager_private::OnDirectoryChanged::Create(event))));
}

class TestDriveFsEventRouter : public DriveFsEventRouter {
Expand All @@ -83,15 +82,16 @@ class TestDriveFsEventRouter : public DriveFsEventRouter {
const std::string& extension_id,
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> event_args) override {
DispatchEventToExtensionImpl(extension_id, event_name, *event_args);
std::vector<base::Value> event_args) override {
DispatchEventToExtensionImpl(extension_id, event_name,
base::Value(std::move(event_args)));
}

MOCK_METHOD(void,
DispatchEventToExtensionImpl,
(const std::string& extension_id,
const std::string& name,
const base::ListValue& event));
const base::Value& event));
MOCK_METHOD(bool, IsPathWatched, (const base::FilePath&));

GURL ConvertDrivePathToFileSystemUrl(const base::FilePath& file_path,
Expand Down Expand Up @@ -767,8 +767,8 @@ TEST_F(DriveFsEventRouterTest, OnError_CantUploadStorageFull) {
mock(),
DispatchEventToExtensionImpl(
"ext", file_manager_private::OnDriveSyncError::kEventName,
testing::MakeMatcher(new ListValueMatcher(std::move(
*file_manager_private::OnDriveSyncError::Create(event))))));
testing::MakeMatcher(new ValueMatcher(base::Value(
file_manager_private::OnDriveSyncError::Create(event))))));

observer().OnError({drivefs::mojom::DriveError::Type::kCantUploadStorageFull,
base::FilePath("/a")});
Expand All @@ -782,8 +782,8 @@ TEST_F(DriveFsEventRouterTest, OnError_CantPinDiskFull) {
mock(),
DispatchEventToExtensionImpl(
"ext", file_manager_private::OnDriveSyncError::kEventName,
testing::MakeMatcher(new ListValueMatcher(std::move(
*file_manager_private::OnDriveSyncError::Create(event))))));
testing::MakeMatcher(new ValueMatcher(base::Value(
file_manager_private::OnDriveSyncError::Create(event))))));

observer().OnError({drivefs::mojom::DriveError::Type::kPinningFailedDiskFull,
base::FilePath("a")});
Expand All @@ -797,8 +797,8 @@ TEST_F(DriveFsEventRouterTest, DisplayConfirmDialog_Display) {
EXPECT_CALL(mock(),
DispatchEventToExtensionImpl(
"ext", file_manager_private::OnDriveConfirmDialog::kEventName,
testing::MakeMatcher(new ListValueMatcher(std::move(
*file_manager_private::OnDriveConfirmDialog::Create(
testing::MakeMatcher(new ValueMatcher(base::Value(
file_manager_private::OnDriveConfirmDialog::Create(
expected_event))))));

drivefs::mojom::DialogReason reason;
Expand All @@ -824,8 +824,8 @@ TEST_F(DriveFsEventRouterTest, DisplayConfirmDialog_OneDialogAtATime) {
EXPECT_CALL(mock(),
DispatchEventToExtensionImpl(
"ext", file_manager_private::OnDriveConfirmDialog::kEventName,
testing::MakeMatcher(new ListValueMatcher(std::move(
*file_manager_private::OnDriveConfirmDialog::Create(
testing::MakeMatcher(new ValueMatcher(base::Value(
file_manager_private::OnDriveConfirmDialog::Create(
expected_event))))));

drivefs::mojom::DialogReason reason;
Expand Down Expand Up @@ -860,8 +860,8 @@ TEST_F(DriveFsEventRouterTest, DisplayConfirmDialog_UnmountBeforeResult) {
EXPECT_CALL(mock(),
DispatchEventToExtensionImpl(
"ext", file_manager_private::OnDriveConfirmDialog::kEventName,
testing::MakeMatcher(new ListValueMatcher(std::move(
*file_manager_private::OnDriveConfirmDialog::Create(
testing::MakeMatcher(new ValueMatcher(base::Value(
file_manager_private::OnDriveConfirmDialog::Create(
expected_event))))))
.Times(2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ bool IsRecoveryToolRunning(Profile* profile) {
void BroadcastEvent(Profile* profile,
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> event_args) {
std::vector<base::Value> event_args) {
extensions::EventRouter::Get(profile)->BroadcastEvent(
std::make_unique<extensions::Event>(histogram_value, event_name,
std::move(event_args)));
Expand All @@ -114,7 +114,7 @@ void DispatchEventToExtension(
const std::string& extension_id,
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> event_args) {
std::vector<base::Value> event_args) {
extensions::EventRouter::Get(profile)->DispatchEventToExtension(
extension_id, std::make_unique<extensions::Event>(
histogram_value, event_name, std::move(event_args)));
Expand Down Expand Up @@ -409,7 +409,7 @@ class DriveFsEventRouterImpl : public DriveFsEventRouter {
const std::string& extension_id,
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> event_args) override {
std::vector<base::Value> event_args) override {
extensions::EventRouter::Get(profile_)->DispatchEventToExtension(
extension_id, std::make_unique<extensions::Event>(
histogram_value, event_name, std::move(event_args)));
Expand Down
3 changes: 1 addition & 2 deletions chrome/browser/extensions/api/alarms/alarms_apitest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class AlarmsApiTest : public ExtensionApiTest,
ASSERT_TRUE(StartEmbeddedTestServer());
}

static std::unique_ptr<base::ListValue> BuildEventArguments(
const bool last_message) {
static std::vector<base::Value> BuildEventArguments(const bool last_message) {
api::test::OnMessage::Info info;
info.data = "";
info.last_message = last_message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ BookmarkManagerPrivateEventRouter::~BookmarkManagerPrivateEventRouter() {
void BookmarkManagerPrivateEventRouter::DispatchEvent(
events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> event_args) {
std::vector<base::Value> event_args) {
EventRouter::Get(browser_context_)
->BroadcastEvent(std::make_unique<Event>(histogram_value, event_name,
std::move(event_args)));
Expand Down Expand Up @@ -251,7 +251,7 @@ BookmarkManagerPrivateDragEventRouter::
void BookmarkManagerPrivateDragEventRouter::DispatchEvent(
events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> args) {
std::vector<base::Value> args) {
EventRouter* event_router = EventRouter::Get(profile_);
if (!event_router)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class BookmarkManagerPrivateEventRouter
// Helper to actually dispatch an event to extension listeners.
void DispatchEvent(events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> event_args);
std::vector<base::Value> event_args);

// Remembers the previous meta info of a node before it was changed.
bookmarks::BookmarkNode::MetaInfoMap prev_meta_info_;
Expand Down Expand Up @@ -121,7 +121,7 @@ class BookmarkManagerPrivateDragEventRouter
// Helper to actually dispatch an event to extension listeners.
void DispatchEvent(events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> args);
std::vector<base::Value> args);

content::WebContents* web_contents_;
Profile* profile_;
Expand Down
7 changes: 3 additions & 4 deletions chrome/browser/extensions/api/bookmarks/bookmarks_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,9 @@ BookmarkEventRouter::~BookmarkEventRouter() {
}
}

void BookmarkEventRouter::DispatchEvent(
events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> event_args) {
void BookmarkEventRouter::DispatchEvent(events::HistogramValue histogram_value,
const std::string& event_name,
std::vector<base::Value> event_args) {
EventRouter* event_router = EventRouter::Get(browser_context_);
if (event_router) {
event_router->BroadcastEvent(std::make_unique<extensions::Event>(
Expand Down
Loading

0 comments on commit d380dd2

Please sign in to comment.