diff options
author | Primiano Tucci <primiano@google.com> | 2014-09-30 14:45:55 +0100 |
---|---|---|
committer | Primiano Tucci <primiano@google.com> | 2014-09-30 14:45:55 +0100 |
commit | 1320f92c476a1ad9d19dba2a48c72b75566198e9 (patch) | |
tree | ea7f149ccad687b22c18a72b729646568b2d54fb /chrome/browser/sync/glue | |
parent | 39b78c562f50ad7d5551ee861121f899239525a2 (diff) | |
download | chromium_org-1320f92c476a1ad9d19dba2a48c72b75566198e9.tar.gz |
Merge from Chromium at DEPS revision 267aeeb8d85c
This commit was generated by merge_to_master.py.
Change-Id: Id3aac9713b301fae64408cdaee0888724eeb7c0e
Diffstat (limited to 'chrome/browser/sync/glue')
46 files changed, 544 insertions, 1724 deletions
diff --git a/chrome/browser/sync/glue/bookmark_change_processor.cc b/chrome/browser/sync/glue/bookmark_change_processor.cc index d6c4d6a0d4..ae0e854ab6 100644 --- a/chrome/browser/sync/glue/bookmark_change_processor.cc +++ b/chrome/browser/sync/glue/bookmark_change_processor.cc @@ -23,6 +23,7 @@ #include "chrome/browser/undo/bookmark_undo_service.h" #include "chrome/browser/undo/bookmark_undo_service_factory.h" #include "chrome/browser/undo/bookmark_undo_utils.h" +#include "components/bookmarks/browser/bookmark_client.h" #include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_utils.h" #include "content/public/browser/browser_thread.h" @@ -214,6 +215,11 @@ void BookmarkChangeProcessor::RemoveAllChildNodes( } void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) { + if (!CanSyncNode(node)) { + NOTREACHED(); + return; + } + const BookmarkNode* parent = node->parent(); int index = node->parent()->GetIndexOf(node); @@ -262,7 +268,9 @@ void BookmarkChangeProcessor::BookmarkNodeAdded(BookmarkModel* model, const BookmarkNode* parent, int index) { DCHECK(share_handle()); - CreateOrUpdateSyncNode(parent->GetChild(index)); + const BookmarkNode* node = parent->GetChild(index); + if (CanSyncNode(node)) + CreateOrUpdateSyncNode(node); } // static @@ -301,7 +309,8 @@ void BookmarkChangeProcessor::BookmarkNodeRemoved( int index, const BookmarkNode* node, const std::set<GURL>& removed_urls) { - RemoveSyncNodeHierarchy(node); + if (CanSyncNode(node)) + RemoveSyncNodeHierarchy(node); } void BookmarkChangeProcessor::BookmarkAllUserNodesRemoved( @@ -312,6 +321,8 @@ void BookmarkChangeProcessor::BookmarkAllUserNodesRemoved( void BookmarkChangeProcessor::BookmarkNodeChanged(BookmarkModel* model, const BookmarkNode* node) { + if (!CanSyncNode(node)) + return; // We shouldn't see changes to the top-level nodes. if (model->is_permanent_node(node)) { NOTREACHED() << "Saw update to permanent node!"; @@ -354,6 +365,10 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, const BookmarkNode* old_parent, int old_index, const BookmarkNode* new_parent, int new_index) { const BookmarkNode* child = new_parent->GetChild(new_index); + + if (!CanSyncNode(child)) + return; + // We shouldn't see changes to the top-level nodes. if (model->is_permanent_node(child)) { NOTREACHED() << "Saw update to permanent node!"; @@ -399,6 +414,8 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( BookmarkModel* model, const BookmarkNode* node) { + if (!CanSyncNode(node)) + return; int64 new_version = syncer::syncable::kInvalidTransactionVersion; std::vector<const BookmarkNode*> children; { @@ -513,9 +530,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( model->RemoveObserver(this); // Changes made to the bookmark model due to sync should not be undoable. -#if !defined(OS_ANDROID) ScopedSuspendBookmarkUndo suspend_undo(profile_); -#endif // Notify UI intensive observers of BookmarkModel that we are about to make // potentially significant changes to it, so the updates may be batched. For @@ -874,4 +889,8 @@ void BookmarkChangeProcessor::SetSyncNodeFavicon( } } +bool BookmarkChangeProcessor::CanSyncNode(const BookmarkNode* node) { + return bookmark_model_->client()->CanSyncNode(node); +} + } // namespace browser_sync diff --git a/chrome/browser/sync/glue/bookmark_change_processor.h b/chrome/browser/sync/glue/bookmark_change_processor.h index 88909a0ba8..cf592f18df 100644 --- a/chrome/browser/sync/glue/bookmark_change_processor.h +++ b/chrome/browser/sync/glue/bookmark_change_processor.h @@ -206,6 +206,9 @@ class BookmarkChangeProcessor : public BookmarkModelObserver, // Creates or updates a sync node associated with |node|. void CreateOrUpdateSyncNode(const BookmarkNode* node); + // Returns false if |node| should not be synced. + bool CanSyncNode(const BookmarkNode* node); + // The bookmark model we are processing changes from. Non-NULL when // |running_| is true. BookmarkModel* bookmark_model_; diff --git a/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc b/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc index 3c00de5cf5..5f817cd14f 100644 --- a/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc @@ -67,7 +67,7 @@ KeyedService* BuildBookmarkModelWithoutLoading( Profile* profile = static_cast<Profile*>(context); ChromeBookmarkClient* bookmark_client = ChromeBookmarkClientFactory::GetForProfile(profile); - BookmarkModel* bookmark_model = new BookmarkModel(bookmark_client, false); + BookmarkModel* bookmark_model = new BookmarkModel(bookmark_client); bookmark_client->Init(bookmark_model); return bookmark_model; } diff --git a/chrome/browser/sync/glue/bookmark_model_associator.cc b/chrome/browser/sync/glue/bookmark_model_associator.cc index c77bf967c7..69e4a7f091 100644 --- a/chrome/browser/sync/glue/bookmark_model_associator.cc +++ b/chrome/browser/sync/glue/bookmark_model_associator.cc @@ -402,9 +402,8 @@ syncer::SyncError BookmarkModelAssociator::AssociateModels( syncer::SyncMergeResult* syncer_merge_result) { // Since any changes to the bookmark model made here are not user initiated, // these change should not be undoable and so suspend the undo tracking. -#if !defined(OS_ANDROID) ScopedSuspendBookmarkUndo suspend_undo(profile_); -#endif + syncer::SyncError error = CheckModelSyncState(local_merge_result, syncer_merge_result); if (error.IsSet()) diff --git a/chrome/browser/sync/glue/chrome_report_unrecoverable_error.cc b/chrome/browser/sync/glue/chrome_report_unrecoverable_error.cc index ff0e2b5904..9c7797bcae 100644 --- a/chrome/browser/sync/glue/chrome_report_unrecoverable_error.cc +++ b/chrome/browser/sync/glue/chrome_report_unrecoverable_error.cc @@ -20,7 +20,7 @@ void ChromeReportUnrecoverableError() { } // We only want to upload |kErrorUploadRatio| ratio of errors. - const double kErrorUploadRatio = 0.0; + const double kErrorUploadRatio = 0.15; if (kErrorUploadRatio <= 0.0) return; // We are not allowed to upload errors. double random_number = base::RandDouble(); diff --git a/chrome/browser/sync/glue/device_info.cc b/chrome/browser/sync/glue/device_info.cc deleted file mode 100644 index f3ea3602dd..0000000000 --- a/chrome/browser/sync/glue/device_info.cc +++ /dev/null @@ -1,253 +0,0 @@ -// Copyright (c) 2012 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/sync/glue/device_info.h" - -#include "base/command_line.h" -#include "base/threading/sequenced_worker_pool.h" -#include "base/values.h" -#include "chrome/common/chrome_version_info.h" -#include "chrome/common/chrome_switches.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 - -// Converts VersionInfo::Channel to string for user-agent string. -std::string ChannelToString(chrome::VersionInfo::Channel channel) { - switch (channel) { - case chrome::VersionInfo::CHANNEL_UNKNOWN: - return "unknown"; - case chrome::VersionInfo::CHANNEL_CANARY: - return "canary"; - case chrome::VersionInfo::CHANNEL_DEV: - return "dev"; - case chrome::VersionInfo::CHANNEL_BETA: - return "beta"; - case chrome::VersionInfo::CHANNEL_STABLE: - return "stable"; - default: - NOTREACHED(); - return "unknown"; - } -} - -} // namespace - -DeviceInfo::DeviceInfo(const std::string& guid, - const std::string& client_name, - const std::string& chrome_version, - const std::string& sync_user_agent, - const sync_pb::SyncEnums::DeviceType device_type, - const std::string& signin_scoped_device_id) - : guid_(guid), - client_name_(client_name), - chrome_version_(chrome_version), - sync_user_agent_(sync_user_agent), - device_type_(device_type), - signin_scoped_device_id_(signin_scoped_device_id) { -} - -DeviceInfo::~DeviceInfo() { } - -const std::string& DeviceInfo::guid() const { - return guid_; -} - -const std::string& DeviceInfo::client_name() const { - return client_name_; -} - -const std::string& DeviceInfo::chrome_version() const { - return chrome_version_; -} - -const std::string& DeviceInfo::sync_user_agent() const { - return sync_user_agent_; -} - -const std::string& DeviceInfo::public_id() const { - return public_id_; -} - -sync_pb::SyncEnums::DeviceType DeviceInfo::device_type() const { - return device_type_; -} - -const std::string& DeviceInfo::signin_scoped_device_id() const { - return signin_scoped_device_id_; -} - -std::string DeviceInfo::GetOSString() const { - switch (device_type_) { - case sync_pb::SyncEnums_DeviceType_TYPE_WIN: - return "win"; - case sync_pb::SyncEnums_DeviceType_TYPE_MAC: - return "mac"; - case sync_pb::SyncEnums_DeviceType_TYPE_LINUX: - return "linux"; - case sync_pb::SyncEnums_DeviceType_TYPE_CROS: - return "chrome_os"; - case sync_pb::SyncEnums_DeviceType_TYPE_PHONE: - case sync_pb::SyncEnums_DeviceType_TYPE_TABLET: - // TODO(lipalani): crbug.com/170375. Add support for ios - // phones and tablets. - return "android"; - default: - return "unknown"; - } -} - -std::string DeviceInfo::GetDeviceTypeString() const { - switch (device_type_) { - case sync_pb::SyncEnums_DeviceType_TYPE_WIN: - case sync_pb::SyncEnums_DeviceType_TYPE_MAC: - case sync_pb::SyncEnums_DeviceType_TYPE_LINUX: - case sync_pb::SyncEnums_DeviceType_TYPE_CROS: - return "desktop_or_laptop"; - case sync_pb::SyncEnums_DeviceType_TYPE_PHONE: - return "phone"; - case sync_pb::SyncEnums_DeviceType_TYPE_TABLET: - return "tablet"; - default: - return "unknown"; - } -} - -bool DeviceInfo::Equals(const DeviceInfo& other) const { - return this->guid() == other.guid() && - this->client_name() == other.client_name() && - this->chrome_version() == other.chrome_version() && - this->sync_user_agent() == other.sync_user_agent() && - this->device_type() == other.device_type() && - this->signin_scoped_device_id() == other.signin_scoped_device_id(); -} - -// static. -sync_pb::SyncEnums::DeviceType DeviceInfo::GetLocalDeviceType() { -#if defined(OS_CHROMEOS) - return sync_pb::SyncEnums_DeviceType_TYPE_CROS; -#elif defined(OS_LINUX) - return sync_pb::SyncEnums_DeviceType_TYPE_LINUX; -#elif defined(OS_MACOSX) - return sync_pb::SyncEnums_DeviceType_TYPE_MAC; -#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; -#else - return sync_pb::SyncEnums_DeviceType_TYPE_OTHER; -#endif -} - -// static -std::string DeviceInfo::MakeUserAgentForSyncApi( - const chrome::VersionInfo& version_info) { - std::string user_agent; - user_agent = "Chrome "; -#if defined(OS_WIN) - user_agent += "WIN "; -#elif defined(OS_CHROMEOS) - user_agent += "CROS "; -#elif defined(OS_ANDROID) - if (IsTabletUI()) - user_agent += "ANDROID-TABLET "; - else - user_agent += "ANDROID-PHONE "; -#elif defined(OS_LINUX) - user_agent += "LINUX "; -#elif defined(OS_FREEBSD) - user_agent += "FREEBSD "; -#elif defined(OS_OPENBSD) - user_agent += "OPENBSD "; -#elif defined(OS_MACOSX) - user_agent += "MAC "; -#endif - if (!version_info.is_valid()) { - DLOG(ERROR) << "Unable to create chrome::VersionInfo object"; - return user_agent; - } - - user_agent += version_info.Version(); - user_agent += " (" + version_info.LastChange() + ")"; - if (!version_info.IsOfficialBuild()) { - user_agent += "-devel"; - } else { - user_agent += " channel(" + - ChannelToString(version_info.GetChannel()) + ")"; - } - - return user_agent; -} - -base::DictionaryValue* DeviceInfo::ToValue() { - base::DictionaryValue* value = new base::DictionaryValue(); - value->SetString("name", client_name_); - value->SetString("id", public_id_); - value->SetString("os", GetOSString()); - value->SetString("type", GetDeviceTypeString()); - value->SetString("chromeVersion", chrome_version_); - return value; -} - -void DeviceInfo::set_public_id(std::string id) { - public_id_ = id; -} - -// static. -void DeviceInfo::CreateLocalDeviceInfo( - const std::string& guid, - const std::string& signin_scoped_device_id, - base::Callback<void(const DeviceInfo& local_info)> callback) { - GetClientName(base::Bind(&DeviceInfo::CreateLocalDeviceInfoContinuation, - guid, - signin_scoped_device_id, - callback)); -} - -// static. -void DeviceInfo::GetClientName( - base::Callback<void(const std::string& client_name)> callback) { - syncer::GetSessionName( - content::BrowserThread::GetBlockingPool(), - base::Bind(&DeviceInfo::GetClientNameContinuation, - callback)); -} - -void DeviceInfo::GetClientNameContinuation( - base::Callback<void(const std::string& local_info)> callback, - const std::string& session_name) { - callback.Run(session_name); -} - -// static. -void DeviceInfo::CreateLocalDeviceInfoContinuation( - const std::string& guid, - const std::string& signin_scoped_device_id, - base::Callback<void(const DeviceInfo& local_info)> callback, - const std::string& session_name) { - chrome::VersionInfo version_info; - - DeviceInfo local_info(guid, - session_name, - version_info.CreateVersionString(), - MakeUserAgentForSyncApi(version_info), - GetLocalDeviceType(), - signin_scoped_device_id); - - callback.Run(local_info); -} - -} // namespace browser_sync diff --git a/chrome/browser/sync/glue/device_info.h b/chrome/browser/sync/glue/device_info.h deleted file mode 100644 index a46e650879..0000000000 --- a/chrome/browser/sync/glue/device_info.h +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (c) 2012 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_SYNC_GLUE_DEVICE_INFO_H_ -#define CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_ - -#include <string> - -#include "base/basictypes.h" -#include "base/bind.h" -#include "sync/protocol/sync.pb.h" - -namespace base { -class DictionaryValue; -} - -namespace chrome { -class VersionInfo; -} - -namespace browser_sync { - -// A class that holds information regarding the properties of a device. -class DeviceInfo { - public: - DeviceInfo(const std::string& guid, - const std::string& client_name, - const std::string& chrome_version, - const std::string& sync_user_agent, - const sync_pb::SyncEnums::DeviceType device_type, - const std::string& signin_scoped_device_id); - ~DeviceInfo(); - - // Sync specific unique identifier for the device. Note if a device - // is wiped and sync is set up again this id WILL be different. - // The same device might have more than 1 guid if the device has multiple - // accounts syncing. - const std::string& guid() const; - - // The host name for the client. - const std::string& client_name() const; - - // Chrome version string. - const std::string& chrome_version() const; - - // The user agent is the combination of OS type, chrome version and which - // channel of chrome(stable or beta). For more information see - // |DeviceInfo::MakeUserAgentForSyncApi|. - const std::string& sync_user_agent() const; - - // Third party visible id for the device. See |public_id_| for more details. - const std::string& public_id() const; - - // Device Type. - sync_pb::SyncEnums::DeviceType device_type() const; - - // Device_id that is stable until user signs out. This device_id is used for - // annotating login scoped refresh token. - const std::string& signin_scoped_device_id() const; - - // Gets the OS in string form. - std::string GetOSString() const; - - // Gets the device type in string form. - std::string GetDeviceTypeString() const; - - // Compares this object's fields with another's. - bool Equals(const DeviceInfo& other) const; - - // Apps can set ids for a device that is meaningful to them but - // not unique enough so the user can be tracked. Exposing |guid| - // would lead to a stable unique id for a device which can potentially - // be used for tracking. - void set_public_id(std::string id); - - // Converts the |DeviceInfo| values to a JS friendly DictionaryValue, - // which extension APIs can expose to third party apps. - base::DictionaryValue* ToValue(); - - static sync_pb::SyncEnums::DeviceType GetLocalDeviceType(); - - // Creates a |DeviceInfo| object representing the local device and passes - // it as parameter to the callback. - static void CreateLocalDeviceInfo( - const std::string& guid, - const std::string& signin_scoped_device_id, - base::Callback<void(const DeviceInfo& local_info)> callback); - - // Gets the local device name and passes it as a parameter to callback. - static void GetClientName( - base::Callback<void(const std::string& local_info)> callback); - - // Helper to construct a user agent string (ASCII) suitable for use by - // the syncapi for any HTTP communication. This string is used by the sync - // backend for classifying client types when calculating statistics. - static std::string MakeUserAgentForSyncApi( - const chrome::VersionInfo& version_info); - - private: - static void GetClientNameContinuation( - base::Callback<void(const std::string& local_info)> callback, - const std::string& session_name); - - static void CreateLocalDeviceInfoContinuation( - const std::string& guid, - const std::string& signin_scoped_device_id, - base::Callback<void(const DeviceInfo& local_info)> callback, - const std::string& session_name); - - const std::string guid_; - - const std::string client_name_; - - const std::string chrome_version_; - - const std::string sync_user_agent_; - - const sync_pb::SyncEnums::DeviceType device_type_; - - std::string signin_scoped_device_id_; - - // Exposing |guid| would lead to a stable unique id for a device which - // can potentially be used for tracking. Public ids are privacy safe - // ids in that the same device will have different id for different apps - // and they are also reset when app/extension is uninstalled. - std::string public_id_; - - DISALLOW_COPY_AND_ASSIGN(DeviceInfo); -}; - -} // namespace browser_sync - -#endif // CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_ diff --git a/chrome/browser/sync/glue/device_info_data_type_controller.cc b/chrome/browser/sync/glue/device_info_data_type_controller.cc deleted file mode 100644 index 81d0fa82f3..0000000000 --- a/chrome/browser/sync/glue/device_info_data_type_controller.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2014 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/sync/glue/device_info_data_type_controller.h" - -#include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" -#include "chrome/browser/sync/glue/local_device_info_provider.h" -#include "content/public/browser/browser_thread.h" - -using content::BrowserThread; - -namespace browser_sync { - -DeviceInfoDataTypeController::DeviceInfoDataTypeController( - sync_driver::SyncApiComponentFactory* sync_factory, - LocalDeviceInfoProvider* local_device_info_provider) - : UIDataTypeController( - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), - base::Bind(&ChromeReportUnrecoverableError), - syncer::DEVICE_INFO, - sync_factory), - local_device_info_provider_(local_device_info_provider) { -} - -DeviceInfoDataTypeController::~DeviceInfoDataTypeController() { -} - -bool DeviceInfoDataTypeController::StartModels() { - // Start the data type as soon as the local device info gets available. - if (local_device_info_provider_->GetLocalDeviceInfo()) { - return true; - } - - subscription_ = local_device_info_provider_->RegisterOnInitializedCallback( - base::Bind(&DeviceInfoDataTypeController::OnLocalDeviceInfoLoaded, this)); - - return false; -} - -void DeviceInfoDataTypeController::OnLocalDeviceInfoLoaded() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK_EQ(state_, MODEL_STARTING); - DCHECK(local_device_info_provider_->GetLocalDeviceInfo()); - - subscription_.reset(); - OnModelLoaded(); -} - -} // namespace browser_sync diff --git a/chrome/browser/sync/glue/device_info_data_type_controller.h b/chrome/browser/sync/glue/device_info_data_type_controller.h deleted file mode 100644 index 38c7b45f33..0000000000 --- a/chrome/browser/sync/glue/device_info_data_type_controller.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2014 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_SYNC_GLUE_DEVICE_INFO_DATA_TYPE_CONTROLLER_H_ -#define CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_DATA_TYPE_CONTROLLER_H_ - -#include "base/memory/scoped_ptr.h" -#include "chrome/browser/sync/glue/local_device_info_provider.h" -#include "components/sync_driver/ui_data_type_controller.h" - -namespace browser_sync { - -// DataTypeController for DEVICE_INFO model type. -class DeviceInfoDataTypeController : public sync_driver::UIDataTypeController { - public: - DeviceInfoDataTypeController( - sync_driver::SyncApiComponentFactory* sync_factory, - LocalDeviceInfoProvider* local_device_info_provider); - - private: - virtual ~DeviceInfoDataTypeController(); - - // UIDataTypeController implementations. - virtual bool StartModels() OVERRIDE; - - // Called by LocalDeviceInfoProvider when the local device into becomes - // available. - void OnLocalDeviceInfoLoaded(); - - LocalDeviceInfoProvider* const local_device_info_provider_; - scoped_ptr<LocalDeviceInfoProvider::Subscription> subscription_; - DISALLOW_COPY_AND_ASSIGN(DeviceInfoDataTypeController); -}; - -} // namespace browser_sync - -#endif // CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_DATA_TYPE_CONTROLLER_H_ diff --git a/chrome/browser/sync/glue/device_info_data_type_controller_unittest.cc b/chrome/browser/sync/glue/device_info_data_type_controller_unittest.cc index 0f0a2b9885..4b76c3d6ec 100644 --- a/chrome/browser/sync/glue/device_info_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/device_info_data_type_controller_unittest.cc @@ -6,13 +6,14 @@ #include "base/callback.h" #include "base/memory/weak_ptr.h" #include "base/run_loop.h" -#include "chrome/browser/sync/glue/device_info_data_type_controller.h" #include "chrome/browser/sync/glue/local_device_info_provider_mock.h" #include "chrome/browser/sync/profile_sync_components_factory_mock.h" +#include "components/sync_driver/device_info_data_type_controller.h" #include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" using sync_driver::DataTypeController; +using sync_driver::DeviceInfoDataTypeController; namespace browser_sync { @@ -37,6 +38,8 @@ class DeviceInfoDataTypeControllerTest : public testing::Test { "device_id")); controller_ = new DeviceInfoDataTypeController( + base::MessageLoopProxy::current(), + base::Closure(), &profile_sync_factory_, local_device_.get()); diff --git a/chrome/browser/sync/glue/device_info_sync_service.cc b/chrome/browser/sync/glue/device_info_sync_service.cc deleted file mode 100644 index 17fd8edf73..0000000000 --- a/chrome/browser/sync/glue/device_info_sync_service.cc +++ /dev/null @@ -1,260 +0,0 @@ -// Copyright 2014 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/sync/glue/device_info_sync_service.h" - -#include "base/strings/stringprintf.h" -#include "chrome/browser/sync/glue/local_device_info_provider.h" -#include "sync/api/sync_change.h" -#include "sync/protocol/sync.pb.h" - -namespace browser_sync { - -using syncer::ModelType; -using syncer::SyncChange; -using syncer::SyncChangeList; -using syncer::SyncChangeProcessor; -using syncer::SyncData; -using syncer::SyncDataList; -using syncer::SyncErrorFactory; -using syncer::SyncMergeResult; - -DeviceInfoSyncService::DeviceInfoSyncService( - LocalDeviceInfoProvider* local_device_info_provider) - : local_device_info_provider_(local_device_info_provider) { - DCHECK(local_device_info_provider); -} - -DeviceInfoSyncService::~DeviceInfoSyncService() { -} - -SyncMergeResult DeviceInfoSyncService::MergeDataAndStartSyncing( - ModelType type, - const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor, - scoped_ptr<SyncErrorFactory> error_handler) { - DCHECK(sync_processor.get()); - DCHECK(error_handler.get()); - DCHECK_EQ(type, syncer::DEVICE_INFO); - - DCHECK(all_data_.empty()); - - sync_processor_ = sync_processor.Pass(); - error_handler_ = error_handler.Pass(); - - // Iterate over all initial sync data and copy it to the cache. - for (SyncDataList::const_iterator iter = initial_sync_data.begin(); - iter != initial_sync_data.end(); - ++iter) { - DCHECK_EQ(syncer::DEVICE_INFO, iter->GetDataType()); - StoreSyncData(iter->GetSpecifics().device_info().cache_guid(), *iter); - } - - size_t num_items_new = initial_sync_data.size(); - size_t num_items_updated = 0; - // Indicates whether a local device has been added or updated. - SyncChange::SyncChangeType change_type = SyncChange::ACTION_INVALID; - - // Initialization should be completed before this type is enabled - // and local device info must be available. - const DeviceInfo* local_device_info = - local_device_info_provider_->GetLocalDeviceInfo(); - DCHECK(local_device_info != NULL); - // Before storing the local device info check if the data with - // the same guid has already been synced. This attempts to retrieve - // DeviceInfo from the cached data initialized above. - scoped_ptr<DeviceInfo> synced_local_device_info = - GetDeviceInfo(local_device_info->guid()); - - if (synced_local_device_info.get()) { - // Local device info has been synced and exists in the cache. - // |num_items_new| and |num_items_updated| need to be updated to - // reflect that. - num_items_new--; - // Overwrite the synced device info with the local data only if - // it is different. - if (!synced_local_device_info->Equals(*local_device_info)) { - num_items_updated++; - change_type = SyncChange::ACTION_UPDATE; - } - } else { - // Local device info doesn't yet exist in the cache and - // will be added further below. - // |num_items_new| and |num_items_updated| are already correct. - change_type = SyncChange::ACTION_ADD; - } - - syncer::SyncMergeResult result(type); - - // Update SyncData from device info if it is new or different than - // the synced one, and also add it to the |change_list|. - if (change_type != SyncChange::ACTION_INVALID) { - SyncData local_data = CreateLocalData(local_device_info); - StoreSyncData(local_device_info->guid(), local_data); - - SyncChangeList change_list; - change_list.push_back(SyncChange(FROM_HERE, change_type, local_data)); - result.set_error( - sync_processor_->ProcessSyncChanges(FROM_HERE, change_list)); - } - - result.set_num_items_before_association(1); - result.set_num_items_after_association(all_data_.size()); - result.set_num_items_added(num_items_new); - result.set_num_items_modified(num_items_updated); - result.set_num_items_deleted(0); - - NotifyObservers(); - - return result; -} - -void DeviceInfoSyncService::StopSyncing(syncer::ModelType type) { - all_data_.clear(); - sync_processor_.reset(); - error_handler_.reset(); -} - -SyncDataList DeviceInfoSyncService::GetAllSyncData( - syncer::ModelType type) const { - SyncDataList list; - - for (SyncDataMap::const_iterator iter = all_data_.begin(); - iter != all_data_.end(); - ++iter) { - list.push_back(iter->second); - } - - return list; -} - -syncer::SyncError DeviceInfoSyncService::ProcessSyncChanges( - const tracked_objects::Location& from_here, - const SyncChangeList& change_list) { - syncer::SyncError error; - - DCHECK(local_device_info_provider_->GetLocalDeviceInfo()); - const std::string& local_device_id = - local_device_info_provider_->GetLocalDeviceInfo()->guid(); - - bool has_changes = false; - - // Iterate over all chanages and merge entries. - for (SyncChangeList::const_iterator iter = change_list.begin(); - iter != change_list.end(); - ++iter) { - const SyncData& sync_data = iter->sync_data(); - DCHECK_EQ(syncer::DEVICE_INFO, sync_data.GetDataType()); - - const std::string& client_id = - sync_data.GetSpecifics().device_info().cache_guid(); - // Ignore device info matching the local device. - if (local_device_id == client_id) { - DVLOG(1) << "Ignoring sync changes for the local DEVICE_INFO"; - continue; - } - - if (iter->change_type() == syncer::SyncChange::ACTION_DELETE) { - has_changes = true; - DeleteSyncData(client_id); - } else if (iter->change_type() == syncer::SyncChange::ACTION_UPDATE || - iter->change_type() == syncer::SyncChange::ACTION_ADD) { - has_changes = true; - StoreSyncData(client_id, sync_data); - } else { - error.Reset(FROM_HERE, "Invalid action received.", syncer::DEVICE_INFO); - } - } - - if (has_changes) { - NotifyObservers(); - } - - return error; -} - -scoped_ptr<DeviceInfo> DeviceInfoSyncService::GetDeviceInfo( - const std::string& client_id) const { - SyncDataMap::const_iterator iter = all_data_.find(client_id); - if (iter == all_data_.end()) { - return scoped_ptr<DeviceInfo>(); - } - - return make_scoped_ptr(CreateDeviceInfo(iter->second)); -} - -ScopedVector<DeviceInfo> DeviceInfoSyncService::GetAllDeviceInfo() const { - ScopedVector<DeviceInfo> list; - - for (SyncDataMap::const_iterator iter = all_data_.begin(); - iter != all_data_.end(); - ++iter) { - list.push_back(CreateDeviceInfo(iter->second)); - } - - return list.Pass(); -} - -void DeviceInfoSyncService::AddObserver(Observer* observer) { - observers_.AddObserver(observer); -} - -void DeviceInfoSyncService::RemoveObserver(Observer* observer) { - observers_.RemoveObserver(observer); -} - -void DeviceInfoSyncService::NotifyObservers() { - FOR_EACH_OBSERVER(Observer, observers_, OnDeviceInfoChange()); -} - -SyncData DeviceInfoSyncService::CreateLocalData(const DeviceInfo* info) { - sync_pb::EntitySpecifics entity; - sync_pb::DeviceInfoSpecifics& specifics = *entity.mutable_device_info(); - - specifics.set_cache_guid(info->guid()); - specifics.set_client_name(info->client_name()); - specifics.set_chrome_version(info->chrome_version()); - specifics.set_sync_user_agent(info->sync_user_agent()); - specifics.set_device_type(info->device_type()); - specifics.set_signin_scoped_device_id(info->signin_scoped_device_id()); - - std::string local_device_tag = - base::StringPrintf("DeviceInfo_%s", info->guid().c_str()); - - return SyncData::CreateLocalData( - local_device_tag, info->client_name(), entity); -} - -DeviceInfo* DeviceInfoSyncService::CreateDeviceInfo( - const syncer::SyncData sync_data) { - const sync_pb::DeviceInfoSpecifics& specifics = - sync_data.GetSpecifics().device_info(); - - return new DeviceInfo(specifics.cache_guid(), - specifics.client_name(), - specifics.chrome_version(), - specifics.sync_user_agent(), - specifics.device_type(), - specifics.signin_scoped_device_id()); -} - -void DeviceInfoSyncService::StoreSyncData(const std::string& client_id, - const SyncData& sync_data) { - DVLOG(1) << "Storing DEVICE_INFO for " - << sync_data.GetSpecifics().device_info().client_name() - << " with ID " << client_id; - all_data_[client_id] = sync_data; -} - -void DeviceInfoSyncService::DeleteSyncData(const std::string& client_id) { - SyncDataMap::iterator iter = all_data_.find(client_id); - if (iter != all_data_.end()) { - DVLOG(1) << "Deleting DEVICE_INFO for " - << iter->second.GetSpecifics().device_info().client_name() - << " with ID " << client_id; - all_data_.erase(iter); - } -} - -} // namespace browser_sync diff --git a/chrome/browser/sync/glue/device_info_sync_service.h b/chrome/browser/sync/glue/device_info_sync_service.h deleted file mode 100644 index 3313fc4273..0000000000 --- a/chrome/browser/sync/glue/device_info_sync_service.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2014 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_SYNC_GLUE_DEVICE_INFO_SYNC_SERVICE_H_ -#define CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_SYNC_SERVICE_H_ - -#include "base/observer_list.h" -#include "chrome/browser/sync/glue/device_info_tracker.h" -#include "sync/api/sync_change_processor.h" -#include "sync/api/sync_data.h" -#include "sync/api/sync_error_factory.h" -#include "sync/api/syncable_service.h" - -namespace browser_sync { - -class LocalDeviceInfoProvider; - -// SyncableService implementation for DEVICE_INFO model type. -class DeviceInfoSyncService : public syncer::SyncableService, - public DeviceInfoTracker { - public: - explicit DeviceInfoSyncService( - LocalDeviceInfoProvider* local_device_info_provider); - virtual ~DeviceInfoSyncService(); - - // syncer::SyncableService implementation. - virtual syncer::SyncMergeResult MergeDataAndStartSyncing( - syncer::ModelType type, - const syncer::SyncDataList& initial_sync_data, - scoped_ptr<syncer::SyncChangeProcessor> sync_processor, - scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; - virtual void StopSyncing(syncer::ModelType type) OVERRIDE; - virtual syncer::SyncDataList GetAllSyncData( - syncer::ModelType type) const OVERRIDE; - virtual syncer::SyncError ProcessSyncChanges( - const tracked_objects::Location& from_here, - const syncer::SyncChangeList& change_list) OVERRIDE; - - // DeviceInfoTracker implementation. - virtual scoped_ptr<DeviceInfo> GetDeviceInfo( - const std::string& client_id) const OVERRIDE; - virtual ScopedVector<DeviceInfo> GetAllDeviceInfo() const OVERRIDE; - virtual void AddObserver(Observer* observer) OVERRIDE; - virtual void RemoveObserver(Observer* observer) OVERRIDE; - - private: - // Create SyncData from local DeviceInfo. - static syncer::SyncData CreateLocalData(const DeviceInfo* info); - // Allocate new DeviceInfo from SyncData. - static DeviceInfo* CreateDeviceInfo(const syncer::SyncData sync_data); - // Store SyncData in the cache. - void StoreSyncData(const std::string& client_id, - const syncer::SyncData& sync_data); - // Delete SyncData from the cache. - void DeleteSyncData(const std::string& client_id); - // Notify all registered observers. - void NotifyObservers(); - - // |local_device_info_provider_| isn't owned. - const LocalDeviceInfoProvider* const local_device_info_provider_; - - // Receives ownership of |sync_processor_| and |error_handler_| in - // MergeDataAndStartSyncing() and destroy them in StopSyncing(). - scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; - scoped_ptr<syncer::SyncErrorFactory> error_handler_; - - // Cache of all syncable and local data. - typedef std::map<std::string, syncer::SyncData> SyncDataMap; - SyncDataMap all_data_; - - // Registered observers, not owned. - ObserverList<Observer, true> observers_; - - DISALLOW_COPY_AND_ASSIGN(DeviceInfoSyncService); -}; - -} // namespace browser_sync - -#endif // CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_SYNC_SERVICE_H_ diff --git a/chrome/browser/sync/glue/device_info_sync_service_unittest.cc b/chrome/browser/sync/glue/device_info_sync_service_unittest.cc index 6fe3a8ee61..5d66a81824 100644 --- a/chrome/browser/sync/glue/device_info_sync_service_unittest.cc +++ b/chrome/browser/sync/glue/device_info_sync_service_unittest.cc @@ -3,16 +3,19 @@ // found in the LICENSE file. #include "base/message_loop/message_loop.h" -#include "chrome/browser/sync/glue/device_info_sync_service.h" #include "chrome/browser/sync/glue/local_device_info_provider_mock.h" +#include "components/sync_driver/device_info_sync_service.h" #include "content/public/test/test_browser_thread_bundle.h" #include "sync/api/sync_change.h" #include "sync/api/sync_change_processor.h" #include "sync/api/sync_change_processor_wrapper_for_test.h" #include "sync/api/sync_error_factory_mock.h" #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test.h" +#include "sync/util/time.h" #include "testing/gtest/include/gtest/gtest.h" +using sync_driver::DeviceInfoSyncService; +using sync_driver::DeviceInfoTracker; using syncer::AttachmentIdList; using syncer::AttachmentServiceProxyForTest; using syncer::ModelType; @@ -112,7 +115,8 @@ class DeviceInfoSyncServiceTest : public testing::Test, } SyncData CreateRemoteData(const std::string& client_id, - const std::string& client_name) { + const std::string& client_name, + int64 backup_timestamp = 0) { sync_pb::EntitySpecifics entity; sync_pb::DeviceInfoSpecifics& specifics = *entity.mutable_device_info(); @@ -123,6 +127,10 @@ class DeviceInfoSyncServiceTest : public testing::Test, specifics.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_LINUX); specifics.set_signin_scoped_device_id("device_id"); + if (backup_timestamp != 0) { + specifics.set_backup_timestamp(backup_timestamp); + } + return SyncData::CreateRemoteData(1, entity, base::Time(), @@ -400,6 +408,152 @@ TEST_F(DeviceInfoSyncServiceTest, ProcessChangesAfterUnsubscribing) { EXPECT_EQ(0, num_device_info_changed_callbacks_); } +// Verifies setting backup timestamp after the initial sync. +TEST_F(DeviceInfoSyncServiceTest, UpdateLocalDeviceBackupTime) { + // Shouldn't have backuptime initially. + base::Time backup_time = sync_service_->GetLocalDeviceBackupTime(); + EXPECT_TRUE(backup_time.is_null()); + + // Perform the initial sync with empty data. + SyncMergeResult merge_result = + sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, + SyncDataList(), + PassProcessor(), + CreateAndPassSyncErrorFactory()); + + // Should have local device after the initial sync. + EXPECT_EQ(1U, sync_processor_->change_list_size()); + EXPECT_EQ(SyncChange::ACTION_ADD, sync_processor_->change_type_at(0)); + + // Shouldn't have backup time initially. + EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0)); + EXPECT_FALSE(sync_processor_->device_info_at(0).has_backup_timestamp()); + + sync_service_->UpdateLocalDeviceBackupTime(base::Time::FromTimeT(1000)); + + // Should have local device info updated with the specified backup timestamp. + EXPECT_EQ(1U, sync_processor_->change_list_size()); + EXPECT_EQ(SyncChange::ACTION_UPDATE, sync_processor_->change_type_at(0)); + EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0)); + EXPECT_TRUE(sync_processor_->device_info_at(0).has_backup_timestamp()); + + backup_time = syncer::ProtoTimeToTime( + sync_processor_->device_info_at(0).backup_timestamp()); + EXPECT_EQ(1000, backup_time.ToTimeT()); + + // Also verify that we get the same backup time directly from the service. + backup_time = sync_service_->GetLocalDeviceBackupTime(); + EXPECT_EQ(1000, backup_time.ToTimeT()); +} + +// Verifies setting backup timestamp prior to the initial sync. +TEST_F(DeviceInfoSyncServiceTest, UpdateLocalDeviceBackupTimeBeforeSync) { + // Set the backup timestamp. + sync_service_->UpdateLocalDeviceBackupTime(base::Time::FromTimeT(2000)); + // Verify that we get it back. + base::Time backup_time = sync_service_->GetLocalDeviceBackupTime(); + EXPECT_EQ(2000, backup_time.ToTimeT()); + + // Now perform the initial sync with empty data. + SyncMergeResult merge_result = + sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, + SyncDataList(), + PassProcessor(), + CreateAndPassSyncErrorFactory()); + + // Should have local device after the initial sync. + // Should have the backup timestamp set. + EXPECT_EQ(1U, sync_processor_->change_list_size()); + EXPECT_EQ(SyncChange::ACTION_ADD, sync_processor_->change_type_at(0)); + EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0)); + EXPECT_TRUE(sync_processor_->device_info_at(0).has_backup_timestamp()); + + backup_time = syncer::ProtoTimeToTime( + sync_processor_->device_info_at(0).backup_timestamp()); + EXPECT_EQ(2000, backup_time.ToTimeT()); +} + +// Verifies that the backup timestamp that comes in the intial sync data +// gets preserved when there are no changes to the local device. +TEST_F(DeviceInfoSyncServiceTest, PreserveBackupTimeWithMatchingLocalDevice) { + base::Time backup_time = base::Time::FromTimeT(3000); + SyncDataList sync_data; + sync_data.push_back(CreateRemoteData( + "guid_1", "client_1", syncer::TimeToProtoTime(backup_time))); + + SyncMergeResult merge_result = + sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, + sync_data, + PassProcessor(), + CreateAndPassSyncErrorFactory()); + + // Everything is matching so there should be no updates. + EXPECT_EQ(0U, sync_processor_->change_list_size()); + + // Verify that we get back the same time. + backup_time = sync_service_->GetLocalDeviceBackupTime(); + EXPECT_EQ(3000, backup_time.ToTimeT()); +} + +// Verifies that the backup timestamp that comes in the intial sync data +// gets merged with the local device data. +TEST_F(DeviceInfoSyncServiceTest, MergeBackupTimeWithMatchingLocalDevice) { + base::Time backup_time = base::Time::FromTimeT(4000); + SyncDataList sync_data; + sync_data.push_back(CreateRemoteData( + "guid_1", "foo_1", syncer::TimeToProtoTime(backup_time))); + + SyncMergeResult merge_result = + sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, + sync_data, + PassProcessor(), + CreateAndPassSyncErrorFactory()); + + // Should be one change because of the client name mismatch. + // However the backup time passed in the initial data should be merged into + // the change. + EXPECT_EQ(1U, sync_processor_->change_list_size()); + + EXPECT_EQ(SyncChange::ACTION_UPDATE, sync_processor_->change_type_at(0)); + EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0)); + EXPECT_EQ("client_1", sync_processor_->client_name_at(0)); + + backup_time = syncer::ProtoTimeToTime( + sync_processor_->device_info_at(0).backup_timestamp()); + EXPECT_EQ(4000, backup_time.ToTimeT()); +} + +// Verifies that mismatching backup timestamp generates an update even +// when the rest of local device data is matching. +TEST_F(DeviceInfoSyncServiceTest, + MergeMismatchingBackupTimeWithMatchingLocalDevice) { + base::Time backup_time = base::Time::FromTimeT(5000); + SyncDataList sync_data; + sync_data.push_back(CreateRemoteData( + "guid_1", "client_1", syncer::TimeToProtoTime(backup_time))); + + // Set the backup timestamp different than the one in the sync data. + sync_service_->UpdateLocalDeviceBackupTime(base::Time::FromTimeT(6000)); + + SyncMergeResult merge_result = + sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, + sync_data, + PassProcessor(), + CreateAndPassSyncErrorFactory()); + + // Should generate and update due to timestamp mismatch. + // The locally set timestamp wins. + EXPECT_EQ(1U, sync_processor_->change_list_size()); + + EXPECT_EQ(SyncChange::ACTION_UPDATE, sync_processor_->change_type_at(0)); + EXPECT_EQ("guid_1", sync_processor_->cache_guid_at(0)); + EXPECT_EQ("client_1", sync_processor_->client_name_at(0)); + + backup_time = syncer::ProtoTimeToTime( + sync_processor_->device_info_at(0).backup_timestamp()); + EXPECT_EQ(6000, backup_time.ToTimeT()); +} + } // namespace } // namespace browser_sync diff --git a/chrome/browser/sync/glue/device_info_tracker.h b/chrome/browser/sync/glue/device_info_tracker.h deleted file mode 100644 index 8244401b7e..0000000000 --- a/chrome/browser/sync/glue/device_info_tracker.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2014 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_SYNC_GLUE_DEVICE_INFO_TRACKER_H_ -#define CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_TRACKER_H_ - -#include "base/memory/scoped_ptr.h" -#include "base/memory/scoped_vector.h" -#include "chrome/browser/sync/glue/device_info.h" - -namespace browser_sync { - -// Interface for tracking synced DeviceInfo. -class DeviceInfoTracker { - public: - virtual ~DeviceInfoTracker() {} - - // Observer class for listening to device info changes. - class Observer { - public: - virtual void OnDeviceInfoChange() = 0; - }; - - // Gets DeviceInfo the synced device with specified client ID. - // Returns an empty scoped_ptr if device with the given |client_id| hasn't - // been synced. - virtual scoped_ptr<DeviceInfo> GetDeviceInfo( - const std::string& client_id) const = 0; - // Gets DeviceInfo for all synced devices (including the local one). - virtual ScopedVector<DeviceInfo> GetAllDeviceInfo() const = 0; - // Registers an observer to be called on syncing any updated DeviceInfo. - virtual void AddObserver(Observer* observer) = 0; - // Unregisters an observer. - virtual void RemoveObserver(Observer* observer) = 0; -}; - -} // namespace browser_sync - -#endif // CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_TRACKER_H_ diff --git a/chrome/browser/sync/glue/favicon_cache.cc b/chrome/browser/sync/glue/favicon_cache.cc index ecd7e1d338..f591fe4fa2 100644 --- a/chrome/browser/sync/glue/favicon_cache.cc +++ b/chrome/browser/sync/glue/favicon_cache.cc @@ -10,7 +10,7 @@ #include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/favicon/favicon_service_factory.h" #include "chrome/browser/history/history_notifications.h" -#include "chrome/browser/history/history_types.h" +#include "components/history/core/browser/history_types.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" #include "sync/api/time.h" diff --git a/chrome/browser/sync/glue/favicon_cache.h b/chrome/browser/sync/glue/favicon_cache.h index d3bd71ca61..c2597f536a 100644 --- a/chrome/browser/sync/glue/favicon_cache.h +++ b/chrome/browser/sync/glue/favicon_cache.h @@ -16,7 +16,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/task/cancelable_task_tracker.h" -#include "chrome/browser/history/history_types.h" +#include "components/history/core/browser/history_types.h" #include "components/sessions/session_id.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" diff --git a/chrome/browser/sync/glue/frontend_data_type_controller.cc b/chrome/browser/sync/glue/frontend_data_type_controller.cc index 03c592d847..d822897a26 100644 --- a/chrome/browser/sync/glue/frontend_data_type_controller.cc +++ b/chrome/browser/sync/glue/frontend_data_type_controller.cc @@ -44,7 +44,7 @@ FrontendDataTypeController::FrontendDataTypeController( void FrontendDataTypeController::LoadModels( const ModelLoadCallback& model_load_callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(!model_load_callback.is_null()); + model_load_callback_ = model_load_callback; if (state_ != NOT_RUNNING) { model_load_callback.Run(type(), @@ -55,9 +55,6 @@ void FrontendDataTypeController::LoadModels( return; } - DCHECK(model_load_callback_.is_null()); - - model_load_callback_ = model_load_callback; state_ = MODEL_STARTING; if (!StartModels()) { // If we are waiting for some external service to load before associating @@ -72,13 +69,10 @@ void FrontendDataTypeController::LoadModels( void FrontendDataTypeController::OnModelLoaded() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(!model_load_callback_.is_null()); DCHECK_EQ(state_, MODEL_STARTING); state_ = MODEL_LOADED; - ModelLoadCallback model_load_callback = model_load_callback_; - model_load_callback_.Reset(); - model_load_callback.Run(type(), syncer::SyncError()); + model_load_callback_.Run(type(), syncer::SyncError()); } void FrontendDataTypeController::StartAssociating( @@ -150,15 +144,12 @@ void FrontendDataTypeController::OnSingleDataTypeUnrecoverableError( const syncer::SyncError& error) { DCHECK_EQ(type(), error.model_type()); RecordUnrecoverableError(error.location(), error.message()); - if (!start_callback_.is_null()) { + if (!model_load_callback_.is_null()) { syncer::SyncMergeResult local_merge_result(type()); local_merge_result.set_error(error); base::MessageLoop::current()->PostTask( FROM_HERE, - base::Bind(start_callback_, - RUNTIME_ERROR, - local_merge_result, - syncer::SyncMergeResult(type()))); + base::Bind(model_load_callback_, type(), error)); } } @@ -260,13 +251,10 @@ void FrontendDataTypeController::AbortModelLoad() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); CleanUp(); state_ = NOT_RUNNING; - ModelLoadCallback model_load_callback = model_load_callback_; - model_load_callback_.Reset(); - model_load_callback.Run(type(), - syncer::SyncError(FROM_HERE, - syncer::SyncError::DATATYPE_ERROR, - "Aborted", - type())); + model_load_callback_.Run( + type(), + syncer::SyncError( + FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "Aborted", type())); } void FrontendDataTypeController::StartDone( diff --git a/chrome/browser/sync/glue/history_delete_directives_data_type_controller.cc b/chrome/browser/sync/glue/history_delete_directives_data_type_controller.cc new file mode 100644 index 0000000000..2c94c52b97 --- /dev/null +++ b/chrome/browser/sync/glue/history_delete_directives_data_type_controller.cc @@ -0,0 +1,69 @@ +// Copyright 2014 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/sync/glue/history_delete_directives_data_type_controller.h" + +#include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" +#include "chrome/browser/sync/profile_sync_service.h" +#include "content/public/browser/browser_thread.h" + +using content::BrowserThread; + +namespace browser_sync { + +HistoryDeleteDirectivesDataTypeController:: + HistoryDeleteDirectivesDataTypeController( + sync_driver::SyncApiComponentFactory* factory, + ProfileSyncService* sync_service) + : sync_driver::UIDataTypeController( + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), + base::Bind(&ChromeReportUnrecoverableError), + syncer::HISTORY_DELETE_DIRECTIVES, + factory), + sync_service_(sync_service) { +} + +HistoryDeleteDirectivesDataTypeController:: + ~HistoryDeleteDirectivesDataTypeController() { +} + +bool HistoryDeleteDirectivesDataTypeController::ReadyForStart() const { + return !sync_service_->EncryptEverythingEnabled(); +} + +bool HistoryDeleteDirectivesDataTypeController::StartModels() { + if (DisableTypeIfNecessary()) + return false; + sync_service_->AddObserver(this); + return true; +} + +void HistoryDeleteDirectivesDataTypeController::StopModels() { + if (sync_service_->HasObserver(this)) + sync_service_->RemoveObserver(this); +} + +void HistoryDeleteDirectivesDataTypeController::OnStateChanged() { + DisableTypeIfNecessary(); +} + +bool HistoryDeleteDirectivesDataTypeController::DisableTypeIfNecessary() { + if (!sync_service_->ShouldPushChanges()) + return false; + + if (ReadyForStart()) + return false; + + if (sync_service_->HasObserver(this)) + sync_service_->RemoveObserver(this); + syncer::SyncError error( + FROM_HERE, + syncer::SyncError::DATATYPE_POLICY_ERROR, + "Delete directives not supported with encryption.", + type()); + OnSingleDataTypeUnrecoverableError(error); + return true; +} + +} // namespace browser_sync diff --git a/chrome/browser/sync/glue/history_delete_directives_data_type_controller.h b/chrome/browser/sync/glue/history_delete_directives_data_type_controller.h new file mode 100644 index 0000000000..7e2bf460e1 --- /dev/null +++ b/chrome/browser/sync/glue/history_delete_directives_data_type_controller.h @@ -0,0 +1,50 @@ +// Copyright 2014 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_SYNC_GLUE_HISTORY_DELETE_DIRECTIVES_DATA_TYPE_CONTROLLER_H_ +#define CHROME_BROWSER_SYNC_GLUE_HISTORY_DELETE_DIRECTIVES_DATA_TYPE_CONTROLLER_H_ + +#include "chrome/browser/sync/profile_sync_service_observer.h" +#include "components/sync_driver/local_device_info_provider.h" +#include "components/sync_driver/ui_data_type_controller.h" + +class Profile; +class ProfileSyncService; + +namespace browser_sync { + +// A controller for delete directives, which cannot sync when full encryption +// is enabled. +class HistoryDeleteDirectivesDataTypeController + : public sync_driver::UIDataTypeController, + public ProfileSyncServiceObserver { + public: + HistoryDeleteDirectivesDataTypeController( + sync_driver::SyncApiComponentFactory* factory, + ProfileSyncService* sync_service); + + // UIDataTypeController override. + virtual bool ReadyForStart() const OVERRIDE; + virtual bool StartModels() OVERRIDE; + virtual void StopModels() OVERRIDE; + + // ProfileSyncServiceBaseObserver implementation. + virtual void OnStateChanged() OVERRIDE; + + private: + // Refcounted. + virtual ~HistoryDeleteDirectivesDataTypeController(); + + // Triggers a SingleDataTypeUnrecoverable error and returns true if the + // type is no longer ready, else does nothing and returns false. + bool DisableTypeIfNecessary(); + + ProfileSyncService* sync_service_; + + DISALLOW_COPY_AND_ASSIGN(HistoryDeleteDirectivesDataTypeController); +}; + +} // namespace browser_sync + +#endif // CHROME_BROWSER_SYNC_GLUE_HISTORY_DELETE_DIRECTIVES_DATA_TYPE_CONTROLLER_H_ diff --git a/chrome/browser/sync/glue/local_device_info_provider.h b/chrome/browser/sync/glue/local_device_info_provider.h deleted file mode 100644 index 4194c8eb8f..0000000000 --- a/chrome/browser/sync/glue/local_device_info_provider.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2014 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_SYNC_GLUE_LOCAL_DEVICE_INFO_PROVIDER_H_ -#define CHROME_BROWSER_SYNC_GLUE_LOCAL_DEVICE_INFO_PROVIDER_H_ - -#include <string> -#include "base/callback_list.h" - -namespace browser_sync { - -class DeviceInfo; - -// Interface for providing sync specific informaiton about the -// local device. -class LocalDeviceInfoProvider { - public: - typedef base::CallbackList<void(void)>::Subscription Subscription; - - virtual ~LocalDeviceInfoProvider() {} - - // Returns sync's representation of the local device info; - // NULL if the device info is unavailable. - // The returned object is fully owned by LocalDeviceInfoProvider (must not - // be freed by the caller). It remains valid until LocalDeviceInfoProvider - // is destroyed. - virtual const DeviceInfo* GetLocalDeviceInfo() const = 0; - - // Returns a GUID string used for creation of the machine tag for - // this local session; an empty sting if LocalDeviceInfoProvider hasn't been - // initialized yet. - virtual std::string GetLocalSyncCacheGUID() const = 0; - - // Starts initializing local device info. - virtual void Initialize( - const std::string& cache_guid, - const std::string& signin_scoped_device_id) = 0; - - // Registers a callback to be called when local device info becomes available. - // The callback will remain registered until the - // returned Subscription is destroyed, which must occur before the - // CallbackList is destroyed. - virtual scoped_ptr<Subscription> RegisterOnInitializedCallback( - const base::Closure& callback) = 0; -}; - -} // namespace browser_sync - -#endif // CHROME_BROWSER_SYNC_GLUE_LOCAL_DEVICE_INFO_PROVIDER_H_ diff --git a/chrome/browser/sync/glue/local_device_info_provider_impl.cc b/chrome/browser/sync/glue/local_device_info_provider_impl.cc index 711e895ef2..bc8e14a358 100644 --- a/chrome/browser/sync/glue/local_device_info_provider_impl.cc +++ b/chrome/browser/sync/glue/local_device_info_provider_impl.cc @@ -2,10 +2,61 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/bind.h" #include "chrome/browser/sync/glue/local_device_info_provider_impl.h" +#include "chrome/common/chrome_version_info.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 { + +// Converts VersionInfo::Channel to string for user-agent string. +std::string ChannelToString(chrome::VersionInfo::Channel channel) { + switch (channel) { + case chrome::VersionInfo::CHANNEL_UNKNOWN: + return "unknown"; + case chrome::VersionInfo::CHANNEL_CANARY: + return "canary"; + case chrome::VersionInfo::CHANNEL_DEV: + return "dev"; + case chrome::VersionInfo::CHANNEL_BETA: + return "beta"; + case chrome::VersionInfo::CHANNEL_STABLE: + return "stable"; + default: + NOTREACHED(); + return "unknown"; + } +} + +#if defined(OS_ANDROID) +bool IsTabletUI() { + return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET; +} +#endif + +sync_pb::SyncEnums::DeviceType GetLocalDeviceType() { +#if defined(OS_CHROMEOS) + return sync_pb::SyncEnums_DeviceType_TYPE_CROS; +#elif defined(OS_LINUX) + return sync_pb::SyncEnums_DeviceType_TYPE_LINUX; +#elif defined(OS_MACOSX) + return sync_pb::SyncEnums_DeviceType_TYPE_MAC; +#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; +#else + return sync_pb::SyncEnums_DeviceType_TYPE_OTHER; +#endif +} + +} // namespace + LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl() : weak_factory_(this) { } @@ -13,7 +64,47 @@ LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl() LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() { } -const DeviceInfo* +// static. +std::string LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi( + const chrome::VersionInfo& version_info) { + std::string user_agent; + user_agent = "Chrome "; +#if defined(OS_WIN) + user_agent += "WIN "; +#elif defined(OS_CHROMEOS) + user_agent += "CROS "; +#elif defined(OS_ANDROID) + if (IsTabletUI()) + user_agent += "ANDROID-TABLET "; + else + user_agent += "ANDROID-PHONE "; +#elif defined(OS_LINUX) + user_agent += "LINUX "; +#elif defined(OS_FREEBSD) + user_agent += "FREEBSD "; +#elif defined(OS_OPENBSD) + user_agent += "OPENBSD "; +#elif defined(OS_MACOSX) + user_agent += "MAC "; +#endif + if (!version_info.is_valid()) { + DLOG(ERROR) << "Unable to create chrome::VersionInfo object"; + return user_agent; + } + + user_agent += version_info.Version(); + user_agent += " (" + version_info.LastChange() + ")"; + if (!version_info.IsOfficialBuild()) { + user_agent += "-devel"; + } else { + user_agent += + " channel(" + ChannelToString(version_info.GetChannel()) + ")"; + } + + return user_agent; +} + +const sync_driver::DeviceInfo* LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const { return local_device_info_.get(); } @@ -22,7 +113,7 @@ std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const { return cache_guid_; } -scoped_ptr<LocalDeviceInfoProvider::Subscription> +scoped_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback( const base::Closure& callback) { DCHECK(!local_device_info_.get()); @@ -33,29 +124,31 @@ void LocalDeviceInfoProviderImpl::Initialize( const std::string& cache_guid, const std::string& signin_scoped_device_id) { DCHECK(!cache_guid.empty()); cache_guid_ = cache_guid; - DeviceInfo::CreateLocalDeviceInfo( - cache_guid_, - signin_scoped_device_id, + + syncer::GetSessionName( + content::BrowserThread::GetBlockingPool(), base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation, - weak_factory_.GetWeakPtr())); + weak_factory_.GetWeakPtr(), + cache_guid, + signin_scoped_device_id)); } void LocalDeviceInfoProviderImpl::InitializeContinuation( - const DeviceInfo& local_info) { - // Copy constructor is disallowed in DeviceInfo, construct a new one from - // the fields passed in local_info. + const std::string& guid, + const std::string& signin_scoped_device_id, + const std::string& session_name) { + chrome::VersionInfo version_info; + local_device_info_.reset( - new DeviceInfo( - local_info.guid(), - local_info.client_name(), - local_info.chrome_version(), - local_info.sync_user_agent(), - local_info.device_type(), - local_info.signin_scoped_device_id())); + new sync_driver::DeviceInfo(guid, + session_name, + version_info.CreateVersionString(), + MakeUserAgentForSyncApi(version_info), + GetLocalDeviceType(), + signin_scoped_device_id)); // Notify observers. callback_list_.Notify(); } } // namespace browser_sync - diff --git a/chrome/browser/sync/glue/local_device_info_provider_impl.h b/chrome/browser/sync/glue/local_device_info_provider_impl.h index 752a663633..7b91fc49dd 100644 --- a/chrome/browser/sync/glue/local_device_info_provider_impl.h +++ b/chrome/browser/sync/glue/local_device_info_provider_impl.h @@ -6,18 +6,23 @@ #define CHROME_BROWSER_SYNC_GLUE_LOCAL_DEVICE_INFO_PROVIDER_IMPL_H_ #include "base/memory/weak_ptr.h" -#include "chrome/browser/sync/glue/device_info.h" -#include "chrome/browser/sync/glue/local_device_info_provider.h" +#include "components/sync_driver/device_info.h" +#include "components/sync_driver/local_device_info_provider.h" + +namespace chrome { +class VersionInfo; +} namespace browser_sync { -class LocalDeviceInfoProviderImpl : public LocalDeviceInfoProvider { +class LocalDeviceInfoProviderImpl + : public sync_driver::LocalDeviceInfoProvider { public: LocalDeviceInfoProviderImpl(); virtual ~LocalDeviceInfoProviderImpl(); // LocalDeviceInfoProvider implementation. - virtual const DeviceInfo* GetLocalDeviceInfo() const OVERRIDE; + virtual const sync_driver::DeviceInfo* GetLocalDeviceInfo() const OVERRIDE; virtual std::string GetLocalSyncCacheGUID() const OVERRIDE; virtual void Initialize( const std::string& cache_guid, @@ -25,11 +30,19 @@ class LocalDeviceInfoProviderImpl : public LocalDeviceInfoProvider { virtual scoped_ptr<Subscription> RegisterOnInitializedCallback( const base::Closure& callback) OVERRIDE; + // Helper to construct a user agent string (ASCII) suitable for use by + // the syncapi for any HTTP communication. This string is used by the sync + // backend for classifying client types when calculating statistics. + static std::string MakeUserAgentForSyncApi( + const chrome::VersionInfo& version_info); + private: - void InitializeContinuation(const DeviceInfo& local_info); + void InitializeContinuation(const std::string& guid, + const std::string& signin_scoped_device_id, + const std::string& session_name); std::string cache_guid_; - scoped_ptr<DeviceInfo> local_device_info_; + scoped_ptr<sync_driver::DeviceInfo> local_device_info_; base::CallbackList<void(void)> callback_list_; base::WeakPtrFactory<LocalDeviceInfoProviderImpl> weak_factory_; diff --git a/chrome/browser/sync/glue/local_device_info_provider_mock.cc b/chrome/browser/sync/glue/local_device_info_provider_mock.cc index 863ca735e9..1c4c2db4d6 100644 --- a/chrome/browser/sync/glue/local_device_info_provider_mock.cc +++ b/chrome/browser/sync/glue/local_device_info_provider_mock.cc @@ -18,7 +18,7 @@ LocalDeviceInfoProviderMock::LocalDeviceInfoProviderMock( const std::string& signin_scoped_device_id) : is_initialized_(true) { local_device_info_.reset( - new DeviceInfo( + new sync_driver::DeviceInfo( guid, client_name, chrome_version, @@ -29,7 +29,7 @@ LocalDeviceInfoProviderMock::LocalDeviceInfoProviderMock( LocalDeviceInfoProviderMock::~LocalDeviceInfoProviderMock() {} -const DeviceInfo* +const sync_driver::DeviceInfo* LocalDeviceInfoProviderMock::GetLocalDeviceInfo() const { return is_initialized_ ? local_device_info_.get() : NULL; } @@ -43,7 +43,7 @@ void LocalDeviceInfoProviderMock::Initialize( // Ignored for the mock provider. } -scoped_ptr<LocalDeviceInfoProvider::Subscription> +scoped_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> LocalDeviceInfoProviderMock::RegisterOnInitializedCallback( const base::Closure& callback) { DCHECK(!is_initialized_); diff --git a/chrome/browser/sync/glue/local_device_info_provider_mock.h b/chrome/browser/sync/glue/local_device_info_provider_mock.h index a795aeaa8d..09c890b8a2 100644 --- a/chrome/browser/sync/glue/local_device_info_provider_mock.h +++ b/chrome/browser/sync/glue/local_device_info_provider_mock.h @@ -5,12 +5,13 @@ #ifndef CHROME_BROWSER_SYNC_GLUE_LOCAL_DEVICE_INFO_PROVIDER_MOCK_H_ #define CHROME_BROWSER_SYNC_GLUE_LOCAL_DEVICE_INFO_PROVIDER_MOCK_H_ -#include "chrome/browser/sync/glue/device_info.h" -#include "chrome/browser/sync/glue/local_device_info_provider.h" +#include "components/sync_driver/device_info.h" +#include "components/sync_driver/local_device_info_provider.h" namespace browser_sync { -class LocalDeviceInfoProviderMock : public LocalDeviceInfoProvider { +class LocalDeviceInfoProviderMock + : public sync_driver::LocalDeviceInfoProvider { public: // Creates uninitialized provider. LocalDeviceInfoProviderMock(); @@ -24,7 +25,7 @@ class LocalDeviceInfoProviderMock : public LocalDeviceInfoProvider { const std::string& signin_scoped_device_id); virtual ~LocalDeviceInfoProviderMock(); - virtual const DeviceInfo* GetLocalDeviceInfo() const OVERRIDE; + virtual const sync_driver::DeviceInfo* GetLocalDeviceInfo() const OVERRIDE; virtual std::string GetLocalSyncCacheGUID() const OVERRIDE; virtual void Initialize( const std::string& cache_guid, @@ -37,7 +38,7 @@ class LocalDeviceInfoProviderMock : public LocalDeviceInfoProvider { private: bool is_initialized_; - scoped_ptr<DeviceInfo> local_device_info_; + scoped_ptr<sync_driver::DeviceInfo> local_device_info_; base::CallbackList<void(void)> callback_list_; }; diff --git a/chrome/browser/sync/glue/local_device_info_provider_unittest.cc b/chrome/browser/sync/glue/local_device_info_provider_unittest.cc index d1fb4ebf53..4932323981 100644 --- a/chrome/browser/sync/glue/local_device_info_provider_unittest.cc +++ b/chrome/browser/sync/glue/local_device_info_provider_unittest.cc @@ -2,11 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#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 "chrome/common/chrome_version_info.h" +#include "sync/util/get_session_name.h" #include "testing/gtest/include/gtest/gtest.h" +using sync_driver::DeviceInfo; +using sync_driver::LocalDeviceInfoProvider; + namespace browser_sync { const char kLocalDeviceGuid[] = "foo"; @@ -72,6 +78,13 @@ TEST_F(LocalDeviceInfoProviderTest, GetLocalDeviceInfo) { EXPECT_EQ(std::string(kLocalDeviceGuid), local_device_info->guid()); EXPECT_EQ(std::string(kSigninScopedDeviceId), local_device_info->signin_scoped_device_id()); + EXPECT_EQ(syncer::GetSessionNameSynchronouslyForTesting(), + local_device_info->client_name()); + + chrome::VersionInfo version_info; + EXPECT_EQ(browser_sync::LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi( + version_info), + local_device_info->sync_user_agent()); } TEST_F(LocalDeviceInfoProviderTest, GetLocalSyncCacheGUID) { diff --git a/chrome/browser/sync/glue/non_frontend_data_type_controller.cc b/chrome/browser/sync/glue/non_frontend_data_type_controller.cc index ee7819cad2..4a09b70608 100644 --- a/chrome/browser/sync/glue/non_frontend_data_type_controller.cc +++ b/chrome/browser/sync/glue/non_frontend_data_type_controller.cc @@ -182,7 +182,7 @@ NonFrontendDataTypeController::NonFrontendDataTypeController( void NonFrontendDataTypeController::LoadModels( const ModelLoadCallback& model_load_callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(!model_load_callback.is_null()); + model_load_callback_ = model_load_callback; if (state_ != NOT_RUNNING) { model_load_callback.Run(type(), syncer::SyncError(FROM_HERE, @@ -368,12 +368,8 @@ void NonFrontendDataTypeController::StartDoneImpl( void NonFrontendDataTypeController::DisableImpl( const syncer::SyncError& error) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!start_callback_.is_null()) { - syncer::SyncMergeResult local_merge_result(type()); - local_merge_result.set_error(error); - start_callback_.Run(RUNTIME_ERROR, - local_merge_result, - syncer::SyncMergeResult(type())); + if (!model_load_callback_.is_null()) { + model_load_callback_.Run(type(), error); } } diff --git a/chrome/browser/sync/glue/password_data_type_controller.cc b/chrome/browser/sync/glue/password_data_type_controller.cc index 3681b04f66..683de68f42 100644 --- a/chrome/browser/sync/glue/password_data_type_controller.cc +++ b/chrome/browser/sync/glue/password_data_type_controller.cc @@ -42,7 +42,7 @@ bool PasswordDataTypeController::PostTaskOnBackendThread( const tracked_objects::Location& from_here, const base::Closure& task) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!password_store_) + if (!password_store_.get()) return false; return password_store_->ScheduleTask(task); } @@ -52,7 +52,7 @@ bool PasswordDataTypeController::StartModels() { DCHECK_EQ(MODEL_STARTING, state()); password_store_ = PasswordStoreFactory::GetForProfile( profile_, Profile::EXPLICIT_ACCESS); - return !!password_store_; + return !!password_store_.get(); } } // namespace browser_sync diff --git a/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc b/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc index 470c11af1d..eec71dfd3e 100644 --- a/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc @@ -60,7 +60,7 @@ class SyncSearchEngineDataTypeControllerTest : public testing::Test { make_scoped_ptr<sync_driver::GenericChangeProcessorFactory>( new sync_driver::FakeGenericChangeProcessorFactory( make_scoped_ptr(new sync_driver::FakeGenericChangeProcessor( - profile_sync_factory_.get()))))); + syncer::SEARCH_ENGINES, profile_sync_factory_.get()))))); EXPECT_CALL(model_load_callback_, Run(_, _)); EXPECT_CALL(*profile_sync_factory_, GetSyncableServiceForType(syncer::SEARCH_ENGINES)). diff --git a/chrome/browser/sync/glue/session_sync_test_helper.cc b/chrome/browser/sync/glue/session_sync_test_helper.cc index d908288ef1..9e241a9fe4 100644 --- a/chrome/browser/sync/glue/session_sync_test_helper.cc +++ b/chrome/browser/sync/glue/session_sync_test_helper.cc @@ -86,7 +86,7 @@ void SessionSyncTestHelper::VerifySyncedSession( ASSERT_EQ(tab->navigations[0].title(), base::ASCIIToUTF16(kTitle)); ASSERT_EQ(tab->navigations[0].transition_type(), - content::PAGE_TRANSITION_TYPED); + ui::PAGE_TRANSITION_TYPED); } } } diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h index 32615d45f6..061c3f4c77 100644 --- a/chrome/browser/sync/glue/sync_backend_host.h +++ b/chrome/browser/sync/glue/sync_backend_host.h @@ -42,8 +42,6 @@ class SyncFrontend; namespace browser_sync { -class SyncedDeviceTracker; - // An API to "host" the top level SyncAPI element. // // This class handles dispatch of potentially blocking calls to appropriate @@ -187,9 +185,6 @@ class SyncBackendHost : public sync_driver::BackendDataTypeConfigurer { virtual void GetModelSafeRoutingInfo( syncer::ModelSafeRoutingInfo* out) const = 0; - // Fetches the DeviceInfo tracker. - virtual SyncedDeviceTracker* GetSyncedDeviceTracker() const = 0; - // Requests that the backend forward to the fronent any protocol events in // its buffer and begin forwarding automatically from now on. Repeated calls // to this function may result in the same events being emitted several diff --git a/chrome/browser/sync/glue/sync_backend_host_core.cc b/chrome/browser/sync/glue/sync_backend_host_core.cc index 26f9e0ea81..1827f514cb 100644 --- a/chrome/browser/sync/glue/sync_backend_host_core.cc +++ b/chrome/browser/sync/glue/sync_backend_host_core.cc @@ -4,12 +4,11 @@ #include "chrome/browser/sync/glue/sync_backend_host_core.h" -#include "base/file_util.h" +#include "base/files/file_util.h" #include "base/metrics/histogram.h" -#include "chrome/browser/sync/glue/device_info.h" #include "chrome/browser/sync/glue/invalidation_adapter.h" +#include "chrome/browser/sync/glue/local_device_info_provider_impl.h" #include "chrome/browser/sync/glue/sync_backend_registrar.h" -#include "chrome/browser/sync/glue/synced_device_tracker.h" #include "chrome/common/chrome_version_info.h" #include "components/invalidation/invalidation_util.h" #include "components/invalidation/object_id_invalidation_map.h" @@ -71,8 +70,7 @@ DoInitializeOptions::DoInitializeOptions( scoped_ptr<syncer::InternalComponentsFactory> internal_components_factory, scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, syncer::ReportUnrecoverableErrorFunction - report_unrecoverable_error_function, - const std::string& signin_scoped_device_id) + report_unrecoverable_error_function) : sync_loop(sync_loop), registrar(registrar), routing_info(routing_info), @@ -90,8 +88,7 @@ DoInitializeOptions::DoInitializeOptions( restored_keystore_key_for_bootstrapping), internal_components_factory(internal_components_factory.Pass()), unrecoverable_error_handler(unrecoverable_error_handler.Pass()), - report_unrecoverable_error_function(report_unrecoverable_error_function), - signin_scoped_device_id(signin_scoped_device_id) { + report_unrecoverable_error_function(report_unrecoverable_error_function) { } DoInitializeOptions::~DoInitializeOptions() {} @@ -404,13 +401,11 @@ void SyncBackendHostCore::DoInitialize( sync_loop_ = options->sync_loop; DCHECK(sync_loop_); - signin_scoped_device_id_ = options->signin_scoped_device_id; - // Finish initializing the HttpBridgeFactory. We do this here because // building the user agent may block on some platforms. chrome::VersionInfo version_info; options->http_bridge_factory->Init( - DeviceInfo::MakeUserAgentForSyncApi(version_info)); + LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi(version_info)); // Blow away the partial or corrupt sync data folder before doing any more // initialization, if necessary. @@ -437,7 +432,7 @@ void SyncBackendHostCore::DoInitialize( args.service_url = options->service_url; args.post_factory = options->http_bridge_factory.Pass(); args.workers = options->workers; - args.extensions_activity = options->extensions_activity; + args.extensions_activity = options->extensions_activity.get(); args.change_delegate = options->registrar; // as SyncManager::ChangeDelegate args.credentials = options->credentials; args.invalidator_client_id = options->invalidator_client_id; @@ -509,25 +504,6 @@ void SyncBackendHostCore::DoInitialProcessControlTypes() { return; } - // Initialize device info. This is asynchronous on some platforms, so we - // provide a callback for when it finishes. - synced_device_tracker_.reset( - new SyncedDeviceTracker(sync_manager_->GetUserShare(), - sync_manager_->cache_guid())); - synced_device_tracker_->InitLocalDeviceInfo( - signin_scoped_device_id_, - base::Bind(&SyncBackendHostCore::DoFinishInitialProcessControlTypes, - weak_ptr_factory_.GetWeakPtr())); -} - -void SyncBackendHostCore::DoFinishInitialProcessControlTypes() { - DCHECK_EQ(base::MessageLoop::current(), sync_loop_); - - registrar_->ActivateDataType(syncer::DEVICE_INFO, - syncer::GROUP_PASSIVE, - synced_device_tracker_.get(), - sync_manager_->GetUserShare()); - host_.Call(FROM_HERE, &SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop, js_backend_, @@ -575,10 +551,6 @@ void SyncBackendHostCore::ShutdownOnUIThread() { void SyncBackendHostCore::DoShutdown(syncer::ShutdownReason reason) { DCHECK_EQ(base::MessageLoop::current(), sync_loop_); - // It's safe to do this even if the type was never activated. - registrar_->DeactivateDataType(syncer::DEVICE_INFO); - synced_device_tracker_.reset(); - DoDestroySyncManager(reason); registrar_ = NULL; diff --git a/chrome/browser/sync/glue/sync_backend_host_core.h b/chrome/browser/sync/glue/sync_backend_host_core.h index 5e61339a5d..46fb599e96 100644 --- a/chrome/browser/sync/glue/sync_backend_host_core.h +++ b/chrome/browser/sync/glue/sync_backend_host_core.h @@ -40,8 +40,7 @@ struct DoInitializeOptions { scoped_ptr<syncer::InternalComponentsFactory> internal_components_factory, scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, syncer::ReportUnrecoverableErrorFunction - report_unrecoverable_error_function, - const std::string& signin_scoped_device_id); + report_unrecoverable_error_function); ~DoInitializeOptions(); base::MessageLoop* sync_loop; @@ -64,7 +63,6 @@ struct DoInitializeOptions { scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler; syncer::ReportUnrecoverableErrorFunction report_unrecoverable_error_function; - std::string signin_scoped_device_id; }; // Helper struct to handle currying params to @@ -180,15 +178,9 @@ class SyncBackendHostCore void OnControlTypesDownloadRetry(); // Called to perform tasks which require the control data to be downloaded. - // This includes refreshing encryption, setting up the device info change - // processor, etc. + // This includes refreshing encryption, etc. void DoInitialProcessControlTypes(); - // Some parts of DoInitialProcessControlTypes() may be executed on a different - // thread. This function asynchronously continues the work started in - // DoInitialProcessControlTypes() once that other thread gets back to us. - void DoFinishInitialProcessControlTypes(); - // The shutdown order is a bit complicated: // 1) Call ShutdownOnUIThread() from |frontend_loop_| to request sync manager // to stop as soon as possible. @@ -219,10 +211,6 @@ class SyncBackendHostCore syncer::SyncManager* sync_manager() { return sync_manager_.get(); } - SyncedDeviceTracker* synced_device_tracker() { - return synced_device_tracker_.get(); - } - void SendBufferedProtocolEventsAndEnableForwarding(); void DisableProtocolEventForwarding(); @@ -293,9 +281,6 @@ class SyncBackendHostCore // Our encryptor, which uses Chrome's encryption functions. sync_driver::SystemEncryptor encryptor_; - // A special ChangeProcessor that tracks the DEVICE_INFO type for us. - scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; - // The top-level syncapi entry point. Lives on the sync thread. scoped_ptr<syncer::SyncManager> sync_manager_; @@ -323,10 +308,6 @@ class SyncBackendHostCore // Set when the forwarding of per-type debug counters is enabled. bool forward_type_info_; - // Obtained from SigninClient::GetSigninScopedDeviceId(). Stored here just to - // pass from SyncBackendHostImpl to SyncedDeviceTracker. - std::string signin_scoped_device_id_; - base::WeakPtrFactory<SyncBackendHostCore> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(SyncBackendHostCore); diff --git a/chrome/browser/sync/glue/sync_backend_host_impl.cc b/chrome/browser/sync/glue/sync_backend_host_impl.cc index 6f4c7e37dd..cbded53f8b 100644 --- a/chrome/browser/sync/glue/sync_backend_host_impl.cc +++ b/chrome/browser/sync/glue/sync_backend_host_impl.cc @@ -135,12 +135,6 @@ void SyncBackendHostImpl::Initialize( InternalComponentsFactory::FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE; } - SigninClient* signin_client = - ChromeSigninClientFactory::GetForProfile(profile_); - DCHECK(signin_client); - std::string signin_scoped_device_id = - signin_client->GetSigninScopedDeviceId(); - scoped_ptr<DoInitializeOptions> init_opts(new DoInitializeOptions( registrar_->sync_thread()->message_loop(), registrar_.get(), @@ -162,8 +156,7 @@ void SyncBackendHostImpl::Initialize( scoped_ptr<InternalComponentsFactory>( new syncer::InternalComponentsFactoryImpl(factory_switches)).Pass(), unrecoverable_error_handler.Pass(), - report_unrecoverable_error_function, - signin_scoped_device_id)); + report_unrecoverable_error_function)); InitCore(init_opts.Pass()); } @@ -514,12 +507,6 @@ void SyncBackendHostImpl::GetModelSafeRoutingInfo( } } -SyncedDeviceTracker* SyncBackendHostImpl::GetSyncedDeviceTracker() const { - if (!initialized()) - return NULL; - return core_->synced_device_tracker(); -} - void SyncBackendHostImpl::RequestBufferedProtocolEventsAndEnableForwarding() { registrar_->sync_thread()->message_loop()->PostTask( FROM_HERE, diff --git a/chrome/browser/sync/glue/sync_backend_host_impl.h b/chrome/browser/sync/glue/sync_backend_host_impl.h index 7e68da08fa..d4cd61f5d2 100644 --- a/chrome/browser/sync/glue/sync_backend_host_impl.h +++ b/chrome/browser/sync/glue/sync_backend_host_impl.h @@ -56,7 +56,6 @@ namespace browser_sync { class ChangeProcessor; class SyncBackendHostCore; class SyncBackendRegistrar; -class SyncedDeviceTracker; struct DoInitializeOptions; // The only real implementation of the SyncBackendHost. See that interface's @@ -128,7 +127,6 @@ class SyncBackendHostImpl const syncer::BaseTransaction* trans) const OVERRIDE; virtual void GetModelSafeRoutingInfo( syncer::ModelSafeRoutingInfo* out) const OVERRIDE; - virtual SyncedDeviceTracker* GetSyncedDeviceTracker() const OVERRIDE; virtual void RequestBufferedProtocolEventsAndEnableForwarding() OVERRIDE; virtual void DisableProtocolEventForwarding() OVERRIDE; virtual void EnableDirectoryTypeDebugInfoForwarding() OVERRIDE; diff --git a/chrome/browser/sync/glue/sync_backend_host_impl_unittest.cc b/chrome/browser/sync/glue/sync_backend_host_impl_unittest.cc index 5adc33ebb0..fb029301ae 100644 --- a/chrome/browser/sync/glue/sync_backend_host_impl_unittest.cc +++ b/chrome/browser/sync/glue/sync_backend_host_impl_unittest.cc @@ -6,7 +6,7 @@ #include <cstddef> -#include "base/file_util.h" +#include "base/files/file_util.h" #include "base/location.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" @@ -15,14 +15,13 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" #include "chrome/browser/prefs/pref_service_syncable.h" -#include "chrome/browser/sync/glue/device_info.h" -#include "chrome/browser/sync/glue/synced_device_tracker.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" #include "components/invalidation/invalidator_state.h" #include "components/invalidation/invalidator_storage.h" #include "components/invalidation/profile_invalidation_provider.h" +#include "components/sync_driver/device_info.h" #include "components/sync_driver/sync_frontend.h" #include "components/sync_driver/sync_prefs.h" #include "content/public/browser/notification_service.h" @@ -630,16 +629,6 @@ TEST_F(SyncBackendHostTest, NewlySupportedTypesWithPartialTypes) { enabled_types_).Empty()); } -// Ensure the device info tracker is initialized properly on startup. -TEST_F(SyncBackendHostTest, InitializeDeviceInfo) { - ASSERT_EQ(NULL, backend_->GetSyncedDeviceTracker()); - - InitializeBackend(true); - const SyncedDeviceTracker* device_tracker = - backend_->GetSyncedDeviceTracker(); - ASSERT_TRUE(device_tracker->ReadLocalDeviceInfo()); -} - // Verify that downloading control types only downloads those types that do // not have initial sync ended set. TEST_F(SyncBackendHostTest, DownloadControlTypes) { @@ -647,7 +636,7 @@ TEST_F(SyncBackendHostTest, DownloadControlTypes) { // Set sync manager behavior before passing it down. Experiments and device // info are new types without progress markers or initial sync ended, while // all other types have been fully downloaded and applied. - syncer::ModelTypeSet new_types(syncer::EXPERIMENTS, syncer::DEVICE_INFO); + syncer::ModelTypeSet new_types(syncer::EXPERIMENTS, syncer::NIGORI); syncer::ModelTypeSet old_types = Difference(enabled_types_, new_types); fake_manager_factory_->set_progress_marker_types(old_types); diff --git a/chrome/browser/sync/glue/sync_backend_host_mock.cc b/chrome/browser/sync/glue/sync_backend_host_mock.cc index 8faed53b07..704f55cb3b 100644 --- a/chrome/browser/sync/glue/sync_backend_host_mock.cc +++ b/chrome/browser/sync/glue/sync_backend_host_mock.cc @@ -111,10 +111,6 @@ bool SyncBackendHostMock::IsCryptographerReady( void SyncBackendHostMock::GetModelSafeRoutingInfo( syncer::ModelSafeRoutingInfo* out) const {} -SyncedDeviceTracker* SyncBackendHostMock::GetSyncedDeviceTracker() const { - return NULL; -} - base::MessageLoop* SyncBackendHostMock::GetSyncLoopForTesting() { return NULL; } diff --git a/chrome/browser/sync/glue/sync_backend_host_mock.h b/chrome/browser/sync/glue/sync_backend_host_mock.h index 2f233dbdb9..41c81914c1 100644 --- a/chrome/browser/sync/glue/sync_backend_host_mock.h +++ b/chrome/browser/sync/glue/sync_backend_host_mock.h @@ -94,8 +94,6 @@ class SyncBackendHostMock : public SyncBackendHost { virtual void GetModelSafeRoutingInfo( syncer::ModelSafeRoutingInfo* out) const OVERRIDE; - virtual SyncedDeviceTracker* GetSyncedDeviceTracker() const OVERRIDE; - virtual void RequestBufferedProtocolEventsAndEnableForwarding() OVERRIDE; virtual void DisableProtocolEventForwarding() OVERRIDE; diff --git a/chrome/browser/sync/glue/synced_device_tracker.cc b/chrome/browser/sync/glue/synced_device_tracker.cc deleted file mode 100644 index 73e8cbb242..0000000000 --- a/chrome/browser/sync/glue/synced_device_tracker.cc +++ /dev/null @@ -1,238 +0,0 @@ -// Copyright (c) 2012 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/sync/glue/synced_device_tracker.h" - -#include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" -#include "chrome/browser/sync/glue/device_info.h" -#include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/read_node.h" -#include "sync/internal_api/public/read_transaction.h" -#include "sync/internal_api/public/user_share.h" -#include "sync/internal_api/public/write_node.h" -#include "sync/internal_api/public/write_transaction.h" -#include "sync/util/time.h" - -namespace browser_sync { - -namespace { - -// Return the DeviceInfo UNIQUE_CLIENT_TAG value for the given sync cache_guid. -std::string DeviceInfoLookupString(const std::string& cache_guid) { - return base::StringPrintf("DeviceInfo_%s", cache_guid.c_str()); -} - -} // namespace - -SyncedDeviceTracker::SyncedDeviceTracker(syncer::UserShare* user_share, - const std::string& cache_guid) - : ChangeProcessor(NULL), - user_share_(user_share), - cache_guid_(cache_guid), - local_device_info_tag_(DeviceInfoLookupString(cache_guid)), - weak_factory_(this) { - observers_ = new ObserverListThreadSafe<Observer>; -} - -SyncedDeviceTracker::~SyncedDeviceTracker() { -} - -void SyncedDeviceTracker::StartImpl() { } - -void SyncedDeviceTracker::ApplyChangesFromSyncModel( - const syncer::BaseTransaction* trans, - int64 model_version, - const syncer::ImmutableChangeRecordList& changes) { - // If desired, we could maintain a cache of device info. This method will be - // called with a transaction every time the device info is modified, so this - // would be the right place to update the cache. -} - -void SyncedDeviceTracker::CommitChangesFromSyncModel() { - observers_->Notify(&Observer::OnDeviceInfoChange); -} - -scoped_ptr<DeviceInfo> SyncedDeviceTracker::ReadLocalDeviceInfo() const { - syncer::ReadTransaction trans(FROM_HERE, user_share_); - return ReadLocalDeviceInfo(trans); -} - -scoped_ptr<DeviceInfo> SyncedDeviceTracker::ReadLocalDeviceInfo( - const syncer::BaseTransaction& trans) const { - syncer::ReadNode node(&trans); - if (node.InitByClientTagLookup(syncer::DEVICE_INFO, local_device_info_tag_) != - syncer::BaseNode::INIT_OK) { - return scoped_ptr<DeviceInfo>(); - } - - const sync_pb::DeviceInfoSpecifics& specifics = node.GetDeviceInfoSpecifics(); - return scoped_ptr<DeviceInfo>( - new DeviceInfo(specifics.cache_guid(), - specifics.client_name(), - specifics.chrome_version(), - specifics.sync_user_agent(), - specifics.device_type(), - specifics.signin_scoped_device_id())); -} - -scoped_ptr<DeviceInfo> SyncedDeviceTracker::ReadDeviceInfo( - const std::string& client_id) const { - syncer::ReadTransaction trans(FROM_HERE, user_share_); - syncer::ReadNode node(&trans); - std::string lookup_string = DeviceInfoLookupString(client_id); - if (node.InitByClientTagLookup(syncer::DEVICE_INFO, lookup_string) != - syncer::BaseNode::INIT_OK) { - return scoped_ptr<DeviceInfo>(); - } - - const sync_pb::DeviceInfoSpecifics& specifics = node.GetDeviceInfoSpecifics(); - return scoped_ptr<DeviceInfo>( - new DeviceInfo(specifics.cache_guid(), - specifics.client_name(), - specifics.chrome_version(), - specifics.sync_user_agent(), - specifics.device_type(), - specifics.signin_scoped_device_id())); -} - -void SyncedDeviceTracker::GetAllSyncedDeviceInfo( - ScopedVector<DeviceInfo>* device_info) const { - if (device_info == NULL) - return; - - device_info->clear(); - - syncer::ReadTransaction trans(FROM_HERE, user_share_); - syncer::ReadNode root_node(&trans); - - if (root_node.InitTypeRoot(syncer::DEVICE_INFO) != - syncer::BaseNode::INIT_OK) { - return; - } - - // Get all the children of the root node and use the child id to read - // device info for devices. - std::vector<int64> children; - root_node.GetChildIds(&children); - - for (std::vector<int64>::const_iterator it = children.begin(); - it != children.end(); ++it) { - syncer::ReadNode node(&trans); - if (node.InitByIdLookup(*it) != syncer::BaseNode::INIT_OK) - return; - - const sync_pb::DeviceInfoSpecifics& specifics = - node.GetDeviceInfoSpecifics(); - device_info->push_back(new DeviceInfo(specifics.cache_guid(), - specifics.client_name(), - specifics.chrome_version(), - specifics.sync_user_agent(), - specifics.device_type(), - specifics.signin_scoped_device_id())); - } -} - -std::string SyncedDeviceTracker::cache_guid() const { - return cache_guid_; -} - -void SyncedDeviceTracker::AddObserver(Observer* observer) { - observers_->AddObserver(observer); -} - -void SyncedDeviceTracker::RemoveObserver(Observer* observer) { - observers_->RemoveObserver(observer); -} - -void SyncedDeviceTracker::InitLocalDeviceInfo( - const std::string& signin_scoped_device_id, - const base::Closure& callback) { - DeviceInfo::CreateLocalDeviceInfo( - cache_guid_, - signin_scoped_device_id, - base::Bind(&SyncedDeviceTracker::InitLocalDeviceInfoContinuation, - weak_factory_.GetWeakPtr(), - callback)); -} - -void SyncedDeviceTracker::InitLocalDeviceInfoContinuation( - const base::Closure& callback, const DeviceInfo& local_info) { - WriteLocalDeviceInfo(local_info); - callback.Run(); -} - -void SyncedDeviceTracker::WriteLocalDeviceInfo(const DeviceInfo& info) { - DCHECK_EQ(cache_guid_, info.guid()); - WriteDeviceInfo(info, local_device_info_tag_); -} - -void SyncedDeviceTracker::WriteDeviceInfo(const DeviceInfo& info, - const std::string& tag) { - syncer::WriteTransaction trans(FROM_HERE, user_share_); - syncer::WriteNode node(&trans); - - sync_pb::DeviceInfoSpecifics specifics; - specifics.set_cache_guid(info.guid()); - specifics.set_client_name(info.client_name()); - specifics.set_chrome_version(info.chrome_version()); - specifics.set_sync_user_agent(info.sync_user_agent()); - specifics.set_device_type(info.device_type()); - specifics.set_signin_scoped_device_id(info.signin_scoped_device_id()); - - if (node.InitByClientTagLookup(syncer::DEVICE_INFO, tag) == - syncer::BaseNode::INIT_OK) { - const sync_pb::DeviceInfoSpecifics& sync_specifics = - node.GetDeviceInfoSpecifics(); - if (sync_specifics.has_backup_timestamp()) - specifics.set_backup_timestamp(sync_specifics.backup_timestamp()); - node.SetDeviceInfoSpecifics(specifics); - node.SetTitle(specifics.client_name()); - } else { - syncer::ReadNode type_root(&trans); - syncer::BaseNode::InitByLookupResult type_root_lookup_result = - type_root.InitTypeRoot(syncer::DEVICE_INFO); - DCHECK_EQ(syncer::BaseNode::INIT_OK, type_root_lookup_result); - - syncer::WriteNode new_node(&trans); - syncer::WriteNode::InitUniqueByCreationResult create_result = - new_node.InitUniqueByCreation(syncer::DEVICE_INFO, - type_root, - tag); - DCHECK_EQ(syncer::WriteNode::INIT_SUCCESS, create_result); - new_node.SetDeviceInfoSpecifics(specifics); - new_node.SetTitle(specifics.client_name()); - } -} - -void SyncedDeviceTracker::UpdateLocalDeviceBackupTime(base::Time backup_time) { - syncer::WriteTransaction trans(FROM_HERE, user_share_); - syncer::WriteNode node(&trans); - - if (node.InitByClientTagLookup(syncer::DEVICE_INFO, local_device_info_tag_) - == syncer::BaseNode::INIT_OK) { - sync_pb::DeviceInfoSpecifics specifics = node.GetDeviceInfoSpecifics(); - int64 new_backup_timestamp = syncer::TimeToProtoTime(backup_time); - if (!specifics.has_backup_timestamp() || - specifics.backup_timestamp() != new_backup_timestamp) { - specifics.set_backup_timestamp(new_backup_timestamp); - node.SetDeviceInfoSpecifics(specifics); - } - } -} - -base::Time SyncedDeviceTracker::GetLocalDeviceBackupTime() const { - syncer::ReadTransaction trans(FROM_HERE, user_share_); - syncer::ReadNode node(&trans); - if (node.InitByClientTagLookup(syncer::DEVICE_INFO, local_device_info_tag_) - == syncer::BaseNode::INIT_OK && - node.GetDeviceInfoSpecifics().has_backup_timestamp()) { - return syncer::ProtoTimeToTime( - node.GetDeviceInfoSpecifics().backup_timestamp()); - } else { - return base::Time(); - } -} - -} // namespace browser_sync diff --git a/chrome/browser/sync/glue/synced_device_tracker.h b/chrome/browser/sync/glue/synced_device_tracker.h deleted file mode 100644 index 9f6fc33ee1..0000000000 --- a/chrome/browser/sync/glue/synced_device_tracker.h +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) 2012 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_SYNC_GLUE_SYNCED_DEVICE_TRACKER_H_ -#define CHROME_BROWSER_SYNC_GLUE_SYNCED_DEVICE_TRACKER_H_ - -#include <string> - -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/scoped_vector.h" -#include "base/memory/weak_ptr.h" -#include "base/observer_list_threadsafe.h" -#include "components/sync_driver/change_processor.h" - -namespace syncer { -struct UserShare; -} - -namespace browser_sync { - -class DeviceInfo; - -class SyncedDeviceTracker : public sync_driver::ChangeProcessor { - public: - SyncedDeviceTracker(syncer::UserShare* user_share, - const std::string& cache_guid); - virtual ~SyncedDeviceTracker(); - - // Observer class for listening to device info changes. - class Observer { - public: - virtual void OnDeviceInfoChange() = 0; - }; - - // ChangeProcessor methods - virtual void StartImpl() OVERRIDE; - virtual void ApplyChangesFromSyncModel( - const syncer::BaseTransaction* trans, - int64 model_version, - const syncer::ImmutableChangeRecordList& changes) OVERRIDE; - virtual void CommitChangesFromSyncModel() OVERRIDE; - - // Methods for accessing and updating the device_info list. - // These are virtual for testing. - virtual scoped_ptr<DeviceInfo> ReadLocalDeviceInfo( - const syncer::BaseTransaction &trans) const; - virtual scoped_ptr<DeviceInfo> ReadLocalDeviceInfo() const; - virtual void InitLocalDeviceInfo(const std::string& signin_scoped_device_id, - const base::Closure& callback); - virtual scoped_ptr<DeviceInfo> ReadDeviceInfo( - const std::string& client_id) const; - virtual void GetAllSyncedDeviceInfo( - ScopedVector<DeviceInfo>* device_info) const; - - virtual std::string cache_guid() const; - - // Can be called on any thread. Will be notified back on the same thread - // they were called on. Observer will be called on every device info - // change. - void AddObserver(Observer* observer); - void RemoveObserver(Observer* observer); - - // Update |backup_timestamp| in local device info specifics to |backup_time| - // if different. - void UpdateLocalDeviceBackupTime(base::Time backup_time); - - // Return time derived from |backup_timestamp| in local device info specifics. - base::Time GetLocalDeviceBackupTime() const; - - private: - friend class SyncedDeviceTrackerTest; - - void InitLocalDeviceInfoContinuation(const base::Closure& callback, - const DeviceInfo& local_info); - - // Helper to write specifics into our node. Also useful for testing. - void WriteLocalDeviceInfo(const DeviceInfo& info); - - // Helper to write arbitrary device info. Useful for writing local device - // info and also used by test cases to write arbitrary device infos. - void WriteDeviceInfo(const DeviceInfo& info, const std::string& tag); - - syncer::UserShare* user_share_; - const std::string cache_guid_; - const std::string local_device_info_tag_; - - // The |ObserverList| has to be thread safe as the changes happen - // on sync thread and the observers could be on any thread. - typedef ObserverListThreadSafe<Observer> ObserverList; - scoped_refptr<ObserverList> observers_; - - base::WeakPtrFactory<SyncedDeviceTracker> weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(SyncedDeviceTracker); -}; - -} // namespace browser_sync - -#endif // CHROME_BROWSER_SYNC_GLUE_SYNCED_DEVICE_TRACKER_H_ diff --git a/chrome/browser/sync/glue/synced_device_tracker_unittest.cc b/chrome/browser/sync/glue/synced_device_tracker_unittest.cc deleted file mode 100644 index 15161e3b28..0000000000 --- a/chrome/browser/sync/glue/synced_device_tracker_unittest.cc +++ /dev/null @@ -1,242 +0,0 @@ -// Copyright (c) 2012 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 <string> - -#include "base/guid.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/scoped_vector.h" -#include "base/message_loop/message_loop.h" -#include "base/run_loop.h" -#include "chrome/browser/sync/glue/device_info.h" -#include "chrome/browser/sync/glue/synced_device_tracker.h" -#include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/test/test_user_share.h" -#include "sync/protocol/sync.pb.h" -#include "sync/syncable/directory.h" -#include "sync/test/test_transaction_observer.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace browser_sync { - -class SyncedDeviceTrackerTest : public ::testing::Test { - protected: - SyncedDeviceTrackerTest() : transaction_count_baseline_(0) { } - virtual ~SyncedDeviceTrackerTest() { } - - virtual void SetUp() { - test_user_share_.SetUp(); - syncer::TestUserShare::CreateRoot(syncer::DEVICE_INFO, user_share()); - - synced_device_tracker_.reset( - new SyncedDeviceTracker(user_share(), - user_share()->directory->cache_guid())); - - // We don't actually touch the Profile, so we can get away with passing in a - // NULL here. Constructing a TestingProfile can take over a 100ms, so this - // optimization can be the difference between 'tests run with a noticeable - // delay' and 'tests run instantaneously'. - synced_device_tracker_->Start(user_share()); - } - - virtual void TearDown() { - synced_device_tracker_.reset(); - test_user_share_.TearDown(); - } - - syncer::UserShare* user_share() { - return test_user_share_.user_share(); - } - - // Expose the private method to our tests. - void WriteLocalDeviceInfo(const DeviceInfo& info) { - synced_device_tracker_->WriteLocalDeviceInfo(info); - } - - void WriteDeviceInfo(const DeviceInfo& device_info) { - synced_device_tracker_->WriteDeviceInfo(device_info, device_info.guid()); - } - - void ResetObservedChangesCounter() { - transaction_count_baseline_ = GetTotalTransactionsCount(); - } - - int GetObservedChangesCounter() { - return GetTotalTransactionsCount() - transaction_count_baseline_; - } - - scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; - - private: - // Count of how many closed WriteTransactions notified of meaningful changes. - int GetTotalTransactionsCount() { - base::RunLoop run_loop; - run_loop.RunUntilIdle(); - return test_user_share_.transaction_observer()->transactions_observed(); - } - - base::MessageLoop message_loop_; - syncer::TestUserShare test_user_share_; - int transaction_count_baseline_; -}; - -namespace { - -// New client scenario: set device info when no previous info existed. -TEST_F(SyncedDeviceTrackerTest, CreateNewDeviceInfo) { - ASSERT_FALSE(synced_device_tracker_->ReadLocalDeviceInfo()); - - ResetObservedChangesCounter(); - - // Include the non-ASCII character "’" (typographic apostrophe) in the client - // name to ensure that SyncedDeviceTracker can properly handle non-ASCII - // characters, which client names can include on some platforms (e.g., Mac - // and iOS). - DeviceInfo write_device_info(user_share()->directory->cache_guid(), - "John’s Device", - "Chromium 3000", - "ChromeSyncAgent 3000", - sync_pb::SyncEnums_DeviceType_TYPE_LINUX, - "device_id"); - WriteLocalDeviceInfo(write_device_info); - - scoped_ptr<DeviceInfo> read_device_info( - synced_device_tracker_->ReadLocalDeviceInfo()); - ASSERT_TRUE(read_device_info); - EXPECT_TRUE(write_device_info.Equals(*read_device_info.get())); - - EXPECT_EQ(1, GetObservedChangesCounter()); -} - -// Restart scenario: update existing device info with identical data. -TEST_F(SyncedDeviceTrackerTest, DontModifyExistingDeviceInfo) { - // For writing. - DeviceInfo device_info(user_share()->directory->cache_guid(), - "John’s Device", - "XYZ v1", - "XYZ SyncAgent v1", - sync_pb::SyncEnums_DeviceType_TYPE_LINUX, - "device_id"); - WriteLocalDeviceInfo(device_info); - - // First read. - scoped_ptr<DeviceInfo> old_device_info( - synced_device_tracker_->ReadLocalDeviceInfo()); - ASSERT_TRUE(old_device_info); - - ResetObservedChangesCounter(); - - // Overwrite the device info with the same data as before. - WriteLocalDeviceInfo(device_info); - - // Ensure that this didn't count as a change worth syncing. - EXPECT_EQ(0, GetObservedChangesCounter()); - - // Second read. - scoped_ptr<DeviceInfo> new_device_info( - synced_device_tracker_->ReadLocalDeviceInfo()); - ASSERT_TRUE(new_device_info); - EXPECT_TRUE(old_device_info->Equals(*new_device_info.get())); -} - -// Upgrade scenario: update existing device info with new version. -TEST_F(SyncedDeviceTrackerTest, UpdateExistingDeviceInfo) { - // Write v1 device info. - DeviceInfo device_info_v1(user_share()->directory->cache_guid(), - "John’s Device", - "XYZ v1", - "XYZ SyncAgent v1", - sync_pb::SyncEnums_DeviceType_TYPE_LINUX, - "device_id1"); - WriteLocalDeviceInfo(device_info_v1); - - ResetObservedChangesCounter(); - - // Write upgraded device info. - DeviceInfo device_info_v2(user_share()->directory->cache_guid(), - "John’s Device", - "XYZ v2", - "XYZ SyncAgent v2", - sync_pb::SyncEnums_DeviceType_TYPE_LINUX, - "device_id2"); - WriteLocalDeviceInfo(device_info_v2); - - // Verify result. - scoped_ptr<DeviceInfo> result_device_info( - synced_device_tracker_->ReadLocalDeviceInfo()); - ASSERT_TRUE(result_device_info); - - EXPECT_TRUE(result_device_info->Equals(device_info_v2)); - - // The update write should have sent a nudge. - EXPECT_EQ(1, GetObservedChangesCounter()); -} - -// Test retrieving DeviceInfos for all the syncing devices. -TEST_F(SyncedDeviceTrackerTest, GetAllDeviceInfo) { - DeviceInfo device_info1(base::GenerateGUID(), - "abc Device", - "XYZ v1", - "XYZ SyncAgent v1", - sync_pb::SyncEnums_DeviceType_TYPE_LINUX, - "device_id1"); - - std::string guid1 = base::GenerateGUID(); - - DeviceInfo device_info2(base::GenerateGUID(), - "def Device", - "XYZ v2", - "XYZ SyncAgent v2", - sync_pb::SyncEnums_DeviceType_TYPE_LINUX, - "device_id2"); - - std::string guid2 = base::GenerateGUID(); - - WriteDeviceInfo(device_info1); - WriteDeviceInfo(device_info2); - - ScopedVector<DeviceInfo> device_info; - synced_device_tracker_->GetAllSyncedDeviceInfo(&device_info); - - EXPECT_EQ(device_info.size(), 2U); - EXPECT_TRUE(device_info[0]->Equals(device_info1)); - EXPECT_TRUE(device_info[1]->Equals(device_info2)); -} - -TEST_F(SyncedDeviceTrackerTest, DeviceBackupTime) { - DeviceInfo device_info(user_share()->directory->cache_guid(), - "John’s Device", - "XYZ v1", - "XYZ SyncAgent v1", - sync_pb::SyncEnums_DeviceType_TYPE_LINUX, - "device_id"); - const base::Time test_backup_time = - base::Time::UnixEpoch() + base::TimeDelta::FromDays(10000); - - WriteLocalDeviceInfo(device_info); - synced_device_tracker_->UpdateLocalDeviceBackupTime(test_backup_time); - - // Verify read of device info and backup time. - EXPECT_EQ(test_backup_time, - synced_device_tracker_->GetLocalDeviceBackupTime()); - scoped_ptr<DeviceInfo> device_info_out( - synced_device_tracker_->ReadLocalDeviceInfo()); - ASSERT_TRUE(device_info_out); - EXPECT_TRUE(device_info.Equals(*device_info_out.get())); - - // Verify backup time is not lost after updating device info. - DeviceInfo device_info2(user_share()->directory->cache_guid(), - "def Device", - "XYZ v2", - "XYZ SyncAgent v2", - sync_pb::SyncEnums_DeviceType_TYPE_LINUX, - "device_id"); - WriteLocalDeviceInfo(device_info2); - EXPECT_EQ(test_backup_time, - synced_device_tracker_->GetLocalDeviceBackupTime()); -} - -} // namespace - -} // namespace browser_sync diff --git a/chrome/browser/sync/glue/typed_url_change_processor.cc b/chrome/browser/sync/glue/typed_url_change_processor.cc index ae25e4f8bd..90804d41f8 100644 --- a/chrome/browser/sync/glue/typed_url_change_processor.cc +++ b/chrome/browser/sync/glue/typed_url_change_processor.cc @@ -207,8 +207,8 @@ void TypedUrlChangeProcessor::HandleURLsVisited( bool TypedUrlChangeProcessor::ShouldSyncVisit( history::URLVisitedDetails* details) { int typed_count = details->row.typed_count(); - content::PageTransition transition = static_cast<content::PageTransition>( - details->transition & content::PAGE_TRANSITION_CORE_MASK); + ui::PageTransition transition = + ui::PageTransitionStripQualifier(details->transition); // Just use an ad-hoc criteria to determine whether to ignore this // notification. For most users, the distribution of visits is roughly a bell @@ -217,7 +217,7 @@ bool TypedUrlChangeProcessor::ShouldSyncVisit( // suggestions. But there are relatively few URLs with > 10 visits, and those // tend to be more broadly distributed such that there's no need to sync up // every visit to preserve their relative ordering. - return (transition == content::PAGE_TRANSITION_TYPED && + return (transition == ui::PAGE_TRANSITION_TYPED && typed_count > 0 && (typed_count < kTypedUrlVisitThrottleThreshold || (typed_count % kTypedUrlVisitThrottleMultiple) == 0)); diff --git a/chrome/browser/sync/glue/typed_url_data_type_controller.cc b/chrome/browser/sync/glue/typed_url_data_type_controller.cc index caaa099c65..bf43c95f70 100644 --- a/chrome/browser/sync/glue/typed_url_data_type_controller.cc +++ b/chrome/browser/sync/glue/typed_url_data_type_controller.cc @@ -92,20 +92,10 @@ syncer::ModelSafeGroup TypedUrlDataTypeController::model_safe_group() return syncer::GROUP_HISTORY; } -void TypedUrlDataTypeController::LoadModels( - const ModelLoadCallback& model_load_callback) { - if (profile()->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled)) { - model_load_callback.Run( - type(), - syncer::SyncError(FROM_HERE, - syncer::SyncError::DATATYPE_ERROR, - "History sync disabled by policy.", - type())); - return; - } - - set_state(MODEL_LOADED); - model_load_callback.Run(type(), syncer::SyncError()); +bool TypedUrlDataTypeController::ReadyForStart() const { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + return !profile()->GetPrefs()->GetBoolean( + prefs::kSavingBrowserHistoryDisabled); } void TypedUrlDataTypeController::SetBackend(history::HistoryBackend* backend) { @@ -126,7 +116,7 @@ void TypedUrlDataTypeController::OnSavingBrowserHistoryDisabledChanged() { syncer::SyncError::DATATYPE_POLICY_ERROR, "History saving is now disabled by policy.", syncer::TYPED_URLS); - OnSingleDataTypeUnrecoverableError(error); + DisableImpl(error); } } } diff --git a/chrome/browser/sync/glue/typed_url_data_type_controller.h b/chrome/browser/sync/glue/typed_url_data_type_controller.h index aacc647ff6..ac7dc9dfb9 100644 --- a/chrome/browser/sync/glue/typed_url_data_type_controller.h +++ b/chrome/browser/sync/glue/typed_url_data_type_controller.h @@ -34,8 +34,7 @@ class TypedUrlDataTypeController : public NonFrontendDataTypeController { // NonFrontendDataTypeController implementation virtual syncer::ModelType type() const OVERRIDE; virtual syncer::ModelSafeGroup model_safe_group() const OVERRIDE; - virtual void LoadModels(const ModelLoadCallback& model_load_callback) - OVERRIDE; + virtual bool ReadyForStart() const OVERRIDE; // Invoked on the history thread to set our history backend - must be called // before CreateSyncComponents() is invoked. diff --git a/chrome/browser/sync/glue/typed_url_model_associator.cc b/chrome/browser/sync/glue/typed_url_model_associator.cc index 30fc427c28..376c5ec833 100644 --- a/chrome/browser/sync/glue/typed_url_model_associator.cc +++ b/chrome/browser/sync/glue/typed_url_model_associator.cc @@ -103,7 +103,7 @@ bool TypedUrlModelAssociator::FixupURLAndGetVisits( } history::VisitRow visit( - url->id(), url->last_visit(), 0, content::PAGE_TRANSITION_TYPED, 0); + url->id(), url->last_visit(), 0, ui::PAGE_TRANSITION_TYPED, 0); visits->push_back(visit); } @@ -634,7 +634,7 @@ TypedUrlModelAssociator::MergeResult TypedUrlModelAssociator::MergeUrls( different |= DIFF_LOCAL_VISITS_ADDED; new_visits->push_back(history::VisitInfo( node_time, - content::PageTransitionFromInt( + ui::PageTransitionFromInt( node.visit_transitions(node_visit_index)))); } // This visit is added to visits below. @@ -704,13 +704,13 @@ void TypedUrlModelAssociator::WriteToTypedUrlSpecifics( // Walk the passed-in visit vector and count the # of typed visits. for (history::VisitVector::const_iterator visit = visits.begin(); visit != visits.end(); ++visit) { - content::PageTransition transition = content::PageTransitionFromInt( - visit->transition & content::PAGE_TRANSITION_CORE_MASK); + ui::PageTransition transition = + ui::PageTransitionStripQualifier(visit->transition); // We ignore reload visits. - if (transition == content::PAGE_TRANSITION_RELOAD) + if (transition == ui::PAGE_TRANSITION_RELOAD) continue; ++total; - if (transition == content::PAGE_TRANSITION_TYPED) + if (transition == ui::PAGE_TRANSITION_TYPED) ++typed_count; } // We should have at least one typed visit. This can sometimes happen if @@ -730,20 +730,20 @@ void TypedUrlModelAssociator::WriteToTypedUrlSpecifics( for (history::VisitVector::const_iterator visit = visits.begin(); visit != visits.end(); ++visit) { - content::PageTransition transition = content::PageTransitionFromInt( - visit->transition & content::PAGE_TRANSITION_CORE_MASK); + ui::PageTransition transition = + ui::PageTransitionStripQualifier(visit->transition); // Skip reload visits. - if (transition == content::PAGE_TRANSITION_RELOAD) + if (transition == ui::PAGE_TRANSITION_RELOAD) continue; // If we only have room for typed visits, then only add typed visits. - if (only_typed && transition != content::PAGE_TRANSITION_TYPED) + if (only_typed && transition != ui::PAGE_TRANSITION_TYPED) continue; if (skip_count > 0) { // We have too many entries to fit, so we need to skip the oldest ones. // Only skip typed URLs if there are too many typed URLs to fit. - if (only_typed || transition != content::PAGE_TRANSITION_TYPED) { + if (only_typed || transition != ui::PAGE_TRANSITION_TYPED) { --skip_count; continue; } @@ -760,7 +760,7 @@ void TypedUrlModelAssociator::WriteToTypedUrlSpecifics( // it's not legal to have an empty visit array (yet another workaround // for http://crbug.com/84258). typed_url->add_visits(url.last_visit().ToInternalValue()); - typed_url->add_visit_transitions(content::PAGE_TRANSITION_RELOAD); + typed_url->add_visit_transitions(ui::PAGE_TRANSITION_RELOAD); } CHECK_GT(typed_url->visits_size(), 0); CHECK_LE(typed_url->visits_size(), kMaxTypedUrlVisits); @@ -793,7 +793,7 @@ void TypedUrlModelAssociator::DiffVisits( } else if (old_visits[old_index].visit_time > new_visit_time) { new_visits->push_back(history::VisitInfo( new_visit_time, - content::PageTransitionFromInt( + ui::PageTransitionFromInt( new_url.visit_transitions(new_index)))); ++new_index; } else { @@ -811,7 +811,7 @@ void TypedUrlModelAssociator::DiffVisits( for ( ; new_index < new_visit_count; ++new_index) { new_visits->push_back(history::VisitInfo( base::Time::FromInternalValue(new_url.visits(new_index)), - content::PageTransitionFromInt(new_url.visit_transitions(new_index)))); + ui::PageTransitionFromInt(new_url.visit_transitions(new_index)))); } } diff --git a/chrome/browser/sync/glue/typed_url_model_associator.h b/chrome/browser/sync/glue/typed_url_model_associator.h index ebb891459d..9357940318 100644 --- a/chrome/browser/sync/glue/typed_url_model_associator.h +++ b/chrome/browser/sync/glue/typed_url_model_associator.h @@ -13,7 +13,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/strings/string16.h" -#include "chrome/browser/history/history_types.h" +#include "components/history/core/browser/history_types.h" #include "components/sync_driver/data_type_error_handler.h" #include "components/sync_driver/model_associator.h" #include "sync/protocol/typed_url_specifics.pb.h" diff --git a/chrome/browser/sync/glue/typed_url_model_associator_unittest.cc b/chrome/browser/sync/glue/typed_url_model_associator_unittest.cc index 731b9942b9..89b8f1fe4b 100644 --- a/chrome/browser/sync/glue/typed_url_model_associator_unittest.cc +++ b/chrome/browser/sync/glue/typed_url_model_associator_unittest.cc @@ -9,9 +9,9 @@ #include "base/synchronization/waitable_event.h" #include "base/test/test_timeouts.h" #include "base/time/time.h" -#include "chrome/browser/history/history_types.h" #include "chrome/browser/sync/glue/typed_url_model_associator.h" #include "chrome/browser/sync/profile_sync_service_mock.h" +#include "components/history/core/browser/history_types.h" #include "content/public/browser/browser_thread.h" #include "content/public/test/test_browser_thread_bundle.h" #include "sync/protocol/typed_url_specifics.pb.h" @@ -39,7 +39,7 @@ class SyncTypedUrlModelAssociatorTest : public testing::Test { history_url.set_hidden(hidden); visits->push_back(history::VisitRow( history_url.id(), history_url.last_visit(), 0, - content::PAGE_TRANSITION_RELOAD, 0)); + ui::PAGE_TRANSITION_RELOAD, 0)); history_url.set_visit_count(visits->size()); return history_url; } @@ -53,7 +53,7 @@ class SyncTypedUrlModelAssociatorTest : public testing::Test { typed_url.set_title(title); typed_url.set_hidden(hidden); typed_url.add_visits(last_visit); - typed_url.add_visit_transitions(content::PAGE_TRANSITION_TYPED); + typed_url.add_visit_transitions(ui::PAGE_TRANSITION_TYPED); return typed_url; } @@ -183,7 +183,7 @@ TEST_F(SyncTypedUrlModelAssociatorTest, MergeUrlsAfterExpiration) { // First, create a history row that has two visits, with timestamps 2 and 3. history::VisitVector(history_visits); history_visits.push_back(history::VisitRow( - 0, base::Time::FromInternalValue(2), 0, content::PAGE_TRANSITION_TYPED, + 0, base::Time::FromInternalValue(2), 0, ui::PAGE_TRANSITION_TYPED, 0)); history::URLRow history_url(MakeTypedUrlRow("http://pie.com/", "pie", 2, 3, false, &history_visits)); @@ -225,9 +225,9 @@ TEST_F(SyncTypedUrlModelAssociatorTest, DiffVisitsSame) { for (size_t c = 0; c < arraysize(visits); ++c) { old_visits.push_back(history::VisitRow( 0, base::Time::FromInternalValue(visits[c]), 0, - content::PAGE_TRANSITION_TYPED, 0)); + ui::PAGE_TRANSITION_TYPED, 0)); new_url.add_visits(visits[c]); - new_url.add_visit_transitions(content::PAGE_TRANSITION_TYPED); + new_url.add_visit_transitions(ui::PAGE_TRANSITION_TYPED); } std::vector<history::VisitInfo> new_visits; @@ -255,12 +255,12 @@ TEST_F(SyncTypedUrlModelAssociatorTest, DiffVisitsRemove) { for (size_t c = 0; c < arraysize(visits_left); ++c) { old_visits.push_back(history::VisitRow( 0, base::Time::FromInternalValue(visits_left[c]), 0, - content::PAGE_TRANSITION_TYPED, 0)); + ui::PAGE_TRANSITION_TYPED, 0)); } for (size_t c = 0; c < arraysize(visits_right); ++c) { new_url.add_visits(visits_right[c]); - new_url.add_visit_transitions(content::PAGE_TRANSITION_TYPED); + new_url.add_visit_transitions(ui::PAGE_TRANSITION_TYPED); } std::vector<history::VisitInfo> new_visits; @@ -289,12 +289,12 @@ TEST_F(SyncTypedUrlModelAssociatorTest, DiffVisitsAdd) { for (size_t c = 0; c < arraysize(visits_left); ++c) { old_visits.push_back(history::VisitRow( 0, base::Time::FromInternalValue(visits_left[c]), 0, - content::PAGE_TRANSITION_TYPED, 0)); + ui::PAGE_TRANSITION_TYPED, 0)); } for (size_t c = 0; c < arraysize(visits_right); ++c) { new_url.add_visits(visits_right[c]); - new_url.add_visit_transitions(content::PAGE_TRANSITION_TYPED); + new_url.add_visit_transitions(ui::PAGE_TRANSITION_TYPED); } std::vector<history::VisitInfo> new_visits; @@ -307,11 +307,11 @@ TEST_F(SyncTypedUrlModelAssociatorTest, DiffVisitsAdd) { for (size_t c = 0; c < arraysize(visits_added); ++c) { EXPECT_EQ(new_visits[c].first.ToInternalValue(), visits_added[c]); - EXPECT_EQ(new_visits[c].second, content::PAGE_TRANSITION_TYPED); + EXPECT_EQ(new_visits[c].second, ui::PAGE_TRANSITION_TYPED); } } -static history::VisitRow CreateVisit(content::PageTransition type, +static history::VisitRow CreateVisit(ui::PageTransition type, int64 timestamp) { return history::VisitRow(0, base::Time::FromInternalValue(timestamp), 0, type, 0); @@ -319,9 +319,9 @@ static history::VisitRow CreateVisit(content::PageTransition type, TEST_F(SyncTypedUrlModelAssociatorTest, WriteTypedUrlSpecifics) { history::VisitVector visits; - visits.push_back(CreateVisit(content::PAGE_TRANSITION_TYPED, 1)); - visits.push_back(CreateVisit(content::PAGE_TRANSITION_RELOAD, 2)); - visits.push_back(CreateVisit(content::PAGE_TRANSITION_LINK, 3)); + visits.push_back(CreateVisit(ui::PAGE_TRANSITION_TYPED, 1)); + visits.push_back(CreateVisit(ui::PAGE_TRANSITION_RELOAD, 2)); + visits.push_back(CreateVisit(ui::PAGE_TRANSITION_LINK, 3)); history::URLRow url(MakeTypedUrlRow("http://pie.com/", "pie", 1, 100, false, &visits)); @@ -332,18 +332,18 @@ TEST_F(SyncTypedUrlModelAssociatorTest, WriteTypedUrlSpecifics) { EXPECT_EQ(typed_url.visit_transitions_size(), typed_url.visits_size()); EXPECT_EQ(1, typed_url.visits(0)); EXPECT_EQ(3, typed_url.visits(1)); - EXPECT_EQ(content::PAGE_TRANSITION_TYPED, - static_cast<content::PageTransition>(typed_url.visit_transitions(0))); - EXPECT_EQ(content::PAGE_TRANSITION_LINK, - static_cast<content::PageTransition>(typed_url.visit_transitions(1))); + EXPECT_EQ(ui::PAGE_TRANSITION_TYPED, + ui::PageTransitionFromInt(typed_url.visit_transitions(0))); + EXPECT_EQ(ui::PAGE_TRANSITION_LINK, + ui::PageTransitionFromInt(typed_url.visit_transitions(1))); } TEST_F(SyncTypedUrlModelAssociatorTest, TooManyVisits) { history::VisitVector visits; int64 timestamp = 1000; - visits.push_back(CreateVisit(content::PAGE_TRANSITION_TYPED, timestamp++)); + visits.push_back(CreateVisit(ui::PAGE_TRANSITION_TYPED, timestamp++)); for (int i = 0 ; i < 100; ++i) { - visits.push_back(CreateVisit(content::PAGE_TRANSITION_LINK, timestamp++)); + visits.push_back(CreateVisit(ui::PAGE_TRANSITION_LINK, timestamp++)); } history::URLRow url(MakeTypedUrlRow("http://pie.com/", "pie", 1, timestamp++, false, &visits)); @@ -356,19 +356,19 @@ TEST_F(SyncTypedUrlModelAssociatorTest, TooManyVisits) { // Visit with timestamp of 1001 should be omitted since we should have // skipped that visit to stay under the cap. EXPECT_EQ(1002, typed_url.visits(1)); - EXPECT_EQ(content::PAGE_TRANSITION_TYPED, - static_cast<content::PageTransition>(typed_url.visit_transitions(0))); - EXPECT_EQ(content::PAGE_TRANSITION_LINK, - static_cast<content::PageTransition>(typed_url.visit_transitions(1))); + EXPECT_EQ(ui::PAGE_TRANSITION_TYPED, + ui::PageTransitionFromInt(typed_url.visit_transitions(0))); + EXPECT_EQ(ui::PAGE_TRANSITION_LINK, + ui::PageTransitionFromInt(typed_url.visit_transitions(1))); } TEST_F(SyncTypedUrlModelAssociatorTest, TooManyTypedVisits) { history::VisitVector visits; int64 timestamp = 1000; for (int i = 0 ; i < 102; ++i) { - visits.push_back(CreateVisit(content::PAGE_TRANSITION_TYPED, timestamp++)); - visits.push_back(CreateVisit(content::PAGE_TRANSITION_LINK, timestamp++)); - visits.push_back(CreateVisit(content::PAGE_TRANSITION_RELOAD, timestamp++)); + visits.push_back(CreateVisit(ui::PAGE_TRANSITION_TYPED, timestamp++)); + visits.push_back(CreateVisit(ui::PAGE_TRANSITION_LINK, timestamp++)); + visits.push_back(CreateVisit(ui::PAGE_TRANSITION_RELOAD, timestamp++)); } history::URLRow url(MakeTypedUrlRow("http://pie.com/", "pie", 1, timestamp++, false, &visits)); @@ -382,8 +382,8 @@ TEST_F(SyncTypedUrlModelAssociatorTest, TooManyTypedVisits) { // Ensure there are no non-typed visits since that's all that should fit. for (int i = 0; i < typed_url.visits_size(); ++i) { - EXPECT_EQ(content::PAGE_TRANSITION_TYPED, - static_cast<content::PageTransition>(typed_url.visit_transitions(i))); + EXPECT_EQ(ui::PAGE_TRANSITION_TYPED, + ui::PageTransitionFromInt(typed_url.visit_transitions(i))); } } @@ -399,8 +399,8 @@ TEST_F(SyncTypedUrlModelAssociatorTest, NoTypedVisits) { EXPECT_EQ(typed_url.visit_transitions_size(), typed_url.visits_size()); // First two typed visits should be skipped. EXPECT_EQ(1000, typed_url.visits(0)); - EXPECT_EQ(content::PAGE_TRANSITION_RELOAD, - static_cast<content::PageTransition>(typed_url.visit_transitions(0))); + EXPECT_EQ(ui::PAGE_TRANSITION_RELOAD, + ui::PageTransitionFromInt(typed_url.visit_transitions(0))); } // This test verifies that we can abort model association from the UI thread. |