Skip to content

Commit

Permalink
Move unguessable_token.mojom from common to base
Browse files Browse the repository at this point in the history
This change moves unguessable_token.mojom from //mojo/common to
//mojo/public/mojom/base. Corresponding typemap and struct traits files
were also moved. Unit test for UnguessableToken was updated to use
SerializeAndDeserialize() from //mojo/public/cpp/test_support/test_utils.h
and moved to mojo_unittests.

Bug: 799482,806965
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: I62c280c06e3b8ebe66af15d20fb9e95a17aa024a
Reviewed-on: https://chromium-review.googlesource.com/974377
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Oksana Zhuravlova <oksamyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545301}
  • Loading branch information
Oksana Zhuravlova authored and Commit Bot committed Mar 23, 2018
1 parent 73c6c36 commit 34579e9
Show file tree
Hide file tree
Showing 36 changed files with 157 additions and 139 deletions.
1 change: 1 addition & 0 deletions components/services/leveldb/public/interfaces/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ mojom("interfaces") {

public_deps = [
"//mojo/common:common_custom_types",
"//mojo/public/mojom/base",
]
}
26 changes: 13 additions & 13 deletions components/services/leveldb/public/interfaces/leveldb.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
module leveldb.mojom;

import "components/services/filesystem/public/interfaces/directory.mojom";
import "mojo/common/unguessable_token.mojom";
import "mojo/common/memory_allocator_dump_cross_process_uid.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";

