Commit 70631ad1 authored by Alex Chau's avatar Alex Chau Committed by Commit Bot

Create SharingService skeleton

- Added a skeleton of SharingService with 3 APIs, implementation is
  empty for now
- Added a proto for SharingMessage
- Added definition of handler for SharingMessage
- SharingService is initialized with a profile
- Added OWNERS file

Bug: 966028
Change-Id: I8beb1d001b8186b7259c7421f6d6d906bcf4a2f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1627367
Commit-Queue: Alex Chau <alexchau@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Auto-Submit: Alex Chau <alexchau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664238}
parent 44f00051
...@@ -1514,6 +1514,13 @@ jumbo_split_static_library("browser") { ...@@ -1514,6 +1514,13 @@ jumbo_split_static_library("browser") {
"sessions/session_tab_helper.h", "sessions/session_tab_helper.h",
"sessions/tab_restore_service_factory.cc", "sessions/tab_restore_service_factory.cc",
"sessions/tab_restore_service_factory.h", "sessions/tab_restore_service_factory.h",
"sharing/sharing_device_info.cc",
"sharing/sharing_device_info.h",
"sharing/sharing_message_handler.h",
"sharing/sharing_service.cc",
"sharing/sharing_service.h",
"sharing/sharing_service_factory.cc",
"sharing/sharing_service_factory.h",
"shell_integration.cc", "shell_integration.cc",
"shell_integration.h", "shell_integration.h",
"shell_integration_android.cc", "shell_integration_android.cc",
...@@ -1863,6 +1870,7 @@ jumbo_split_static_library("browser") { ...@@ -1863,6 +1870,7 @@ jumbo_split_static_library("browser") {
"//chrome/browser/resource_coordinator:mojo_bindings", "//chrome/browser/resource_coordinator:mojo_bindings",
"//chrome/browser/resource_coordinator:tab_manager_features", "//chrome/browser/resource_coordinator:tab_manager_features",
"//chrome/browser/safe_browsing", "//chrome/browser/safe_browsing",
"//chrome/browser/sharing/proto",
"//chrome/browser/ssl:proto", "//chrome/browser/ssl:proto",
"//chrome/browser/ui", "//chrome/browser/ui",
"//chrome/browser/ui/webui/bluetooth_internals", "//chrome/browser/ui/webui/bluetooth_internals",
......
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
#include "chrome/browser/send_tab_to_self/send_tab_to_self_util.h" #include "chrome/browser/send_tab_to_self/send_tab_to_self_util.h"
#include "chrome/browser/sessions/session_service_factory.h" #include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h" #include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/sharing/sharing_service_factory.h"
#include "chrome/browser/signin/about_signin_internals_factory.h" #include "chrome/browser/signin/about_signin_internals_factory.h"
#include "chrome/browser/signin/account_consistency_mode_manager_factory.h" #include "chrome/browser/signin/account_consistency_mode_manager_factory.h"
#include "chrome/browser/signin/account_investigator_factory.h" #include "chrome/browser/signin/account_investigator_factory.h"
...@@ -375,6 +376,7 @@ void ChromeBrowserMainExtraPartsProfiles:: ...@@ -375,6 +376,7 @@ void ChromeBrowserMainExtraPartsProfiles::
#if BUILDFLAG(ENABLE_SESSION_SERVICE) #if BUILDFLAG(ENABLE_SESSION_SERVICE)
SessionServiceFactory::GetInstance(); SessionServiceFactory::GetInstance();
#endif #endif
SharingServiceFactory::GetInstance();
ShortcutsBackendFactory::GetInstance(); ShortcutsBackendFactory::GetInstance();
SigninProfileAttributesUpdaterFactory::GetInstance(); SigninProfileAttributesUpdaterFactory::GetInstance();
......
peter@chromium.org
# COMPONENT: UI>Browser>Sharing
# Copyright 2019 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.
import("//third_party/protobuf/proto_library.gni")
group("proto_lite") {
public_deps = [
":proto",
"//third_party/protobuf:protobuf_lite",
]
}
proto_library("proto") {
sources = [
"sharing_message.proto",
]
}
// Copyright 2019 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.
syntax = "proto3";
package chrome_browser_sharing;
// Required in Chrome.
option optimize_for = LITE_RUNTIME;
// Message for sending between devices in Sharing.
message SharingMessage {
// Unique message identifier. required.
string message_id = 1;
// Identifier of sender. required.
string sender_guid = 2;
// Timestamp at which message was sent. required.
int64 send_timestamp = 3;
// Payload of the message, contains one of the messages below. required.
oneof payload {
PingMessage ping_message = 4;
AckMessage ack_message = 5;
}
}
// Message for pinging the receiver expecting an acknowledgement.
message PingMessage {
// Intentionally empty.
}
// Message for acknowledging the sender after a non-AckMessage is received.
message AckMessage {
// required.
string original_message_id = 1;
}
// Copyright 2019 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/sharing/sharing_device_info.h"
SharingDeviceInfo::SharingDeviceInfo(const std::string& guid,
const std::string& human_readable_name,
base::Time last_online_timestamp,
int capabilities)
: guid_(guid),
human_readable_name_(human_readable_name),
last_online_timestamp_(last_online_timestamp),
capabilities_(capabilities) {}
SharingDeviceInfo::~SharingDeviceInfo() = default;
const std::string& SharingDeviceInfo::guid() const {
return guid_;
}
const std::string& SharingDeviceInfo::human_readable_name() const {
return human_readable_name_;
}
base::Time SharingDeviceInfo::last_online_timestamp() const {
return last_online_timestamp_;
}
int SharingDeviceInfo::capabilities() const {
return capabilities_;
}
// Copyright 2019 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_SHARING_SHARING_DEVICE_INFO_H_
#define CHROME_BROWSER_SHARING_SHARING_DEVICE_INFO_H_
#include <string>
#include "base/macros.h"
#include "base/time/time.h"
// Capabilities of which a device can perform.
enum class SharingDeviceCapability { kNone = 0 };
// A class that holds information regarding the properties of a device.
class SharingDeviceInfo {
public:
SharingDeviceInfo(const std::string& guid,
const std::string& human_readable_name,
base::Time last_online_timestamp,
int capabilities);
~SharingDeviceInfo();
// Unique identifier for the device.
const std::string& guid() const;
// A human readable name of the device.
const std::string& human_readable_name() const;
// Returns the time at which this device was last online.
base::Time last_online_timestamp() const;
// Gets a bitmask of available capaiblities of the device, defined in
// SharingDeviceCapability enum.
int capabilities() const;
private:
const std::string guid_;
const std::string human_readable_name_;
const base::Time last_online_timestamp_;
int capabilities_;
DISALLOW_COPY_AND_ASSIGN(SharingDeviceInfo);
};
#endif // CHROME_BROWSER_SHARING_SHARING_DEVICE_INFO_H_
// Copyright 2019 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_SHARING_SHARING_MESSAGE_HANDLER_H_
#define CHROME_BROWSER_SHARING_SHARING_MESSAGE_HANDLER_H_
#include <string>
#include "chrome/browser/sharing/proto/sharing_message.pb.h"
// Interface for handling incoming SharingMessage.
class SharingMessageHandler {
public:
SharingMessageHandler();
virtual ~SharingMessageHandler();
// Called when a SharingMessage has been received.
virtual void OnMessage(
const chrome_browser_sharing::SharingMessage& message) = 0;
};
#endif // CHROME_BROWSER_SHARING_SHARING_MESSAGE_HANDLER_H_
// Copyright 2019 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/sharing/sharing_service.h"
SharingService::SharingService() = default;
SharingService::~SharingService() = default;
std::vector<SharingDeviceInfo> SharingService::GetDeviceCandidates(
int required_capabilities) const {
return std::vector<SharingDeviceInfo>();
}
bool SharingService::SendMessage(
const std::string& device_guid,
const chrome_browser_sharing::SharingMessage& message) {
return true;
}
void SharingService::RegisterHandler(
chrome_browser_sharing::SharingMessage::PayloadCase payload_type,
SharingMessageHandler* handler) {}
// Copyright 2019 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_SHARING_SHARING_SERVICE_H_
#define CHROME_BROWSER_SHARING_SHARING_SERVICE_H_
#include <string>
#include <vector>
#include "chrome/browser/sharing/proto/sharing_message.pb.h"
#include "chrome/browser/sharing/sharing_device_info.h"
#include "chrome/browser/sharing/sharing_message_handler.h"
#include "components/keyed_service/core/keyed_service.h"
// Class to manage lifecycle of sharing feature, and provide APIs to send
// sharing messages to other devices.
class SharingService : public KeyedService {
public:
SharingService();
~SharingService() override;
// Returns a list of DeviceInfo that is available to receive messages.
// All returned devices has the specified |required_capabilities| defined in
// SharingDeviceCapability enum.
std::vector<SharingDeviceInfo> GetDeviceCandidates(
int required_capabilities) const;
// Sends a message to the device specified by GUID.
bool SendMessage(const std::string& device_guid,
const chrome_browser_sharing::SharingMessage& message);
// Registers a handler of a given SharingMessage payload type.
void RegisterHandler(
chrome_browser_sharing::SharingMessage::PayloadCase payload_type,
SharingMessageHandler* handler);
private:
DISALLOW_COPY_AND_ASSIGN(SharingService);
};
#endif // CHROME_BROWSER_SHARING_SHARING_SERVICE_H_
// Copyright 2019 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/sharing/sharing_service_factory.h"
#include "base/memory/singleton.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/sharing/sharing_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/browser_context.h"
namespace {
constexpr char kServiceName[] = "SharingService";
} // namespace
// static
SharingServiceFactory* SharingServiceFactory::GetInstance() {
return base::Singleton<SharingServiceFactory>::get();
}
// static
SharingService* SharingServiceFactory::GetForBrowserContext(
content::BrowserContext* context) {
return static_cast<SharingService*>(
GetInstance()->GetServiceForBrowserContext(context, true));
}
SharingServiceFactory::SharingServiceFactory()
: BrowserContextKeyedServiceFactory(
kServiceName,
BrowserContextDependencyManager::GetInstance()) {}
SharingServiceFactory::~SharingServiceFactory() = default;
KeyedService* SharingServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new SharingService();
}
content::BrowserContext* SharingServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
bool SharingServiceFactory::ServiceIsCreatedWithBrowserContext() const {
return true;
}
// Copyright 2019 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_SHARING_SHARING_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SHARING_SHARING_SERVICE_FACTORY_H_
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace base {
template <typename T>
struct DefaultSingletonTraits;
} // namespace base
namespace content {
class BrowserContext;
}
class SharingService;
// Factory for SharingService.
class SharingServiceFactory : public BrowserContextKeyedServiceFactory {
public:
// Returns singleton instance of SharingServiceFactory.
static SharingServiceFactory* GetInstance();
// Returns the SharingService associated with |context|.
static SharingService* GetForBrowserContext(content::BrowserContext* context);
private:
friend struct base::DefaultSingletonTraits<SharingServiceFactory>;
SharingServiceFactory();
~SharingServiceFactory() override;
// BrowserContextKeyedServiceFactory overrides:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
bool ServiceIsCreatedWithBrowserContext() const override;
DISALLOW_COPY_AND_ASSIGN(SharingServiceFactory);
};
#endif // CHROME_BROWSER_SHARING_SHARING_SERVICE_FACTORY_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