OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/sync/driver/local_device_info_provider_mock.h" | |
6 | |
7 namespace sync_driver { | |
8 | |
9 LocalDeviceInfoProviderMock::LocalDeviceInfoProviderMock() | |
10 : is_initialized_(false) {} | |
11 | |
12 LocalDeviceInfoProviderMock::LocalDeviceInfoProviderMock( | |
13 const std::string& guid, | |
14 const std::string& client_name, | |
15 const std::string& chrome_version, | |
16 const std::string& sync_user_agent, | |
17 const sync_pb::SyncEnums::DeviceType device_type, | |
18 const std::string& signin_scoped_device_id) | |
19 : is_initialized_(true) { | |
20 local_device_info_.reset(new DeviceInfo(guid, client_name, chrome_version, | |
21 sync_user_agent, device_type, | |
22 signin_scoped_device_id)); | |
23 } | |
24 | |
25 LocalDeviceInfoProviderMock::~LocalDeviceInfoProviderMock() {} | |
26 | |
27 const DeviceInfo* LocalDeviceInfoProviderMock::GetLocalDeviceInfo() const { | |
28 return is_initialized_ ? local_device_info_.get() : nullptr; | |
29 } | |
30 | |
31 std::string LocalDeviceInfoProviderMock::GetSyncUserAgent() const { | |
32 return "useragent"; | |
33 } | |
34 | |
35 std::string LocalDeviceInfoProviderMock::GetLocalSyncCacheGUID() const { | |
36 return local_device_info_.get() ? local_device_info_->guid() : ""; | |
37 } | |
38 | |
39 void LocalDeviceInfoProviderMock::Initialize( | |
40 const std::string& cache_guid, | |
41 const std::string& signin_scoped_device_id, | |
42 const scoped_refptr<base::TaskRunner>& blocking_task_runner) { | |
43 local_device_info_.reset(new DeviceInfo( | |
44 cache_guid, "client_name", "chrome_version", GetSyncUserAgent(), | |
45 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, signin_scoped_device_id)); | |
46 SetInitialized(true); | |
47 } | |
48 | |
49 void LocalDeviceInfoProviderMock::Initialize( | |
50 std::unique_ptr<DeviceInfo> local_device_info) { | |
51 local_device_info_.swap(local_device_info); | |
52 SetInitialized(true); | |
53 } | |
54 | |
55 std::unique_ptr<LocalDeviceInfoProvider::Subscription> | |
56 LocalDeviceInfoProviderMock::RegisterOnInitializedCallback( | |
57 const base::Closure& callback) { | |
58 DCHECK(!is_initialized_); | |
59 return callback_list_.Add(callback); | |
60 } | |
61 | |
62 void LocalDeviceInfoProviderMock::Clear() { | |
63 local_device_info_.reset(); | |
64 is_initialized_ = false; | |
65 } | |
66 | |
67 void LocalDeviceInfoProviderMock::SetInitialized(bool is_initialized) { | |
68 is_initialized_ = is_initialized; | |
69 if (is_initialized_) { | |
70 callback_list_.Notify(); | |
71 } | |
72 } | |
73 | |
74 } // namespace sync_driver | |
OLD | NEW |