diff options
author | zea <zea@chromium.org> | 2015-10-27 17:16:11 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-28 00:17:03 +0000 |
commit | 035008523b829d1f62db6b2ec825b8ca2aa4736d (patch) | |
tree | 9dac3c3baeff711b568317909741376b4c18a73b | |
parent | a88f62b41cdce337b9d0c74a57b01957790e8605 (diff) | |
download | chromium_src-035008523b829d1f62db6b2ec825b8ca2aa4736d.zip chromium_src-035008523b829d1f62db6b2ec825b8ca2aa4736d.tar.gz chromium_src-035008523b829d1f62db6b2ec825b8ca2aa4736d.tar.bz2 |
[Sync] Componentize local_device_info_provider_impl and test
Pass channel and version info in at construction time, and the blocking pool at initialize
time.
BUG=396136
Review URL: https://codereview.chromium.org/1397913002
Cr-Commit-Position: refs/heads/master@{#356447}
14 files changed, 99 insertions, 72 deletions
diff --git a/chrome/browser/sync/glue/sync_backend_host_core.cc b/chrome/browser/sync/glue/sync_backend_host_core.cc index 3192d1b..feaf26c 100644 --- a/chrome/browser/sync/glue/sync_backend_host_core.cc +++ b/chrome/browser/sync/glue/sync_backend_host_core.cc @@ -9,12 +9,12 @@ #include "base/location.h" #include "base/metrics/histogram.h" #include "base/single_thread_task_runner.h" -#include "chrome/browser/sync/glue/local_device_info_provider_impl.h" #include "components/data_use_measurement/core/data_use_user_data.h" #include "components/invalidation/public/invalidation_util.h" #include "components/invalidation/public/object_id_invalidation_map.h" #include "components/sync_driver/glue/sync_backend_registrar.h" #include "components/sync_driver/invalidation_adapter.h" +#include "components/sync_driver/local_device_info_provider_impl.h" #include "sync/internal_api/public/events/protocol_event.h" #include "sync/internal_api/public/http_post_provider_factory.h" #include "sync/internal_api/public/internal_components_factory.h" diff --git a/chrome/browser/sync/profile_sync_components_factory_impl.cc b/chrome/browser/sync/profile_sync_components_factory_impl.cc index 4cc8ec2..deb02f81 100644 --- a/chrome/browser/sync/profile_sync_components_factory_impl.cc +++ b/chrome/browser/sync/profile_sync_components_factory_impl.cc @@ -11,7 +11,6 @@ #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url_service_factory.h" -#include "chrome/browser/sync/glue/local_device_info_provider_impl.h" #include "chrome/browser/sync/glue/sync_backend_host.h" #include "chrome/browser/sync/glue/sync_backend_host_impl.h" #include "chrome/browser/sync/glue/theme_data_type_controller.h" @@ -38,6 +37,7 @@ #include "components/sync_driver/data_type_manager_impl.h" #include "components/sync_driver/device_info_data_type_controller.h" #include "components/sync_driver/glue/chrome_report_unrecoverable_error.h" +#include "components/sync_driver/local_device_info_provider_impl.h" #include "components/sync_driver/proxy_data_type_controller.h" #include "components/sync_driver/sync_client.h" #include "components/sync_driver/ui_data_type_controller.h" @@ -49,6 +49,7 @@ #include "sync/internal_api/public/attachments/attachment_service.h" #include "sync/internal_api/public/attachments/attachment_service_impl.h" #include "sync/internal_api/public/attachments/attachment_uploader_impl.h" +#include "ui/base/device_form_factor.h" #if defined(ENABLE_APP_LIST) #include "ui/app_list/app_list_switches.h" @@ -418,7 +419,10 @@ ProfileSyncComponentsFactoryImpl::CreateSyncBackendHost( scoped_ptr<sync_driver::LocalDeviceInfoProvider> ProfileSyncComponentsFactoryImpl::CreateLocalDeviceInfoProvider() { return scoped_ptr<sync_driver::LocalDeviceInfoProvider>( - new browser_sync::LocalDeviceInfoProviderImpl()); + new browser_sync::LocalDeviceInfoProviderImpl( + chrome::GetChannel(), + chrome::GetVersionString(), + ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET)); } class TokenServiceProvider diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 49682cc..8637210 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -1127,7 +1127,8 @@ void ProfileSyncService::OnBackendInitialized( signin_client->GetSigninScopedDeviceId(); // Initialize local device info. - local_device_->Initialize(cache_guid, signin_scoped_device_id); + local_device_->Initialize(cache_guid, signin_scoped_device_id, + content::BrowserThread::GetBlockingPool()); if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK) ConfigureDataTypeManager(); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 22f1682..d964fec 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2864,8 +2864,6 @@ 'browser/sync/chrome_sync_client.h', 'browser/sync/glue/extensions_activity_monitor.cc', 'browser/sync/glue/extensions_activity_monitor.h', - 'browser/sync/glue/local_device_info_provider_impl.cc', - 'browser/sync/glue/local_device_info_provider_impl.h', 'browser/sync/glue/sync_backend_host.cc', 'browser/sync/glue/sync_backend_host.h', 'browser/sync/glue/sync_backend_host_core.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 4a47e4c..70be26b 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -222,8 +222,6 @@ 'browser/sync/abstract_profile_sync_service_test.cc', 'browser/sync/abstract_profile_sync_service_test.h', 'browser/sync/backend_migrator_unittest.cc', - 'browser/sync/chrome_sync_client_unittest.cc', - 'browser/sync/glue/local_device_info_provider_unittest.cc', 'browser/sync/glue/search_engine_data_type_controller_unittest.cc', 'browser/sync/glue/sync_backend_host_impl_unittest.cc', 'browser/sync/glue/sync_backend_host_mock.cc', diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 67fef78..1de188b 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -671,9 +671,6 @@ 'sync_driver/device_info_sync_service_unittest.cc', 'sync_driver/frontend_data_type_controller_unittest.cc', 'sync_driver/generic_change_processor_unittest.cc', - 'sync_driver/glue/browser_thread_model_worker_unittest.cc', - 'sync_driver/glue/sync_backend_registrar_unittest.cc', - 'sync_driver/glue/ui_model_worker_unittest.cc', 'sync_driver/model_association_manager_unittest.cc', 'sync_driver/non_blocking_data_type_controller_unittest.cc', 'sync_driver/non_frontend_data_type_controller_unittest.cc', diff --git a/components/sync_driver.gypi b/components/sync_driver.gypi index 0a578cf..845b93d 100644 --- a/components/sync_driver.gypi +++ b/components/sync_driver.gypi @@ -80,6 +80,8 @@ 'sync_driver/invalidation_helper.cc', 'sync_driver/invalidation_helper.h', 'sync_driver/local_device_info_provider.h', + 'sync_driver/local_device_info_provider_impl.cc', + 'sync_driver/local_device_info_provider_impl.h', 'sync_driver/model_association_manager.cc', 'sync_driver/model_association_manager.h', 'sync_driver/model_associator.h', diff --git a/components/sync_driver/BUILD.gn b/components/sync_driver/BUILD.gn index 50a620e..a23d755 100644 --- a/components/sync_driver/BUILD.gn +++ b/components/sync_driver/BUILD.gn @@ -61,6 +61,8 @@ source_set("sync_driver") { "invalidation_helper.cc", "invalidation_helper.h", "local_device_info_provider.h", + "local_device_info_provider_impl.cc", + "local_device_info_provider_impl.h", "model_association_manager.cc", "model_association_manager.h", "model_associator.h", @@ -213,6 +215,7 @@ source_set("unit_tests") { "glue/browser_thread_model_worker_unittest.cc", "glue/sync_backend_registrar_unittest.cc", "glue/ui_model_worker_unittest.cc", + "local_device_info_provider_unittest.cc", "model_association_manager_unittest.cc", "non_blocking_data_type_controller_unittest.cc", "non_frontend_data_type_controller_unittest.cc", diff --git a/components/sync_driver/local_device_info_provider.h b/components/sync_driver/local_device_info_provider.h index d61041e..464146f 100644 --- a/components/sync_driver/local_device_info_provider.h +++ b/components/sync_driver/local_device_info_provider.h @@ -8,11 +8,15 @@ #include <string> #include "base/callback_list.h" +namespace base { +class TaskRunner; +} + namespace sync_driver { class DeviceInfo; -// Interface for providing sync specific informaiton about the +// Interface for providing sync specific information about the // local device. class LocalDeviceInfoProvider { public: @@ -40,7 +44,8 @@ class LocalDeviceInfoProvider { // Starts initializing local device info. virtual void Initialize( const std::string& cache_guid, - const std::string& signin_scoped_device_id) = 0; + const std::string& signin_scoped_device_id, + const scoped_refptr<base::TaskRunner>& blocking_task_runner) = 0; // Registers a callback to be called when local device info becomes available. // The callback will remain registered until the diff --git a/chrome/browser/sync/glue/local_device_info_provider_impl.cc b/components/sync_driver/local_device_info_provider_impl.cc index 282814bc..69abc98 100644 --- a/chrome/browser/sync/glue/local_device_info_provider_impl.cc +++ b/components/sync_driver/local_device_info_provider_impl.cc @@ -2,25 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "components/sync_driver/local_device_info_provider_impl.h" + #include "base/bind.h" -#include "chrome/browser/sync/glue/local_device_info_provider_impl.h" -#include "chrome/common/channel_info.h" +#include "base/task_runner.h" #include "components/sync_driver/sync_util.h" -#include "content/public/browser/browser_thread.h" #include "sync/util/get_session_name.h" -#include "ui/base/device_form_factor.h" namespace browser_sync { namespace { -#if defined(OS_ANDROID) -bool IsTabletUI() { - return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET; -} -#endif - -sync_pb::SyncEnums::DeviceType GetLocalDeviceType() { +sync_pb::SyncEnums::DeviceType GetLocalDeviceType(bool is_tablet) { #if defined(OS_CHROMEOS) return sync_pb::SyncEnums_DeviceType_TYPE_CROS; #elif defined(OS_LINUX) @@ -30,8 +23,8 @@ sync_pb::SyncEnums::DeviceType GetLocalDeviceType() { #elif defined(OS_WIN) return sync_pb::SyncEnums_DeviceType_TYPE_WIN; #elif defined(OS_ANDROID) - return IsTabletUI() ? sync_pb::SyncEnums_DeviceType_TYPE_TABLET - : sync_pb::SyncEnums_DeviceType_TYPE_PHONE; + return is_tablet ? sync_pb::SyncEnums_DeviceType_TYPE_TABLET + : sync_pb::SyncEnums_DeviceType_TYPE_PHONE; #else return sync_pb::SyncEnums_DeviceType_TYPE_OTHER; #endif @@ -39,29 +32,33 @@ sync_pb::SyncEnums::DeviceType GetLocalDeviceType() { } // namespace -LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl() - : weak_factory_(this) { -} +LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl( + version_info::Channel channel, + const std::string& version, + bool is_tablet) + : channel_(channel), + version_(version), + is_tablet_(is_tablet), + weak_factory_(this) {} -LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() { -} +LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {} -const sync_driver::DeviceInfo* -LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const { +const sync_driver::DeviceInfo* LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() + const { return local_device_info_.get(); } std::string LocalDeviceInfoProviderImpl::GetSyncUserAgent() const { -#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) - return MakeDesktopUserAgentForSync(chrome::GetChannel()); -#elif defined(OS_CHROMEOS) - return MakeUserAgentForSync("CROS ", chrome::GetChannel()); +#if defined(OS_CHROMEOS) + return MakeUserAgentForSync("CROS ", channel_); #elif defined(OS_ANDROID) - if (IsTabletUI()) { - return MakeUserAgentForSync("ANDROID-TABLET ", chrome::GetChannel()); + if (is_tablet_) { + return MakeUserAgentForSync("ANDROID-TABLET ", channel_); } else { - return MakeUserAgentForSync("ANDROID-PHONE ", chrome::GetChannel()); + return MakeUserAgentForSync("ANDROID-PHONE ", channel_); } +#elif !defined(OS_CHROMEOS) && !defined(OS_ANDROID) + return MakeDesktopUserAgentForSync(channel_); #endif } @@ -77,15 +74,16 @@ LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback( } void LocalDeviceInfoProviderImpl::Initialize( - const std::string& cache_guid, const std::string& signin_scoped_device_id) { + const std::string& cache_guid, + const std::string& signin_scoped_device_id, + const scoped_refptr<base::TaskRunner>& blocking_task_runner) { DCHECK(!cache_guid.empty()); cache_guid_ = cache_guid; syncer::GetSessionName( - content::BrowserThread::GetBlockingPool(), + blocking_task_runner, base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation, - weak_factory_.GetWeakPtr(), - cache_guid, + weak_factory_.GetWeakPtr(), cache_guid, signin_scoped_device_id)); } @@ -93,13 +91,9 @@ void LocalDeviceInfoProviderImpl::InitializeContinuation( const std::string& guid, const std::string& signin_scoped_device_id, const std::string& session_name) { - local_device_info_.reset( - new sync_driver::DeviceInfo(guid, - session_name, - chrome::GetVersionString(), - GetSyncUserAgent(), - GetLocalDeviceType(), - signin_scoped_device_id)); + local_device_info_.reset(new sync_driver::DeviceInfo( + guid, session_name, version_, GetSyncUserAgent(), + GetLocalDeviceType(is_tablet_), signin_scoped_device_id)); // Notify observers. callback_list_.Notify(); diff --git a/chrome/browser/sync/glue/local_device_info_provider_impl.h b/components/sync_driver/local_device_info_provider_impl.h index 7323cf2..306f81f 100644 --- a/chrome/browser/sync/glue/local_device_info_provider_impl.h +++ b/components/sync_driver/local_device_info_provider_impl.h @@ -2,36 +2,51 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_SYNC_GLUE_LOCAL_DEVICE_INFO_PROVIDER_IMPL_H_ -#define CHROME_BROWSER_SYNC_GLUE_LOCAL_DEVICE_INFO_PROVIDER_IMPL_H_ +#ifndef COMPONENTS_SYNC_DRIVER_LOCAL_DEVICE_INFO_PROVIDER_IMPL_H_ +#define COMPONENTS_SYNC_DRIVER_LOCAL_DEVICE_INFO_PROVIDER_IMPL_H_ +#include "base/macros.h" #include "base/memory/weak_ptr.h" #include "components/sync_driver/device_info.h" #include "components/sync_driver/local_device_info_provider.h" +#include "components/version_info/version_info.h" namespace browser_sync { class LocalDeviceInfoProviderImpl : public sync_driver::LocalDeviceInfoProvider { public: - LocalDeviceInfoProviderImpl(); + LocalDeviceInfoProviderImpl(version_info::Channel channel, + const std::string& version, + bool is_tablet); ~LocalDeviceInfoProviderImpl() override; // LocalDeviceInfoProvider implementation. const sync_driver::DeviceInfo* GetLocalDeviceInfo() const override; std::string GetSyncUserAgent() const override; std::string GetLocalSyncCacheGUID() const override; - void Initialize(const std::string& cache_guid, - const std::string& signin_scoped_device_id) override; + void Initialize( + const std::string& cache_guid, + const std::string& signin_scoped_device_id, + const scoped_refptr<base::TaskRunner>& blocking_task_runner) override; scoped_ptr<Subscription> RegisterOnInitializedCallback( const base::Closure& callback) override; private: - void InitializeContinuation(const std::string& guid, const std::string& signin_scoped_device_id, const std::string& session_name); + // The channel (CANARY, DEV, BETA, etc.) of the current client. + const version_info::Channel channel_; + + // The version string for the current client. + const std::string version_; + + // Whether this device has a tablet form factor (only used on Android + // devices). + const bool is_tablet_; + std::string cache_guid_; scoped_ptr<sync_driver::DeviceInfo> local_device_info_; base::CallbackList<void(void)> callback_list_; @@ -42,4 +57,4 @@ class LocalDeviceInfoProviderImpl } // namespace browser_sync -#endif // CHROME_BROWSER_SYNC_GLUE_LOCAL_DEVICE_INFO_PROVIDER_IMPL_H_ +#endif // COMPONENTS_SYNC_DRIVER_LOCAL_DEVICE_INFO_PROVIDER_IMPL_H_ diff --git a/components/sync_driver/local_device_info_provider_mock.cc b/components/sync_driver/local_device_info_provider_mock.cc index 8c22b8b..47d2146 100644 --- a/components/sync_driver/local_device_info_provider_mock.cc +++ b/components/sync_driver/local_device_info_provider_mock.cc @@ -42,7 +42,9 @@ std::string LocalDeviceInfoProviderMock::GetLocalSyncCacheGUID() const { } void LocalDeviceInfoProviderMock::Initialize( - const std::string& cache_guid, const std::string& signin_scoped_device_id) { + const std::string& cache_guid, + const std::string& signin_scoped_device_id, + const scoped_refptr<base::TaskRunner>& blocking_task_runner) { // Ignored for the mock provider. } diff --git a/components/sync_driver/local_device_info_provider_mock.h b/components/sync_driver/local_device_info_provider_mock.h index 454360a..8ae2e60 100644 --- a/components/sync_driver/local_device_info_provider_mock.h +++ b/components/sync_driver/local_device_info_provider_mock.h @@ -30,8 +30,10 @@ class LocalDeviceInfoProviderMock const DeviceInfo* GetLocalDeviceInfo() const override; std::string GetSyncUserAgent() const override; std::string GetLocalSyncCacheGUID() const override; - void Initialize(const std::string& cache_guid, - const std::string& signin_scoped_device_id) override; + void Initialize( + const std::string& cache_guid, + const std::string& signin_scoped_device_id, + const scoped_refptr<base::TaskRunner>& blocking_task_runner) override; scoped_ptr<Subscription> RegisterOnInitializedCallback( const base::Closure& callback) override; diff --git a/chrome/browser/sync/glue/local_device_info_provider_unittest.cc b/components/sync_driver/local_device_info_provider_unittest.cc index 9176c30..21b7ced 100644 --- a/chrome/browser/sync/glue/local_device_info_provider_unittest.cc +++ b/components/sync_driver/local_device_info_provider_unittest.cc @@ -5,7 +5,8 @@ #include "base/bind.h" #include "base/message_loop/message_loop.h" #include "base/run_loop.h" -#include "chrome/browser/sync/glue/local_device_info_provider_impl.h" +#include "components/sync_driver/local_device_info_provider_impl.h" +#include "components/version_info/version_info.h" #include "sync/util/get_session_name.h" #include "testing/gtest/include/gtest/gtest.h" @@ -17,13 +18,16 @@ namespace browser_sync { const char kLocalDeviceGuid[] = "foo"; const char kSigninScopedDeviceId[] = "device_id"; -class LocalDeviceInfoProviderTest : public testing::Test { +class SyncLocalDeviceInfoProviderTest : public testing::Test { public: - LocalDeviceInfoProviderTest() - : called_back_(false) {} - ~LocalDeviceInfoProviderTest() override {} + SyncLocalDeviceInfoProviderTest() : called_back_(false) {} + ~SyncLocalDeviceInfoProviderTest() override {} - void SetUp() override { provider_.reset(new LocalDeviceInfoProviderImpl()); } + void SetUp() override { + provider_.reset(new LocalDeviceInfoProviderImpl( + version_info::Channel::UNKNOWN, + version_info::GetVersionStringWithModifier("UNKNOWN"), false)); + } void TearDown() override { provider_.reset(); @@ -33,14 +37,16 @@ class LocalDeviceInfoProviderTest : public testing::Test { protected: void InitializeProvider() { // Start initialization. - provider_->Initialize(kLocalDeviceGuid, kSigninScopedDeviceId); + provider_->Initialize(kLocalDeviceGuid, + kSigninScopedDeviceId, + message_loop_.task_runner()); // Subscribe to the notification and wait until the callback // is called. The callback will quit the loop. base::RunLoop run_loop; scoped_ptr<LocalDeviceInfoProvider::Subscription> subscription( provider_->RegisterOnInitializedCallback( - base::Bind(&LocalDeviceInfoProviderTest::QuitLoopOnInitialized, + base::Bind(&SyncLocalDeviceInfoProviderTest::QuitLoopOnInitialized, base::Unretained(this), &run_loop))); run_loop.Run(); } @@ -58,14 +64,14 @@ class LocalDeviceInfoProviderTest : public testing::Test { base::MessageLoop message_loop_; }; -TEST_F(LocalDeviceInfoProviderTest, OnInitializedCallback) { +TEST_F(SyncLocalDeviceInfoProviderTest, OnInitializedCallback) { ASSERT_FALSE(called_back_); InitializeProvider(); EXPECT_TRUE(called_back_); } -TEST_F(LocalDeviceInfoProviderTest, GetLocalDeviceInfo) { +TEST_F(SyncLocalDeviceInfoProviderTest, GetLocalDeviceInfo) { ASSERT_EQ(NULL, provider_->GetLocalDeviceInfo()); InitializeProvider(); @@ -82,7 +88,7 @@ TEST_F(LocalDeviceInfoProviderTest, GetLocalDeviceInfo) { local_device_info->sync_user_agent()); } -TEST_F(LocalDeviceInfoProviderTest, GetLocalSyncCacheGUID) { +TEST_F(SyncLocalDeviceInfoProviderTest, GetLocalSyncCacheGUID) { ASSERT_EQ(std::string(), provider_->GetLocalSyncCacheGUID()); InitializeProvider(); |