enum DatabaseError {
OK,
Expand Down Expand Up @@ -136,48 +136,48 @@ interface LevelDBDatabase {
// Snapshots -------------------------------------------------------------

// Returns a handle to the current database state.
GetSnapshot() => (mojo.common.mojom.UnguessableToken snapshot);
GetSnapshot() => (mojo_base.mojom.UnguessableToken snapshot);

// Releases a previously acquired snapshot.
ReleaseSnapshot(mojo.common.mojom.UnguessableToken snapshot);
ReleaseSnapshot(mojo_base.mojom.UnguessableToken snapshot);

// If |key| exists at the time |snapshot_id| was taken, return OK and the
// value. Otherwise return NOT_FOUND.
GetFromSnapshot(mojo.common.mojom.UnguessableToken snapshot,
GetFromSnapshot(mojo_base.mojom.UnguessableToken snapshot,
array<uint8> key)
=> (DatabaseError status, array<uint8> value);

// Iteartors -------------------------------------------------------------

// Creates an iterator, either from the current view or from a snapshot.
NewIterator() => (mojo.common.mojom.UnguessableToken iterator);
NewIteratorFromSnapshot(mojo.common.mojom.UnguessableToken snapshot)
=> (mojo.common.mojom.UnguessableToken? iterator);
NewIterator() => (mojo_base.mojom.UnguessableToken iterator);
NewIteratorFromSnapshot(mojo_base.mojom.UnguessableToken snapshot)
=> (mojo_base.mojom.UnguessableToken? iterator);

ReleaseIterator(mojo.common.mojom.UnguessableToken iterator);
ReleaseIterator(mojo_base.mojom.UnguessableToken iterator);

// Positions the iterator at the first key, last key, or the first key after
// |target|.
[Sync]
IteratorSeekToFirst(mojo.common.mojom.UnguessableToken iterator)
IteratorSeekToFirst(mojo_base.mojom.UnguessableToken iterator)
=> (bool valid, DatabaseError status, array<uint8>? key,
array<uint8>? value);
[Sync]
IteratorSeekToLast(mojo.common.mojom.UnguessableToken iterator)
IteratorSeekToLast(mojo_base.mojom.UnguessableToken iterator)
=> (bool valid, DatabaseError status, array<uint8>? key,
array<uint8>? value);
[Sync]
IteratorSeek(mojo.common.mojom.UnguessableToken iterator, array<uint8> target)
IteratorSeek(mojo_base.mojom.UnguessableToken iterator, array<uint8> target)
=> (bool valid, DatabaseError status, array<uint8>? key,
array<uint8>? value);

// Moves forward or backwards in iterator space.
[Sync]
IteratorNext(mojo.common.mojom.UnguessableToken iterator)
IteratorNext(mojo_base.mojom.UnguessableToken iterator)
=> (bool valid, DatabaseError status, array<uint8>? key,
array<uint8>? value);
[Sync]
IteratorPrev(mojo.common.mojom.UnguessableToken iterator)
IteratorPrev(mojo_base.mojom.UnguessableToken iterator)
=> (bool valid, DatabaseError status, array<uint8>? key,
array<uint8>? value);
};
6 changes: 3 additions & 3 deletions content/common/frame.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import "content/public/common/resource_type.mojom";
import "content/public/common/subresource_load_info.mojom";
import "content/public/common/transferrable_url_loader.mojom";
import "content/public/common/window_container_type.mojom";
import "mojo/common/unguessable_token.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";
import "services/network/public/mojom/url_loader.mojom";
import "services/service_manager/public/mojom/interface_provider.mojom";
import "services/viz/public/interfaces/compositing/surface_id.mojom";
Expand Down Expand Up @@ -90,7 +90,7 @@ interface FrameNavigationControl {
URLLoaderFactoryBundle? subresource_loader_factories,
array<TransferrableURLLoader>? subresource_overrides,
ControllerServiceWorkerInfo? controller_service_worker_info,
mojo.common.mojom.UnguessableToken devtools_navigation_token);
mojo_base.mojom.UnguessableToken devtools_navigation_token);

// Tells the renderer that a failed navigation is ready to commit.
//
Expand Down Expand Up @@ -222,7 +222,7 @@ struct CreateNewWindowReply {
// attribute them to the context frame.
// |devtools_frame_token| is only defined by the browser and is never
// sent back from the renderer in the control calls.
mojo.common.mojom.UnguessableToken devtools_main_frame_token;
mojo_base.mojom.UnguessableToken devtools_main_frame_token;
};

// An opaque handle that keeps alive the associated render process even after
Expand Down
4 changes: 2 additions & 2 deletions content/common/render_widget_window_tree_client_factory.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

module content.mojom;

import "mojo/common/unguessable_token.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";
import "services/ui/public/interfaces/window_tree.mojom";

interface RenderWidgetWindowTreeClient {
// Asks the renderer to create a Window for the frame with the routing id
// |routing_id| and embeds the WindowTreeClient that was previously supplied
// to ScheduleEmbed().
Embed(uint32 frame_routing_id, mojo.common.mojom.UnguessableToken token);
Embed(uint32 frame_routing_id, mojo_base.mojom.UnguessableToken token);

// Called when a render frame has been destroyed. This is sent via mojom
// to handle to ensure there aren't race conditions because of message order
Expand Down
8 changes: 4 additions & 4 deletions content/common/renderer.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "content/common/native_types.mojom";
import "content/common/service_worker/embedded_worker.mojom";
import "ipc/constants.mojom";
import "mojo/public/mojom/base/time.mojom";
import "mojo/common/unguessable_token.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";
import "services/network/public/mojom/network_types.mojom";
import "services/service_manager/public/mojom/interface_provider.mojom";
import "services/service_manager/public/mojom/service.mojom";
Expand Down Expand Up @@ -61,7 +61,7 @@ struct CreateViewParams {
// attribute them to the context frame.
// |devtools_main_frame_token| is only defined by the browser and is never
// sent back from the renderer in the control calls.
mojo.common.mojom.UnguessableToken devtools_main_frame_token;
mojo_base.mojom.UnguessableToken devtools_main_frame_token;

// The ID of the proxy object for the main frame in this view. It is only
// used if |swapped_out| is true.
Expand Down Expand Up @@ -148,7 +148,7 @@ struct CreateFrameParams {
// attribute them to the context frame.
// |devtools_frame_token| is only defined by the browser and is never
// sent back from the renderer in the control calls.
mojo.common.mojom.UnguessableToken devtools_frame_token;
mojo_base.mojom.UnguessableToken devtools_frame_token;

// When the new frame has a parent, |frame_owner_properties| holds the
// properties of the HTMLFrameOwnerElement from the parent process.
Expand Down Expand Up @@ -210,7 +210,7 @@ interface Renderer {
CreateFrameProxy(int32 routing_id, int32 render_view_routing_id,
int32 opener_routing_id, int32 parent_routing_id,
FrameReplicationState replication_state,
mojo.common.mojom.UnguessableToken devtools_frame_token);
mojo_base.mojom.UnguessableToken devtools_frame_token);

// Tells the renderer that the network type has changed so that
// navigator.onLine and navigator.connection can be updated.
Expand Down
4 changes: 2 additions & 2 deletions content/common/service_worker/embedded_worker.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "content/common/service_worker/service_worker_event_dispatcher.mojom";
import "content/common/service_worker/service_worker_provider.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "mojo/public/mojom/base/time.mojom";
import "mojo/common/unguessable_token.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";
import "services/service_manager/public/mojom/interface_provider.mojom";
import "third_party/WebKit/public/mojom/service_worker/service_worker.mojom";
import "third_party/WebKit/public/mojom/service_worker/service_worker_installed_scripts_manager.mojom";
Expand Down Expand Up @@ -38,7 +38,7 @@ struct EmbeddedWorkerStartParams {
// The id to talk with the DevTools agent for the worker.
int32 worker_devtools_agent_route_id;
// Unique token identifying this worker for DevTools.
mojo.common.mojom.UnguessableToken devtools_worker_token;
mojo_base.mojom.UnguessableToken devtools_worker_token;
// When true, worker script evaluation is blocked until
// EmbeddedWorkerInstanceClient::ResumeAfterDownload() is called.
bool pause_after_download;
Expand Down
4 changes: 2 additions & 2 deletions content/common/shared_worker/shared_worker_factory.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module content.mojom;
import "content/common/shared_worker/shared_worker.mojom";
import "content/common/shared_worker/shared_worker_host.mojom";
import "content/common/shared_worker/shared_worker_info.mojom";
import "mojo/common/unguessable_token.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";
import "services/service_manager/public/mojom/interface_provider.mojom";
import "third_party/WebKit/public/web/worker_content_settings_proxy.mojom";

Expand All @@ -27,7 +27,7 @@ interface SharedWorkerFactory {
CreateSharedWorker(
SharedWorkerInfo info,
bool pause_on_start,
mojo.common.mojom.UnguessableToken devtools_worker_token,
mojo_base.mojom.UnguessableToken devtools_worker_token,
blink.mojom.WorkerContentSettingsProxy content_settings,
SharedWorkerHost host,
SharedWorker& shared_worker,
Expand Down
2 changes: 1 addition & 1 deletion content/public/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,10 @@ android_library("content_javatests") {
"//media/capture/video/android:capture_java",
"//media/mojo/interfaces:interfaces_java",
"//mojo/android:system_java",
"//mojo/common:common_custom_types_java",
"//mojo/public/interfaces/bindings/tests:test_interfaces_java",
"//mojo/public/java:bindings_java",
"//mojo/public/java:system_java",
"//mojo/public/mojom/base:base_java",
"//net/android:net_java",
"//net/android:net_java_test_support",
"//third_party/android_support_test_runner:rules_java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.chromium.content_shell_apk.ContentShellActivityTestRule;
import org.chromium.media.mojom.AndroidOverlayClient;
import org.chromium.media.mojom.AndroidOverlayConfig;
import org.chromium.mojo.common.mojom.UnguessableToken;
import org.chromium.mojo.system.MojoException;
import org.chromium.mojo_base.mojom.UnguessableToken;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Callable;
Expand Down
2 changes: 1 addition & 1 deletion docs/security/mojo.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ enforce that the input data is valid. Common ones to watch out for:
* JSON: use `mojo.common.mojom.Value`, not `string`.
* Mojo interfaces: use `Interface` or `Interface&`, not `handle` or
`handle<message_pipe>`.
* Nonces: use `mojo.common.mojom.UnguessableToken`, not `string`.
* Nonces: use `mojo_base.mojom.UnguessableToken`, not `string`.
* Origins: use `url.mojom.Origin`, not `url.mojom.Url` and certainly not
`string`.
* Time types: use `mojo_base.mojom.TimeDelta` /
Expand Down
4 changes: 2 additions & 2 deletions media/mojo/interfaces/android_overlay.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module media.mojom;

import "media/mojo/interfaces/media_types.mojom";
import "mojo/common/unguessable_token.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom";

// Provides mojo clients with AndroidOverlay instances. This will live in the
Expand Down Expand Up @@ -58,7 +58,7 @@ struct AndroidOverlayConfig {
// will be the parent of the overlay. For legacy reasons, we need this token
// to be sent via IPC, so using the message pipe, or other mojo construct, as
// the identifier won't work yet.
mojo.common.mojom.UnguessableToken routing_token;
mojo_base.mojom.UnguessableToken routing_token;

// Initial rectangle.
gfx.mojom.Rect rect;
Expand Down
4 changes: 2 additions & 2 deletions media/mojo/interfaces/media_drm_storage.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module media.mojom;

import "mojo/common/unguessable_token.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";

struct SessionData {
array<uint8> key_set_id;
Expand All @@ -18,7 +18,7 @@ interface MediaDrmStorage {
// current origin. The origin ID should be randomly generated if it doesn't
// exist. |origin_id| must be valid.
// This should not modify anything in the storage.
Initialize() => (mojo.common.mojom.UnguessableToken origin_id);
Initialize() => (mojo_base.mojom.UnguessableToken origin_id);

// Saves origin information (e.g. origin ID, provision time) in the storage
// after MediaDrm is provisioned for current origin.
Expand Down
4 changes: 2 additions & 2 deletions media/mojo/interfaces/renderer.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module media.mojom;
import "media/mojo/interfaces/demuxer_stream.mojom";
import "media/mojo/interfaces/media_types.mojom";
import "mojo/public/mojom/base/time.mojom";
import "mojo/common/unguessable_token.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom";
import "url/mojom/url.mojom";

Expand Down Expand Up @@ -46,7 +46,7 @@ interface Renderer {
// content::MediaPlayerRenderer.
// Unexpected calls to this method will close the connection.
InitiateScopedSurfaceRequest()
=> (mojo.common.mojom.UnguessableToken request_token);
=> (mojo_base.mojom.UnguessableToken request_token);
};

interface RendererClient {
Expand Down
8 changes: 4 additions & 4 deletions media/mojo/interfaces/video_decoder.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ module media.mojom;
import "gpu/ipc/common/sync_token.mojom";
import "media/mojo/interfaces/media_log.mojom";
import "media/mojo/interfaces/media_types.mojom";
import "mojo/common/unguessable_token.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";

// Identifies a CommandBufferStub. MediaGpuChannelManager is responsible
// for minting |channel_token| values.
struct CommandBufferId {
mojo.common.mojom.UnguessableToken channel_token;
mojo_base.mojom.UnguessableToken channel_token;
int32 route_id;
};

Expand All @@ -23,7 +23,7 @@ interface VideoFrameHandleReleaser {
//
// TODO(sandersd): Do we need release notification for non-texture
// VideoFrames? If so, |release_sync_token| should be optional.
ReleaseVideoFrame(mojo.common.mojom.UnguessableToken release_token,
ReleaseVideoFrame(mojo_base.mojom.UnguessableToken release_token,
gpu.mojom.SyncToken release_sync_token);
};

Expand Down Expand Up @@ -117,7 +117,7 @@ interface VideoDecoderClient {
// VideoFrameHandleReleaser::Release() when it is finished using |frame|.
OnVideoFrameDecoded(VideoFrame frame,
bool can_read_without_stalling,
mojo.common.mojom.UnguessableToken? release_token);
mojo_base.mojom.UnguessableToken? release_token);

// Request to be notified when the current OverlayInfo changes. This results
// in at least one call to OnOverlayInfoChanged() for the initial OverlayInfo.
Expand Down
1 change: 0 additions & 1 deletion mojo/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ mojom("common_custom_types") {
"memory_allocator_dump_cross_process_uid.mojom",
"process_id.mojom",
"thread_priority.mojom",
"unguessable_token.mojom",
"values.mojom",
]

Expand Down
16 changes: 0 additions & 16 deletions mojo/common/common_custom_types_struct_traits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,6 @@

namespace mojo {

// static
bool StructTraits<
common::mojom::UnguessableTokenDataView,
base::UnguessableToken>::Read(common::mojom::UnguessableTokenDataView data,
base::UnguessableToken* out) {
uint64_t high = data.high();
uint64_t low = data.low();

// Receiving a zeroed UnguessableToken is a security issue.
if (high == 0 && low == 0)
return false;

*out = base::UnguessableToken::Deserialize(high, low);
return true;
}

// static
common::mojom::ThreadPriority
EnumTraits<common::mojom::ThreadPriority, base::ThreadPriority>::ToMojom(
Expand Down
22 changes: 1 addition & 21 deletions mojo/common/common_custom_types_struct_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,10 @@
#include "mojo/common/mojo_common_export.h"
#include "mojo/common/process_id.mojom-shared.h"
#include "mojo/common/thread_priority.mojom-shared.h"
#include "mojo/common/unguessable_token.mojom-shared.h"
#include "mojo/public/mojom/base/unguessable_token.mojom-shared.h"

namespace mojo {

// If base::UnguessableToken is no longer 128 bits, the logic below and the
// mojom::UnguessableToken type should be updated.
static_assert(sizeof(base::UnguessableToken) == 2 * sizeof(uint64_t),
"base::UnguessableToken should be of size 2 * sizeof(uint64_t).");

template <>
struct StructTraits<common::mojom::UnguessableTokenDataView,
base::UnguessableToken> {
static uint64_t high(const base::UnguessableToken& token) {
return token.GetHighForSerialization();
}

static uint64_t low(const base::UnguessableToken& token) {
return token.GetLowForSerialization();
}

static bool Read(common::mojom::UnguessableTokenDataView data,
base::UnguessableToken* out);
};

template <>
struct StructTraits<common::mojom::ProcessIdDataView, base::ProcessId> {
static uint32_t pid(const base::ProcessId& process_id) {
Expand Down
Loading

0 comments on commit 34579e9

Please sign in to comment.