Skip to content

Commit

Permalink
Subclass browser_sync::ProfileSyncService
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh committed May 7, 2019
1 parent 01718b2 commit 9035e6c
Show file tree
Hide file tree
Showing 13 changed files with 995 additions and 882 deletions.
38 changes: 25 additions & 13 deletions browser/extensions/api/brave_sync_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <vector>

#include "brave/common/extensions/api/brave_sync.h"
#include "brave/components/brave_sync/brave_profile_sync_service.h"
#include "brave/components/brave_sync/client/brave_sync_client.h"
#include "brave/components/brave_sync/client/client_ext_impl_data.h"
#include "brave/components/brave_sync/values_conv.h"
Expand All @@ -18,16 +19,17 @@
#include "components/browser_sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"

using browser_sync::ProfileSyncService;
using brave_sync::BraveProfileSyncService;
using content::BrowserContext;

namespace extensions {
namespace api {

namespace {

ProfileSyncService* GetProfileSyncService(BrowserContext* browser_context) {
return ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile(
BraveProfileSyncService* GetProfileSyncService(
BrowserContext* browser_context) {
return ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile(
Profile::FromBrowserContext(browser_context));
}

Expand All @@ -37,7 +39,8 @@ ExtensionFunction::ResponseAction BraveSyncGetInitDataFunction::Run() {
brave_sync::GetInitData::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

ProfileSyncService* sync_service = GetProfileSyncService(browser_context());
BraveProfileSyncService* sync_service =
GetProfileSyncService(browser_context());
DCHECK(sync_service);
sync_service->OnGetInitData(params->sync_version);

Expand All @@ -49,7 +52,8 @@ ExtensionFunction::ResponseAction BraveSyncSyncSetupErrorFunction::Run() {
brave_sync::SyncSetupError::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

ProfileSyncService* sync_service = GetProfileSyncService(browser_context());
BraveProfileSyncService* sync_service =
GetProfileSyncService(browser_context());
DCHECK(sync_service);
sync_service->OnSyncSetupError(
params->error);
Expand All @@ -62,7 +66,8 @@ ExtensionFunction::ResponseAction BraveSyncSyncDebugFunction::Run() {
brave_sync::SyncDebug::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

ProfileSyncService* sync_service = GetProfileSyncService(browser_context());
BraveProfileSyncService* sync_service =
GetProfileSyncService(browser_context());
DCHECK(sync_service);
sync_service->OnSyncDebug(
params->message);
Expand All @@ -75,7 +80,8 @@ ExtensionFunction::ResponseAction BraveSyncSaveInitDataFunction::Run() {
brave_sync::SaveInitData::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

ProfileSyncService* sync_service = GetProfileSyncService(browser_context());
BraveProfileSyncService* sync_service =
GetProfileSyncService(browser_context());
DCHECK(sync_service);
sync_service->OnSaveInitData(
params->seed ? *params->seed : std::vector<uint8_t>(),
Expand All @@ -85,7 +91,8 @@ ExtensionFunction::ResponseAction BraveSyncSaveInitDataFunction::Run() {
}

ExtensionFunction::ResponseAction BraveSyncSyncReadyFunction::Run() {
ProfileSyncService* sync_service = GetProfileSyncService(browser_context());
BraveProfileSyncService* sync_service =
GetProfileSyncService(browser_context());
DCHECK(sync_service);
sync_service->OnSyncReady();

Expand All @@ -100,7 +107,8 @@ ExtensionFunction::ResponseAction BraveSyncGetExistingObjectsFunction::Run() {
auto records = std::make_unique<std::vector<::brave_sync::SyncRecordPtr>>();
::brave_sync::ConvertSyncRecords(params->records, *records.get());

ProfileSyncService* sync_service = GetProfileSyncService(browser_context());
BraveProfileSyncService* sync_service =
GetProfileSyncService(browser_context());
DCHECK(sync_service);
sync_service->OnGetExistingObjects(
params->category_name,
Expand All @@ -119,7 +127,8 @@ ExtensionFunction::ResponseAction BraveSyncResolvedSyncRecordsFunction::Run() {
auto records = std::make_unique<std::vector<::brave_sync::SyncRecordPtr>>();
::brave_sync::ConvertSyncRecords(params->records, *records.get());

ProfileSyncService* sync_service = GetProfileSyncService(browser_context());
BraveProfileSyncService* sync_service =
GetProfileSyncService(browser_context());
DCHECK(sync_service);
sync_service->OnResolvedSyncRecords(
params->category_name,
Expand All @@ -134,7 +143,8 @@ BraveSyncSaveBookmarksBaseOrderFunction::Run() {
brave_sync::SaveBookmarksBaseOrder::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

ProfileSyncService* sync_service = GetProfileSyncService(browser_context());
BraveProfileSyncService* sync_service =
GetProfileSyncService(browser_context());
DCHECK(sync_service);
sync_service->OnSaveBookmarksBaseOrder(
params->order);
Expand All @@ -147,7 +157,8 @@ ExtensionFunction::ResponseAction BraveSyncSyncWordsPreparedFunction::Run() {
brave_sync::SyncWordsPrepared::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

ProfileSyncService* sync_service = GetProfileSyncService(browser_context());
BraveProfileSyncService* sync_service =
GetProfileSyncService(browser_context());
DCHECK(sync_service);
sync_service->OnSyncWordsPrepared(params->words);

Expand All @@ -156,7 +167,8 @@ ExtensionFunction::ResponseAction BraveSyncSyncWordsPreparedFunction::Run() {

ExtensionFunction::ResponseAction BraveSyncExtensionInitializedFunction::Run() {
// Also inform sync client extension started
ProfileSyncService* sync_service = GetProfileSyncService(browser_context());
BraveProfileSyncService* sync_service =
GetProfileSyncService(browser_context());
DCHECK(sync_service);
sync_service->GetBraveSyncClient()->OnExtensionInitialized();

Expand Down
3 changes: 2 additions & 1 deletion browser/ui/webui/sync/sync_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/memory/weak_ptr.h"
#include "brave/common/webui_url_constants.h"
#include "brave/components/brave_sync/brave_profile_sync_service.h"
#include "brave/components/brave_sync/brave_sync_service.h"
#include "brave/components/brave_sync/brave_sync_service_observer.h"
#include "brave/components/brave_sync/grit/brave_sync_resources.h"
Expand Down Expand Up @@ -121,7 +122,7 @@ void SyncUIDOMHandler::Init() {
Profile* profile = Profile::FromWebUI(web_ui());
sync_service_ =
static_cast<brave_sync::BraveSyncService*>(
ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile(profile));
ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile(profile));
if (sync_service_)
sync_service_->AddObserver(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "brave/components/brave_sync/brave_profile_sync_service.h"
using brave_sync::BraveProfileSyncService;
#include "../../../../../chrome/browser/sync/profile_sync_service_factory.cc"

// static
BraveProfileSyncService*
ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile(Profile* profile) {
return static_cast<BraveProfileSyncService*>(GetForProfile(profile));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace brave_sync {
class BraveProfileSyncService;
} // namespace brave_sync
#include "../../../../../chrome/browser/sync/profile_sync_service_factory.h"
Loading

0 comments on commit 9035e6c

Please sign in to comment.