Commit 8b10c4c2 authored by Alex Chau's avatar Alex Chau Committed by Commit Bot

High level interface for NearbySharingService

- Methods are a mirror of NearbySharingChimeraService in Android
- Added a few data types and callback to define NearbySharingService
  methods
- Only data related methods are introduced for now. Implementations are
  empty

Bug: 1084283
Change-Id: I18e691b76bc4872bb4a4f4771af1b368b07af6e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2207374
Commit-Queue: Alex Chau <alexchau@chromium.org>
Reviewed-by: default avatarRichard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770997}
parent 89183689
...@@ -3401,8 +3401,11 @@ static_library("browser") { ...@@ -3401,8 +3401,11 @@ static_library("browser") {
"metrics/tab_stats_tracker_delegate.h", "metrics/tab_stats_tracker_delegate.h",
"metrics/tab_stats_tracker_delegate_win.cc", "metrics/tab_stats_tracker_delegate_win.cc",
"metrics/tab_stats_tracker_win.cc", "metrics/tab_stats_tracker_win.cc",
"nearby_sharing/attachment.h",
"nearby_sharing/fast_initiation_manager.cc", "nearby_sharing/fast_initiation_manager.cc",
"nearby_sharing/fast_initiation_manager.h", "nearby_sharing/fast_initiation_manager.h",
"nearby_sharing/file_attachment.cc",
"nearby_sharing/file_attachment.h",
"nearby_sharing/nearby_sharing_prefs.cc", "nearby_sharing/nearby_sharing_prefs.cc",
"nearby_sharing/nearby_sharing_prefs.h", "nearby_sharing/nearby_sharing_prefs.h",
"nearby_sharing/nearby_sharing_service.h", "nearby_sharing/nearby_sharing_service.h",
...@@ -3410,6 +3413,14 @@ static_library("browser") { ...@@ -3410,6 +3413,14 @@ static_library("browser") {
"nearby_sharing/nearby_sharing_service_factory.h", "nearby_sharing/nearby_sharing_service_factory.h",
"nearby_sharing/nearby_sharing_service_impl.cc", "nearby_sharing/nearby_sharing_service_impl.cc",
"nearby_sharing/nearby_sharing_service_impl.h", "nearby_sharing/nearby_sharing_service_impl.h",
"nearby_sharing/share_target.cc",
"nearby_sharing/share_target.h",
"nearby_sharing/share_target_discovered_callback.h",
"nearby_sharing/text_attachment.cc",
"nearby_sharing/text_attachment.h",
"nearby_sharing/transfer_metadata.cc",
"nearby_sharing/transfer_metadata.h",
"nearby_sharing/transfer_update_callback.h",
"notifications/notification_system_observer.cc", "notifications/notification_system_observer.cc",
"notifications/notification_system_observer.h", "notifications/notification_system_observer.h",
"notifications/profile_notification.cc", "notifications/profile_notification.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_ATTACHMENT_H_
#define CHROME_BROWSER_NEARBY_SHARING_ATTACHMENT_H_
#include <stdint.h>
// A single attachment to be sent by / received from a ShareTarget, can be
// either a file or text.
class Attachment {
public:
enum class Family { kFile, kText, kMaxValue = kText };
virtual ~Attachment() = default;
virtual int64_t size() const = 0;
virtual Family family() const = 0;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_ATTACHMENT_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/nearby_sharing/file_attachment.h"
FileAttachment::FileAttachment(std::string file_name,
Type type,
int64_t size,
base::Optional<base::FilePath> file_path,
std::string mime_type)
: file_name_(std::move(file_name)),
type_(type),
size_(size),
file_path_(std::move(file_path)),
mime_type_(std::move(mime_type)) {}
FileAttachment::~FileAttachment() = default;
int64_t FileAttachment::size() const {
return size_;
}
Attachment::Family FileAttachment::family() const {
return Attachment::Family::kFile;
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_FILE_ATTACHMENT_H_
#define CHROME_BROWSER_NEARBY_SHARING_FILE_ATTACHMENT_H_
#include <string>
#include "base/files/file_path.h"
#include "base/optional.h"
#include "chrome/browser/nearby_sharing/attachment.h"
// A single attachment to be sent by / received from a |ShareTarget|, can be
// either a file or text.
class FileAttachment : public Attachment {
public:
// Different types are used to offer richer experiences on Receiver side,
// mainly for: 1. displaying notification of attachment types, 2. opening
// different types with different apps. Remember to update Notifications,
// ShareTarget, etc once more types are introduced here.
enum class Type {
kUnknown,
kImage,
kVideo,
kApp,
kAudio,
kMaxValue = kAudio
};
FileAttachment(std::string file_name,
Type type,
int64_t size,
base::Optional<base::FilePath> file_path,
std::string mime_type);
~FileAttachment() override;
// Attachment:
int64_t size() const override;
Attachment::Family family() const override;
const std::string& file_name() const { return file_name_; }
Type type() const { return type_; }
const base::Optional<base::FilePath>& file_path() const { return file_path_; }
const std::string& mime_type() const { return mime_type_; }
private:
std::string file_name_;
Type type_;
int64_t size_;
base::Optional<base::FilePath> file_path_;
std::string mime_type_;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_FILE_ATTACHMENT_H_
...@@ -5,12 +5,76 @@ ...@@ -5,12 +5,76 @@
#ifndef CHROME_BROWSER_NEARBY_SHARING_NEARBY_SHARING_SERVICE_H_ #ifndef CHROME_BROWSER_NEARBY_SHARING_NEARBY_SHARING_SERVICE_H_
#define CHROME_BROWSER_NEARBY_SHARING_NEARBY_SHARING_SERVICE_H_ #define CHROME_BROWSER_NEARBY_SHARING_NEARBY_SHARING_SERVICE_H_
#include "base/callback.h"
#include "base/files/file_path.h"
#include "chrome/browser/nearby_sharing/share_target_discovered_callback.h"
#include "chrome/browser/nearby_sharing/transfer_update_callback.h"
// This service implements Nearby Sharing on top of the Nearby Connections mojo. // This service implements Nearby Sharing on top of the Nearby Connections mojo.
// Currently only single profile will be allowed to be bound at a time and only // Currently only single profile will be allowed to be bound at a time and only
// after the user has enabled Nearby Sharing in prefs. // after the user has enabled Nearby Sharing in prefs.
class NearbySharingService { class NearbySharingService {
public: public:
enum class StatusCodes {
// The operation was successful.
kOk,
// The operation failed, without any more information.
kError,
};
using StatusCodesCallback =
base::OnceCallback<void(StatusCodes status_codes)>;
virtual ~NearbySharingService() = default; virtual ~NearbySharingService() = default;
// Registers a send surface for handling payload transfer status and device
// discovery.
virtual void RegisterSendSurface(
TransferUpdateCallback* transferCallback,
ShareTargetDiscoveredCallback* discoveryCallback,
StatusCodesCallback status_codes_callback) = 0;
// Unregisters the current send surface.
virtual void UnregisterSendSurface(
TransferUpdateCallback* transferCallback,
ShareTargetDiscoveredCallback* discoveryCallback,
StatusCodesCallback status_codes_callback) = 0;
// Registers a receiver surface for handling payload transfer status.
virtual void RegisterReceiveSurface(
TransferUpdateCallback* transferCallback,
StatusCodesCallback status_codes_callback) = 0;
// Unregistesrs the current receive surface.
virtual void UnregisterReceiveSurface(
TransferUpdateCallback* transferCallback,
StatusCodesCallback status_codes_callback) = 0;
// Sends text to the remote |share_target|.
virtual void SendText(const ShareTarget& share_target,
std::string text,
StatusCodesCallback status_codes_callback) = 0;
// Sends files to the remote |share_target|.
virtual void SendFiles(const ShareTarget& share_target,
const std::vector<base::FilePath>& files,
StatusCodesCallback status_codes_callback) = 0;
// Accepts incoming share from the remote |share_target|.
virtual void Accept(const ShareTarget& share_target,
StatusCodesCallback status_codes_callback) = 0;
// Rejects incoming share from the remote |share_target|.
virtual void Reject(const ShareTarget& share_target,
StatusCodesCallback status_codes_callback) = 0;
// Cancels outoing shares to the remote |share_target|.
virtual void Cancel(const ShareTarget& share_target,
StatusCodesCallback status_codes_callback) = 0;
// Opens attachments from the remote |share_target|.
virtual void Open(const ShareTarget& share_target,
StatusCodesCallback status_codes_callback) = 0;
}; };
#endif // CHROME_BROWSER_NEARBY_SHARING_NEARBY_SHARING_SERVICE_H_ #endif // CHROME_BROWSER_NEARBY_SHARING_NEARBY_SHARING_SERVICE_H_
...@@ -3,6 +3,70 @@ ...@@ -3,6 +3,70 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/nearby_sharing/nearby_sharing_service_impl.h" #include "chrome/browser/nearby_sharing/nearby_sharing_service_impl.h"
#include "base/logging.h" #include "base/logging.h"
NearbySharingServiceImpl::NearbySharingServiceImpl(Profile* profile) {} NearbySharingServiceImpl::NearbySharingServiceImpl(Profile* profile) {}
void NearbySharingServiceImpl::RegisterSendSurface(
TransferUpdateCallback* transferCallback,
ShareTargetDiscoveredCallback* discoveryCallback,
StatusCodesCallback status_codes_callback) {
std::move(status_codes_callback).Run(StatusCodes::kOk);
}
void NearbySharingServiceImpl::UnregisterSendSurface(
TransferUpdateCallback* transferCallback,
ShareTargetDiscoveredCallback* discoveryCallback,
StatusCodesCallback status_codes_callback) {
std::move(status_codes_callback).Run(StatusCodes::kOk);
}
void NearbySharingServiceImpl::RegisterReceiveSurface(
TransferUpdateCallback* transferCallback,
StatusCodesCallback status_codes_callback) {
std::move(status_codes_callback).Run(StatusCodes::kOk);
}
void NearbySharingServiceImpl::UnregisterReceiveSurface(
TransferUpdateCallback* transferCallback,
StatusCodesCallback status_codes_callback) {
std::move(status_codes_callback).Run(StatusCodes::kOk);
}
void NearbySharingServiceImpl::NearbySharingServiceImpl::SendText(
const ShareTarget& share_target,
std::string text,
StatusCodesCallback status_codes_callback) {
std::move(status_codes_callback).Run(StatusCodes::kOk);
}
void NearbySharingServiceImpl::SendFiles(
const ShareTarget& share_target,
const std::vector<base::FilePath>& files,
StatusCodesCallback status_codes_callback) {
std::move(status_codes_callback).Run(StatusCodes::kOk);
}
void NearbySharingServiceImpl::Accept(
const ShareTarget& share_target,
StatusCodesCallback status_codes_callback) {
std::move(status_codes_callback).Run(StatusCodes::kOk);
}
void NearbySharingServiceImpl::Reject(
const ShareTarget& share_target,
StatusCodesCallback status_codes_callback) {
std::move(status_codes_callback).Run(StatusCodes::kOk);
}
void NearbySharingServiceImpl::Cancel(
const ShareTarget& share_target,
StatusCodesCallback status_codes_callback) {
std::move(status_codes_callback).Run(StatusCodes::kOk);
}
void NearbySharingServiceImpl::Open(const ShareTarget& share_target,
StatusCodesCallback status_codes_callback) {
std::move(status_codes_callback).Run(StatusCodes::kOk);
}
...@@ -15,6 +15,35 @@ class NearbySharingServiceImpl : public NearbySharingService, ...@@ -15,6 +15,35 @@ class NearbySharingServiceImpl : public NearbySharingService,
public: public:
explicit NearbySharingServiceImpl(Profile* profile); explicit NearbySharingServiceImpl(Profile* profile);
~NearbySharingServiceImpl() override = default; ~NearbySharingServiceImpl() override = default;
// NearbySharingService:
void RegisterSendSurface(TransferUpdateCallback* transferCallback,
ShareTargetDiscoveredCallback* discoveryCallback,
StatusCodesCallback status_codes_callback) override;
void UnregisterSendSurface(
TransferUpdateCallback* transferCallback,
ShareTargetDiscoveredCallback* discoveryCallback,
StatusCodesCallback status_codes_callback) override;
void RegisterReceiveSurface(
TransferUpdateCallback* transferCallback,
StatusCodesCallback status_codes_callback) override;
void UnregisterReceiveSurface(
TransferUpdateCallback* transferCallback,
StatusCodesCallback status_codes_callback) override;
void SendText(const ShareTarget& share_target,
std::string text,
StatusCodesCallback status_codes_callback) override;
void SendFiles(const ShareTarget& share_target,
const std::vector<base::FilePath>& files,
StatusCodesCallback status_codes_callback) override;
void Accept(const ShareTarget& share_target,
StatusCodesCallback status_codes_callback) override;
void Reject(const ShareTarget& share_target,
StatusCodesCallback status_codes_callback) override;
void Cancel(const ShareTarget& share_target,
StatusCodesCallback status_codes_callback) override;
void Open(const ShareTarget& share_target,
StatusCodesCallback status_codes_callback) override;
}; };
#endif // CHROME_BROWSER_NEARBY_SHARING_NEARBY_SHARING_SERVICE_IMPL_H_ #endif // CHROME_BROWSER_NEARBY_SHARING_NEARBY_SHARING_SERVICE_IMPL_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/nearby_sharing/share_target.h"
#include "base/atomic_sequence_num.h"
namespace {
// The last ID given to the previously created ShareTarget.
base::AtomicSequenceNumber g_id_generator;
} // namespace
ShareTarget::ShareTarget(std::string device_name,
GURL image_url,
Type type,
std::vector<TextAttachment> text_attachments,
std::vector<FileAttachment> file_attachments,
bool is_incoming,
base::Optional<std::string> full_name,
bool is_known)
: id_(g_id_generator.GetNext()),
device_name_(std::move(device_name)),
image_url_(std::move(image_url)),
type_(type),
text_attachments_(std::move(text_attachments)),
file_attachments_(std::move(file_attachments)),
is_incoming_(is_incoming),
full_name_(std::move(full_name)),
is_known_(is_known) {}
ShareTarget::~ShareTarget() = default;
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_SHARE_TARGET_H_
#define CHROME_BROWSER_NEARBY_SHARING_SHARE_TARGET_H_
#include <string>
#include <vector>
#include "base/optional.h"
#include "chrome/browser/nearby_sharing/file_attachment.h"
#include "chrome/browser/nearby_sharing/text_attachment.h"
#include "url/gurl.h"
// A remote device.
class ShareTarget {
public:
enum class Type { kUnknown, kPhone, kTablet, kLaptop, kMaxValue = kLaptop };
ShareTarget(std::string device_name,
GURL image_url,
Type type,
std::vector<TextAttachment> text_attachments,
std::vector<FileAttachment> file_attachments,
bool is_incoming,
base::Optional<std::string> full_name,
bool is_known);
~ShareTarget();
int id() { return id_; }
const std::string& device_name() { return device_name_; }
// Returns a Uri that points to an image of the ShareTarget, if one exists.
const base::Optional<GURL>& image_url() { return image_url_; }
Type type() { return type_; }
const std::vector<TextAttachment>& text_attachments() {
return text_attachments_;
}
const std::vector<FileAttachment>& file_attachments() {
return file_attachments_;
}
bool is_incoming() { return is_incoming_; }
const base::Optional<std::string>& full_name() { return full_name_; }
// Returns True if local device has the PublicCertificate the remote device is
// advertising.
bool is_known() { return is_known_; }
private:
int id_;
std::string device_name_;
base::Optional<GURL> image_url_;
Type type_;
std::vector<TextAttachment> text_attachments_;
std::vector<FileAttachment> file_attachments_;
bool is_incoming_;
base::Optional<std::string> full_name_;
bool is_known_;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_SHARE_TARGET_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_SHARE_TARGET_DISCOVERED_CALLBACK_H_
#define CHROME_BROWSER_NEARBY_SHARING_SHARE_TARGET_DISCOVERED_CALLBACK_H_
#include "base/observer_list_types.h"
#include "chrome/browser/nearby_sharing/share_target.h"
// Reports newly discovered devices.
class ShareTargetDiscoveredCallback : public base::CheckedObserver {
public:
virtual void OnShareTargetDiscovered(ShareTarget shareTarget) = 0;
virtual void OnShareTargetLost(ShareTarget shareTarget) = 0;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_SHARE_TARGET_DISCOVERED_CALLBACK_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/nearby_sharing/text_attachment.h"
TextAttachment::TextAttachment(std::string text_body, Type type, int64_t size)
: text_body_(std::move(text_body)), type_(type), size_(size) {}
TextAttachment::~TextAttachment() = default;
int64_t TextAttachment::size() const {
return size_;
}
Attachment::Family TextAttachment::family() const {
return Attachment::Family::kText;
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_TEXT_ATTACHMENT_H_
#define CHROME_BROWSER_NEARBY_SHARING_TEXT_ATTACHMENT_H_
#include <string>
#include "base/optional.h"
#include "chrome/browser/nearby_sharing/attachment.h"
// Represents a text attachment.
class TextAttachment : public Attachment {
public:
// Different types are used to offer richer experiences on Receiver side,
// mainly for: 1. displaying notification of attachment types, 2. opening
// different types with different apps. Remember to update Notifications,
// ShareTarget, etc once more types are introduced here.
enum class Type {
kText,
kUrl,
kAddress,
kPhoneNumber,
kMaxValue = kPhoneNumber
};
TextAttachment(std::string text_body, Type type, int64_t size);
~TextAttachment() override;
// Attachment:
int64_t size() const override;
Attachment::Family family() const override;
const std::string& text_body() const { return text_body_; }
Type type() const { return type_; }
private:
std::string text_body_;
Type type_;
int64_t size_;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_TEXT_ATTACHMENT_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/nearby_sharing/transfer_metadata.h"
TransferMetadata::TransferMetadata(Status status,
float progress,
base::Optional<std::string> token,
bool is_original,
bool is_final_status)
: status_(status),
progress_(progress),
token_(std::move(token)),
is_original_(is_original),
is_final_status_(is_final_status) {}
TransferMetadata::~TransferMetadata() = default;
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_TRANSFER_METADATA_H_
#define CHROME_BROWSER_NEARBY_SHARING_TRANSFER_METADATA_H_
#include <string>
#include "base/optional.h"
#include "url/gurl.h"
// Metadata about an ongoing transfer. Wraps transient data like status and
// progress.
class TransferMetadata {
public:
enum class Status {
kUnknown,
kConnecting,
kAwaitingLocalConfirmation,
kAwaitingRemoteAcceptance,
kAwaitingRemoteAcceptanceFailed,
kInProgress,
kComplete,
kFailed,
kRejected,
kCancelled,
kTimedOut,
kMediaUnavailable,
kMediaDownloading,
kNotEnoughSpace,
kUnsupportedAttachmentType,
kExternalProviderLaunched,
kMaxValue = kExternalProviderLaunched
};
TransferMetadata(Status status,
float progress,
base::Optional<std::string> token,
bool is_original,
bool is_final_status);
~TransferMetadata();
Status status() { return status_; }
float progress() { return progress_; }
// Represents the UKey2 token from Nearby Connection. base::nullopt if no
// UKey2 comparison is needed for this transfer.
const base::Optional<std::string>& token() { return token_; }
// True if this |TransferMetadata| has not been seen.
bool is_original() { return is_original_; }
// True if this |TransferMetadata| is the last status for this transfer.
bool is_final_status() { return is_final_status_; }
private:
Status status_;
float progress_;
base::Optional<std::string> token_;
bool is_original_;
bool is_final_status_;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_TRANSFER_METADATA_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_TRANSFER_UPDATE_CALLBACK_H_
#define CHROME_BROWSER_NEARBY_SHARING_TRANSFER_UPDATE_CALLBACK_H_
#include "base/observer_list_types.h"
#include "chrome/browser/nearby_sharing/share_target.h"
#include "chrome/browser/nearby_sharing/transfer_metadata.h"
// Reports the transfer status for an ongoing transfer with a |ShareTarget|.
class TransferUpdateCallback : public base::CheckedObserver {
public:
virtual void OnTransferUpdate(ShareTarget shareTarget,
TransferMetadata transferMetadata) = 0;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_TRANSFER_UPDATE_CALLBACK_H_
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