| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h" | 6 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h" |
| 7 #include "chrome/common/chrome_version_info.h" | 7 #include "chrome/common/chrome_version_info.h" |
| 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "sync/util/get_session_name.h" |
| 8 #include "ui/base/device_form_factor.h" | 10 #include "ui/base/device_form_factor.h" |
| 9 | 11 |
| 10 namespace browser_sync { | 12 namespace browser_sync { |
| 11 | 13 |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 // Converts VersionInfo::Channel to string for user-agent string. | 16 // Converts VersionInfo::Channel to string for user-agent string. |
| 15 std::string ChannelToString(chrome::VersionInfo::Channel channel) { | 17 std::string ChannelToString(chrome::VersionInfo::Channel channel) { |
| 16 switch (channel) { | 18 switch (channel) { |
| 17 case chrome::VersionInfo::CHANNEL_UNKNOWN: | 19 case chrome::VersionInfo::CHANNEL_UNKNOWN: |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 if (!version_info.IsOfficialBuild()) { | 97 if (!version_info.IsOfficialBuild()) { |
| 96 user_agent += "-devel"; | 98 user_agent += "-devel"; |
| 97 } else { | 99 } else { |
| 98 user_agent += | 100 user_agent += |
| 99 " channel(" + ChannelToString(version_info.GetChannel()) + ")"; | 101 " channel(" + ChannelToString(version_info.GetChannel()) + ")"; |
| 100 } | 102 } |
| 101 | 103 |
| 102 return user_agent; | 104 return user_agent; |
| 103 } | 105 } |
| 104 | 106 |
| 105 const DeviceInfo* | 107 const sync_driver::DeviceInfo* |
| 106 LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const { | 108 LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const { |
| 107 return local_device_info_.get(); | 109 return local_device_info_.get(); |
| 108 } | 110 } |
| 109 | 111 |
| 110 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const { | 112 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const { |
| 111 return cache_guid_; | 113 return cache_guid_; |
| 112 } | 114 } |
| 113 | 115 |
| 114 scoped_ptr<LocalDeviceInfoProvider::Subscription> | 116 scoped_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> |
| 115 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback( | 117 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback( |
| 116 const base::Closure& callback) { | 118 const base::Closure& callback) { |
| 117 DCHECK(!local_device_info_.get()); | 119 DCHECK(!local_device_info_.get()); |
| 118 return callback_list_.Add(callback); | 120 return callback_list_.Add(callback); |
| 119 } | 121 } |
| 120 | 122 |
| 121 void LocalDeviceInfoProviderImpl::Initialize( | 123 void LocalDeviceInfoProviderImpl::Initialize( |
| 122 const std::string& cache_guid, const std::string& signin_scoped_device_id) { | 124 const std::string& cache_guid, const std::string& signin_scoped_device_id) { |
| 123 DCHECK(!cache_guid.empty()); | 125 DCHECK(!cache_guid.empty()); |
| 124 cache_guid_ = cache_guid; | 126 cache_guid_ = cache_guid; |
| 125 | 127 |
| 126 DeviceInfo::GetClientName( | 128 syncer::GetSessionName( |
| 129 content::BrowserThread::GetBlockingPool(), |
| 127 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation, | 130 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation, |
| 128 weak_factory_.GetWeakPtr(), | 131 weak_factory_.GetWeakPtr(), |
| 129 cache_guid, | 132 cache_guid, |
| 130 signin_scoped_device_id)); | 133 signin_scoped_device_id)); |
| 131 } | 134 } |
| 132 | 135 |
| 133 void LocalDeviceInfoProviderImpl::InitializeContinuation( | 136 void LocalDeviceInfoProviderImpl::InitializeContinuation( |
| 134 const std::string& guid, | 137 const std::string& guid, |
| 135 const std::string& signin_scoped_device_id, | 138 const std::string& signin_scoped_device_id, |
| 136 const std::string& session_name) { | 139 const std::string& session_name) { |
| 137 chrome::VersionInfo version_info; | 140 chrome::VersionInfo version_info; |
| 138 | 141 |
| 139 local_device_info_.reset(new DeviceInfo(guid, | 142 local_device_info_.reset( |
| 140 session_name, | 143 new sync_driver::DeviceInfo(guid, |
| 141 version_info.CreateVersionString(), | 144 session_name, |
| 142 MakeUserAgentForSyncApi(version_info), | 145 version_info.CreateVersionString(), |
| 143 GetLocalDeviceType(), | 146 MakeUserAgentForSyncApi(version_info), |
| 144 signin_scoped_device_id)); | 147 GetLocalDeviceType(), |
| 148 signin_scoped_device_id)); |
| 145 | 149 |
| 146 // Notify observers. | 150 // Notify observers. |
| 147 callback_list_.Notify(); | 151 callback_list_.Notify(); |
| 148 } | 152 } |
| 149 | 153 |
| 150 } // namespace browser_sync | 154 } // namespace browser_sync |
| 151 | |
| OLD | NEW |